grub.git
6 years agoieee1275: split up grub_machine_get_bootlocation master
Eric Snowberg [Fri, 9 Mar 2018 04:42:22 +0000 (20:42 -0800)]
ieee1275: split up grub_machine_get_bootlocation

Split up some of the functionality in grub_machine_get_bootlocation into
grub_ieee1275_get_boot_dev.  This will allow for code reuse in a follow on
patch.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agochainloader: patch in BPB's sectors_per_track and num_heads
C. Masloch [Thu, 1 Feb 2018 14:51:55 +0000 (15:51 +0100)]
chainloader: patch in BPB's sectors_per_track and num_heads

These fields must reflect the ROM-BIOS's geometry for CHS-based
loaders to correctly load their next stage. Most loaders do not
query the ROM-BIOS (Int13.08), relying on the BPB fields to hold
the correct values already.

Tested with lDebug booted in qemu via grub2's
FreeDOS direct loading support, refer to
https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug
(For this test, lDebug's iniload.asm must be assembled with
-D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.)

Signed-off-by: C. Masloch <pushbx@38.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agogrub-mkconfig/10_linux: Support multiple early initrd images
Matthew S. Turnbull [Sat, 24 Feb 2018 22:44:58 +0000 (17:44 -0500)]
grub-mkconfig/10_linux: Support multiple early initrd images

Add support for multiple, shared, early initrd images. These early
images will be loaded in the order declared, and all will be loaded
before the initrd image.

While many classes of data can be provided by early images, the
immediate use case would be for distributions to provide CPU
microcode to mitigate the Meltdown and Spectre vulnerabilities.

There are two environment variables provided for declaring the early
images.

* GRUB_EARLY_INITRD_LINUX_STOCK is for the distribution declare
  images that are provided by the distribution or installed packages.
  If undeclared, this will default to a set of common microcode image
  names.

* GRUB_EARLY_INITRD_LINUX_CUSTOM is for user created images. User
  images will be loaded after the stock images.

These separate configurations allow the distribution and user to
declare different image sets without clobbering each other.

This also makes a minor update to ensure that UUID partition labels
stay disabled when no initrd image is found, even if early images are
present.

This is a continuation of a previous patch published by Christian
Hesse in 2016:
http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00025.html

Down stream Gentoo bug:
https://bugs.gentoo.org/645088

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: Matthew S. Turnbull <sparky@bluefang-logic.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: fix build regression in grub_mkimage_load_image
Eric Snowberg [Tue, 6 Mar 2018 21:38:58 +0000 (13:38 -0800)]
mkimage: fix build regression in grub_mkimage_load_image

The grub_mkimage_load_image function (commit 7542af6, mkimage: refactor a bunch
of section data into a struct.) introduces a build regression on SPARC:

  cc1: warnings being treated as errors
  In file included from util/grub-mkimage32.c:23:
  util/grub-mkimagexx.c: In function 'grub_mkimage_load_image32':
  util/grub-mkimagexx.c:1968: error: missing initializer
  util/grub-mkimagexx.c:1968: error: (near initialization for 'smd.sections')
  make[2]: *** [util/grub_mkimage-grub-mkimage32.o] Error 1

Initialize the entire section_metadata structure.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoRevert "Keep the native terminal active when enabling gfxterm"
dann frazier [Fri, 2 Mar 2018 17:02:19 +0000 (10:02 -0700)]
Revert "Keep the native terminal active when enabling gfxterm"

This can cause an issue where GRUB is trying to display both a text and
graphical menu on the display at the same time, resulting in a flickering
effect when e.g. scrolling quickly through a menu (LP: #1752767).

Revert for now while we look for a better solution for the original issue.

This reverts commit 52ef7b23f528ce844716661d586497a177e80d5b.

Signed-off-by: dann frazier <dann.frazier@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agosparc64: #blocks64 disk node method
Eric Snowberg [Tue, 27 Feb 2018 01:34:20 +0000 (17:34 -0800)]
sparc64: #blocks64 disk node method

Return the 64bit number of blocks of storage associated with the device or
instance. Where a "block" is a unit of storage consisting of the number of
bytes returned by the package's "block-size" method. If the size cannot be
determined, or if the number of blocks exceeds the range return -1.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agosparc64: #blocks disk node method
Eric Snowberg [Tue, 27 Feb 2018 01:34:19 +0000 (17:34 -0800)]
sparc64: #blocks disk node method

Return the number of blocks of storage associated with the device or
instance. Where a "block" is a unit of storage consisting of the number
of bytes returned by the package's "block-size" method. If the size cannot
be determined, the #blocks method returns the maximum unsigned integer
(which, because of Open Firmware's assumption of two's complement arithmetic,
is equivalent to the signed number -1). If the number of blocks exceeds
the range of an unsigned number, return 0 to alert the caller to try
the #blocks64 command.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: block-size deblocker support method
Eric Snowberg [Tue, 27 Feb 2018 01:34:18 +0000 (17:34 -0800)]
ieee1275: block-size deblocker support method

IEEE Std 1275-1994 Standard for Boot (Initialization Configuration)
Firmware: Core Requirements and Practices

3.8.3 deblocker support package

Any package that uses the "deblocker" support package must define
the following method, which the deblocker uses as a low-level
interface to the device

block-size ( -- block-len ) Return "granularity" for accesses to this
device.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: no-data-command bus specific method
Daniel Kiper [Mon, 5 Mar 2018 14:11:18 +0000 (15:11 +0100)]
ieee1275: no-data-command bus specific method

IEEE 1275-1994 Standard for Boot (Initialization Configuration)
Firmware: Core Requirements and Practices

E.3.2.2 Bus-specific methods for bus nodes

A package implementing the scsi-2 device type shall implement the
following bus-specific method:

no-data-command ( cmd-addr -- error? )
Executes a simple SCSI command, automatically retrying under
certain conditions.  cmd-addr is the address of a 6-byte command buffer
containing an SCSI command that does not have a data transfer phase.
Executes the command, retrying indefinitely with the same retry criteria
as retry-command.

error? is nonzero if an error occurred, zero otherwise.
NOTE no-data-command is a convenience function. It provides
no capabilities that are not present in retry-command, but for
those commands that meet its restrictions, it is easier to use.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: set-address bus specific method
Eric Snowberg [Tue, 27 Feb 2018 01:34:16 +0000 (17:34 -0800)]
ieee1275: set-address bus specific method

IEEE 1275-1994 Standard for Boot (Initialization Configuration)
Firmware: Core Requirements and Practices
E.3.2.2 Bus-specific methods for bus nodes

A package implementing the scsi-2 device type shall implement the
following bus-specific method:

 set-address ( unit# target# -- )
   Sets the SCSI target number (0x0..0xf) and unit number (0..7) to which
   subsequent commands apply.

This function is for devices with #address-cells == 2

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: encode-unit command for 4 addr cell devs
Eric Snowberg [Tue, 27 Feb 2018 01:34:15 +0000 (17:34 -0800)]
ieee1275: encode-unit command for 4 addr cell devs

Convert physical address to text unit-string.

Convert phys.lo ... phys-high, the numerical representation, to unit-string,
the text string representation of a physical address within the address
space defined by this device node. The number of cells in the list
phys.lo ... phys.hi is determined by the value of the #address-cells property
of this node.

This function is for devices with #address-cells == 4

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: decode-unit command for 4 addr cell devs
Eric Snowberg [Tue, 27 Feb 2018 01:34:14 +0000 (17:34 -0800)]
ieee1275: decode-unit command for 4 addr cell devs

decode-unit ( addr len -- phys.lo ... phys.hi )

Convert text unit-string to physical address.

Convert unit-string, the text string representation, to phys.lo ... phys.hi,
the numerical representation of a physical address within the address space
defined by this device node. The number of cells in the list
phys.lo ... phys.hi is determined by the value of the #address-cells
property of this node.

This function is for devices with #address-cells == 4

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agosparc64: Limit nvme of_path_of_nvme to just SPARC
Eric Snowberg [Fri, 2 Mar 2018 03:25:09 +0000 (19:25 -0800)]
sparc64: Limit nvme of_path_of_nvme to just SPARC

Limit NVMe of_path_of_nvme to just SPARC hardware for now.  It has been
found that non-Open Firmware hardware platforms can some how access
this function.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: Fix crash in of_path_of_nvme when of_path is empty
John Paul Adrian Glaubitz [Thu, 1 Mar 2018 22:34:53 +0000 (23:34 +0100)]
ieee1275: Fix crash in of_path_of_nvme when of_path is empty

The of_path_of_nvme function (commit 2391d57, ieee1275: add nvme
support within ofpath) introduced a functional regression:

On systems which are not based on Open Firmware but have at
least one NVME device, find_obppath will return NULL and thus
trying to append the disk name to of_path will result in a
crash.

The proper behavior of of_path_of_nvme is, however, to just
return NULL in such cases, like other users of find_obppath,
such as of_path_of_scsi.

Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years ago.mod files: Strip annobin annotations and .eh_frame, and their relocations
Peter Jones [Wed, 21 Feb 2018 20:20:29 +0000 (15:20 -0500)]
.mod files: Strip annobin annotations and .eh_frame, and their relocations

This way debuginfo built from the .module will still include this
information, but the final result won't have the data we don't actually
need in the modules, either on-disk, loaded at runtime, or in prebuilt
images.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: avoid copying relocations for sections that won't be copied.
Peter Jones [Wed, 21 Feb 2018 20:20:28 +0000 (15:20 -0500)]
mkimage: avoid copying relocations for sections that won't be copied.

Some versions of gcc include a plugin called "annobin", and in some
build systems this is enabled by default.  This plugin creates special
ELF note sections to track which ABI-breaking features are used by a
binary, as well as a series of relocations to annotate where.

If grub is compiled with this feature, then when grub-mkimage translates
the binary to another file format which does not strongly associate
relocation data with sections (i.e. when platform is *-efi), these
relocations appear to be against the .text section rather than the
original note section.  When the binary is loaded by the PE runtime
loader, hilarity ensues.

This issue is not necessarily limited to the annobin, but could arise
any time there are relocations in sections that are not represented in
grub-mkimage's output.

This patch seeks to avoid this issue by only including relocations that
refer to sections which will be included in the final binary.

As an aside, this should also obviate the need to avoid -funwind-tables,
-fasynchronous-unwind-tables, and any sections similar to .eh_frame in
the future.  I've tested it on x86-64-efi with the following gcc command
line options (as recorded by -grecord-gcc-flags), but I still need to
test the result on some other platforms that have been problematic in
the past (especially ARM Aarch64) before I feel comfortable making
changes to the configure.ac bits:

GNU C11 7.2.1 20180116 (Red Hat 7.2.1-7) -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -mno-stack-arg-probe -mcmodel=large -mno-red-zone -m64 -mtune=generic -march=x86-64 -g3 -Os -freg-struct-return -fno-stack-protector -ffreestanding -funwind-tables -fasynchronous-unwind-tables -fno-strict-aliasing -fstack-clash-protection -fno-ident -fplugin=annobin

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: refactor a bunch of section data into a struct.
Peter Jones [Wed, 21 Feb 2018 20:20:27 +0000 (15:20 -0500)]
mkimage: refactor a bunch of section data into a struct.

This basically moves a bunch of the section information we pass around a
lot into a struct, and passes a pointer to a single one of those
instead.

This shouldn't change the binary file output or the "grub-mkimage -v"
output in any way.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: make locate_sections() set up vaddresses as well.
Peter Jones [Wed, 21 Feb 2018 20:20:26 +0000 (15:20 -0500)]
mkimage: make locate_sections() set up vaddresses as well.

This puts both kinds of address initialization at the same place, and also lets
us iterate through the section list one time fewer.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: rename a couple of things to be less confusing later.
Peter Jones [Wed, 21 Feb 2018 20:20:25 +0000 (15:20 -0500)]
mkimage: rename a couple of things to be less confusing later.

This renames some things:

- the "strtab" and "strtab_section" in relocate_symbols are changed to "symtab"
  instead, so as to be less confusing when "strtab" is moved to a struct in a
  later patch.

- The places where we pass section_vaddresses to functions are changed to also
  be called section_vaddresses"inside those functions, so I get less confused
  when I put addresses and vaddresses in a struct in a later patch.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: make it easier to run syntax checkers on grub-mkimagexx.c
Peter Jones [Wed, 21 Feb 2018 20:20:24 +0000 (15:20 -0500)]
mkimage: make it easier to run syntax checkers on grub-mkimagexx.c

This makes it so you can treat grub-mkimagexx.c as a file you can build
directly, so syntax checkers like vim's "syntastic" plugin, which uses
"gcc -x c -fsyntax-only" to build it, will work.

One still has to do whatever setup is required to make it pick the right
include dirs, which -W options we use, etc., but this makes it so you
can do the checking on the file you're editing, rather than on a
different file.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoaout.h: Fix missing include.
Peter Jones [Wed, 21 Feb 2018 20:20:23 +0000 (15:20 -0500)]
aout.h: Fix missing include.

grub_aout_load() has a grub_file_t parameter, and depending on what order
includes land in, it's sometimes not defined.  This patch explicitly adds
file.h to aout.h so that it will always be defined.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: fix build regression in of_path_of_nvme
Joakim Bech [Mon, 26 Feb 2018 08:57:34 +0000 (09:57 +0100)]
ieee1275: fix build regression in of_path_of_nvme

The of_path_of_nvme function (commit 2391d57, ieee1275: add nvme
support within ofpath) introduced a build regression:
    grub-core/osdep/linux/ofpath.c:365:21: error: comparison between pointer
    and zero character constant [-Werror=pointer-compare]
       if ((digit_string != '\0') && (*part_end == 'p'))

Update digit_string to compare against the char instead of the pointer.

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm: make linux.h safe to include for non-native builds
Leif Lindholm [Thu, 1 Feb 2018 18:18:56 +0000 (18:18 +0000)]
arm: make linux.h safe to include for non-native builds

<grub/machine/loader.h> (for machine arm/efi) and
<grub/machine/kernel.h> (for machine arm/coreboot) will not always
resolve (and will likely not be valid to) if pulled in when building
non-native commands, such as host tools or the "file" command.
So explicitly include them with their expanded pathnames.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm: switch linux loader to linux_arm_kernel_header struct
Leif Lindholm [Thu, 1 Feb 2018 18:18:55 +0000 (18:18 +0000)]
arm: switch linux loader to linux_arm_kernel_header struct

Use kernel header struct and magic definition to align (and coexist) with
i386/arm64 ports.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64: align linux kernel magic macro naming with i386
Leif Lindholm [Thu, 1 Feb 2018 18:18:54 +0000 (18:18 +0000)]
arm64: align linux kernel magic macro naming with i386

Change GRUB_ARM64_LINUX_MAGIC to GRUB_LINUX_ARM64_MAGIC_SIGNATURE.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64: align linux kernel header struct naming with i386
Leif Lindholm [Thu, 1 Feb 2018 18:18:53 +0000 (18:18 +0000)]
arm64: align linux kernel header struct naming with i386

Rename struct grub_arm64_linux_kernel_header -> linux_arm64_kernel_header.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoi386: make struct linux_kernel_header architecture specific
Leif Lindholm [Thu, 1 Feb 2018 18:18:52 +0000 (18:18 +0000)]
i386: make struct linux_kernel_header architecture specific

struct linux_kernel_header -> struct linux_i386_kernel_header

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomake GRUB_LINUX_MAGIC_SIGNATURE architecture-specific
Leif Lindholm [Thu, 1 Feb 2018 18:18:51 +0000 (18:18 +0000)]
make GRUB_LINUX_MAGIC_SIGNATURE architecture-specific

Rename GRUB_LINUX_MAGIC_SIGNATURE GRUB_LINUX_I386_MAGIC_SIGNATURE,
to be usable in code that supports more than one image type.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoMake arch-specific linux.h include guards architecture unique
Leif Lindholm [Thu, 1 Feb 2018 18:18:50 +0000 (18:18 +0000)]
Make arch-specific linux.h include guards architecture unique

Replace uses of GRUB_LINUX_MACHINE_HEADER and GRUB_LINUX_CPU_HEADER
with GRUB_<arch>_LINUX_HEADER include guards to prevent issues when
including more than one of them.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64/efi: move EFI_PAGE definitions to efi/memory.h
Leif Lindholm [Thu, 1 Feb 2018 18:18:49 +0000 (18:18 +0000)]
arm64/efi: move EFI_PAGE definitions to efi/memory.h

The EFI page definitions and macros are generic and should not be confined
to arm64 headers - so move to efi/memory.h.
Also add EFI_PAGE_SIZE macro.

Update loader sources to reflect new header location.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agolibgcrypt: Import replacement CRC operations
Colin Watson [Sun, 11 Feb 2018 00:18:12 +0000 (00:18 +0000)]
libgcrypt: Import replacement CRC operations

The CRC implementation imported from libgcrypt 1.5.3 is arguably
non-free, due to being encumbered by the restrictive Internet Society
licence on RFCs (see e.g. https://wiki.debian.org/NonFreeIETFDocuments).
Fortunately, libgcrypt has since replaced it with a version that is both
reportedly better-optimised and doesn't suffer from this encumbrance.

The ideal solution would be to update to a new version of libgcrypt, and
I spent some time trying to do that.  However, util/import_gcry.py
requires complex modifications to cope with the new version, and I
stalled part-way through; furthermore, GRUB's libgcrypt tree already
contains some backports of upstream changes.  Rather than allowing the
perfect to be the enemy of the good, I think it's best to backport this
single change to at least sort out the licensing situation.  Doing so
won't make things any harder for a future wholesale upgrade.

This commit is mostly a straightforward backport of
https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=commitdiff;h=06e122baa3321483a47bbf82fd2a4540becfa0c9,
but I also imported bufhelp.h from libgcrypt 1.7.0 (newer versions
required further changes elsewhere).

I've tested that "hashsum -h crc32" still produces correct output for a
variety of files on both i386-pc and x86_64-emu targets.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: add nvme support within ofpath
Eric Snowberg [Tue, 20 Feb 2018 17:57:14 +0000 (09:57 -0800)]
ieee1275: add nvme support within ofpath

Add NVMe support within ofpath.

The Open Firmware text representation for a NVMe device contains the
Namespace ID. An invalid namespace ID is one whose value is zero or whose
value is greater than the value reported by the Number of Namespaces (NN)
field in the Identify Controller data structure.  At the moment  only a
single Namespace is supported, therefore the value is currently hard coded
to one.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agochainloader: Fix wrong break condition (must be AND not, OR)
Daniel Kiper [Fri, 23 Feb 2018 21:32:55 +0000 (22:32 +0100)]
chainloader: Fix wrong break condition (must be AND not, OR)

The definition of bpb's num_total_sectors_16 and num_total_sectors_32
is that either the 16-bit field is non-zero and is used (in which case
eg mkfs.fat sets the 32-bit field to zero), or it is zero and the
32-bit field is used. Therefore, a BPB is invalid only if *both*
fields are zero; having one field as zero and the other as non-zero is
the case to be expected. (Indeed, according to Microsoft's specification
one of the fields *must* be zero, and the other non-zero.)

This affects all users of grub_chainloader_patch_bpb which are in
chainloader.c, freedos.c, and ntldr.c

Some descriptions of the semantics of these two fields:

https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html

  The old 2-byte fields "total number of sectors" and "number of
  sectors per FAT" are now zero; this information is now found in
  the new 4-byte fields.

(Here given in the FAT32 EBPB section but the total sectors 16/32 bit
fields semantic is true of FAT12 and FAT16 too.)

https://wiki.osdev.org/FAT#BPB_.28BIOS_Parameter_Block.29

  19 | 2 | The total sectors in the logical volume. If this value is 0,
  it means there are more than 65535 sectors in the volume, and the actual
  count is stored in "Large Sectors (bytes 32-35).

  32 | 4 | Large amount of sector on media. This field is set if there
  are more than 65535 sectors in the volume.

(Doesn't specify what the "large" field is set to when unused, but as
mentioned mkfs.fat sets it to zero then.)

https://technet.microsoft.com/en-us/library/cc976796.aspx

  0x13 | WORD | 0x0000 |
  Small Sectors . The number of sectors on the volume represented in 16
  bits (< 65,536). For volumes larger than 65,536 sectors, this field
  has a value of zero and the Large Sectors field is used instead.

  0x20 | DWORD | 0x01F03E00 |
  Large Sectors . If the value of the Small Sectors field is zero, this
  field contains the total number of sectors in the FAT16 volume. If the
  value of the Small Sectors field is not zero, the value of this field
  is zero.

https://staff.washington.edu/dittrich/misc/fatgen103.pdf page 10

  BPB_TotSec16 | 19 | 2 |
  This field is the old 16-bit total count of sectors on the volume.
  This count includes the count of all sectors in all four regions of the
  volume. This field can be 0; if it is 0, then BPB_TotSec32 must be
  non-zero. For FAT32 volumes, this field must be 0. For FAT12 and
  FAT16 volumes, this field contains the sector count, and
  BPB_TotSec32 is 0 if the total sector count “fits” (is less than
  0x10000).

  BPB_TotSec32 | 32 | 4 |
  This field is the new 32-bit total count of sectors on the volume.
  This count includes the count of all sectors in all four regions of the
  volume. This field can be 0; if it is 0, then BPB_TotSec16 must be
  non-zero. For FAT32 volumes, this field must be non-zero. For
  FAT12/FAT16 volumes, this field contains the sector count if
  BPB_TotSec16 is 0 (count is greater than or equal to 0x10000).

(This specifies that an unused BPB_TotSec32 field is set to zero.)

By the way fix offsets in include/grub/fat.h.

Tested with lDebug booted in qemu via grub2's
FreeDOS direct loading support, refer to
https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug

Signed-off-by: C. Masloch <pushbx@38.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agox86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32
H.J. Lu [Sat, 17 Feb 2018 14:47:28 +0000 (06:47 -0800)]
x86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32

Starting from binutils commit bd7ab16b4537788ad53521c45469a1bdae84ad4a:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bd7ab16b4537788ad53521c45469a1bdae84ad4a

x86-64 assembler generates R_X86_64_PLT32, instead of R_X86_64_PC32, for
32-bit PC-relative branches.  Grub2 should treat R_X86_64_PLT32 as
R_X86_64_PC32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoMake grub-install check for errors from efibootmgr
Steve McIntyre [Wed, 31 Jan 2018 21:49:36 +0000 (21:49 +0000)]
Make grub-install check for errors from efibootmgr

Code is currently ignoring errors from efibootmgr, giving users
clearly bogus output like:

        Setting up grub-efi-amd64 (2.02~beta3-4) ...
        Installing for x86_64-efi platform.
        Could not delete variable: No space left on device
        Could not prepare Boot variable: No space left on device
        Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install
should know that and report it!

We've been using similar patch in Debian now for some time, with no ill effects.

Signed-off-by: Steve McIntyre <93sam@debian.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agosparc64: fix OF path names for sun4v systems
Eric Snowberg [Wed, 31 Jan 2018 04:49:48 +0000 (20:49 -0800)]
sparc64: fix OF path names for sun4v systems

Fix the Open Firmware (OF) path property for sun4v SPARC systems.
These platforms do not have a /sas/ within their path. Over time
different OF addressing schemes have been supported. There
is no generic addressing scheme that works across every HBA.

It looks that this functionality will not work if you try to cross-install
SPARC GRUB2 binary using e.g. x86 grub-install. By default it should work.
However, we will also have other issues here, like lack of access to OF
firmware/paths, which make such configs unusable anyway. So, let's leave
this patch as is for time being. If somebody cares then he/she should fix
the issue(s) at some point.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agosparc64: Add blocklist GPT support for SPARC
Eric Snowberg [Fri, 12 May 2017 01:25:24 +0000 (18:25 -0700)]
sparc64: Add blocklist GPT support for SPARC

Add block-list GPT support for SPARC.  The OBP "load" and "boot" methods
are partition aware and neither command can see the partition table. Also
neither command can address the entire physical disk. When the install
happens, grub generates the block-list entries based on the beginning of the
physical disk, not the beginning of the partition. This patch fixes the
block-list entries so they match what OBP expects during boot for a GPT disk.

T5 and above now supports GPT as well as VTOC.

This patch has been tested on T5-2 and newer SPARC systems.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoahci: Improve error handling
Stefan Fritsch [Fri, 19 Jan 2018 13:13:29 +0000 (14:13 +0100)]
ahci: Improve error handling

Check the error bits in the interrupt status register. According to the
AHCI 1.2 spec, "Interrupt sources that are disabled (‘0’) are still
reflected in the status registers.", so this should work even though
grub uses polling

This fixes the following problem on a Fujitsu E744 laptop:

Sometimes there is a very long delay (up to several minutes) when
booting from hard disk. It seems accessing the DVD drive (which has no
disk inserted) sometimes fails with some errors, which leads to each
access being stalled until the 20s timeout triggers. This seems to
happen when grub is trying to read filesystem/partition data.

The problem is that the command_issue bit that is checked in the loop is
only reset if the "HBA receives a FIS which clears the BSY, DRQ, and ERR
bits for the command", but the ERR bit is never cleared. Therefore
command_issue is never reset and grub waits for the timeout.

The relevant bit in our case is the Task File Error Status (TFES), which
is equivalent to the ERR bit 0 in tfd. But this patch also checks
the other error bits except for the "Interface non-fatal error status"
bit.

Signed-off-by: Stefan Fritsch <fritsch@genua.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoKeep the native terminal active when enabling gfxterm
dann frazier [Thu, 18 Jan 2018 18:57:26 +0000 (11:57 -0700)]
Keep the native terminal active when enabling gfxterm

grub-mkconfig will set GRUB_TERMINAL_OUTPUT to "gfxterm" unless the user
has overridden it. On EFI systems, this will stop output from going to the
default "console" terminal. When the EFI fw console is configured to output to
both serial and video, this will cause GRUB to only display on video - while
continuing to accept input from both video and serial.

Instead of switching from "console" to "gfxterm", let's output to both.

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64/xen: Add missing #address-cells and #size-cells properties
Julien Grall [Wed, 29 Nov 2017 17:08:12 +0000 (17:08 +0000)]
arm64/xen: Add missing #address-cells and #size-cells properties

The properties #address-cells and #size-cells are used to know the
number of cells for ranges provided by "regs". If they don't exist, the
value are resp. 2 and 1.

Currently, when multiboot nodes are created it is assumed that #address-cells
and #size-cells are exactly 2. However, they are never set by GRUB and
will result to later failure when the device-tree is generated by GRUB
or contain different values.

To prevent this failure, create the both properties in the chosen nodes.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agogrub-mkconfig: Fix detecting .sig files as system images
Jordan Glover [Wed, 29 Nov 2017 13:35:37 +0000 (08:35 -0500)]
grub-mkconfig: Fix detecting .sig files as system images

grub-mkconfig detects detached RSA signatures for kernel images used for
signature checking as valid images and adds them to grub.cfg as separate
menu entries. This patch adds .sig extension to common blacklist.

Signed-off-by: Jordan Glover <Golden_Miller83@protonmail.ch>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoieee1275: Fix segfault in grub-ofpathname
Eric Snowberg [Tue, 28 Nov 2017 19:51:39 +0000 (11:51 -0800)]
ieee1275: Fix segfault in grub-ofpathname

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agogrub-install: Fix memory leak
Eric Snowberg [Mon, 27 Nov 2017 17:12:49 +0000 (09:12 -0800)]
grub-install: Fix memory leak

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agols: prevent double open
Eric Snowberg [Mon, 13 Nov 2017 16:27:28 +0000 (08:27 -0800)]
ls: prevent double open

Prevent a double open.  This can cause problems with some ieee1275
devices, causing the system to hang.  The double open can occur
as follows:

grub_ls_list_files (char *dirname, int longlist, int all, int human)
       dev = grub_device_open (device_name);
       dev remains open while:
       grub_normal_print_device_info (device_name);
                dev = grub_device_open (name);

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agotsc: Change default tsc calibration method to pmtimer on EFI systems
David E. Box [Fri, 15 Sep 2017 22:37:05 +0000 (15:37 -0700)]
tsc: Change default tsc calibration method to pmtimer on EFI systems

On efi systems, make pmtimer based tsc calibration the default over the
pit. This prevents Grub from hanging on Intel SoC systems that power gate
the pit.

Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoefi: Free malloc regions on exit
Alexander Graf [Thu, 31 Aug 2017 14:40:19 +0000 (16:40 +0200)]
efi: Free malloc regions on exit

When we exit grub, we don't free all the memory that we allocated earlier
for our heap region. This can cause problems with setups where you try
to descend the boot order using "exit" entries, such as PXE -> HD boot
scenarios.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoefi: Move grub_reboot() into kernel
Alexander Graf [Thu, 31 Aug 2017 14:40:18 +0000 (16:40 +0200)]
efi: Move grub_reboot() into kernel

The reboot function calls machine_fini() and then reboots the system.
Currently it lives in lib/ which means it gets compiled into the
reboot module which lives on the heap.

In a following patch, I want to free the heap on machine_fini()
though, so we would free the memory that the code is running in. That
obviously breaks with smarter UEFI implementations.

So this patch moves it into the core. That way we ensure that all
code running after machine_fini() in the UEFI case is running from
memory that got allocated (and gets deallocated) by the UEFI core.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoUse grub-file to figure out whether multiboot2 should be used for Xen.gz
Konrad Rzeszutek Wilk [Tue, 29 Aug 2017 20:40:53 +0000 (16:40 -0400)]
Use grub-file to figure out whether multiboot2 should be used for Xen.gz

The multiboot2 is much more preferable than multiboot. Especiall
if booting under EFI where multiboot does not have the functionality
to pass ImageHandler.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoFix util/grub.d/20_linux_xen.in: Add xen_boot command support for aarch64
Konrad Rzeszutek Wilk [Tue, 29 Aug 2017 20:40:52 +0000 (16:40 -0400)]
Fix util/grub.d/20_linux_xen.in: Add xen_boot command support for aarch64

Commit d33045ce7ffcb7c1e4a60c14d5ca64b36e3c5abe introduced
the support for this, but it does not work under x86 (as it stops
20_linux_xen from running).

The 20_linux_xen is run under a shell and any exits from within it:

(For example on x86):
+ /usr/bin/grub2-file --is-arm64-efi /boot/xen-4.9.0.gz
[root@tst063 grub]# echo $?
1

will result in 20_linux_xen exiting without continuing
and also causing grub2-mkconfig to stop processing.

As in:

 [root@tst063 grub]# ./grub-mkconfig | tail
 Generating grub configuration file ...
 Found linux image: /boot/vmlinuz-4.13.0-0.rc5.git1.1.fc27.x86_64
 Found initrd image: /boot/initramfs-4.13.0-0.rc5.git1.1.fc27.x86_64.img
 Found linux image: /boot/vmlinuz-0-rescue-ec082ee24aea41b9b16aca52a6d10cc2
 Found initrd image: /boot/initramfs-0-rescue-ec082ee24aea41b9b16aca52a6d10cc2.img
  echo 'Loading Linux 0-rescue-ec082ee24aea41b9b16aca52a6d10cc2 ...'
  linux /vmlinuz-0-rescue-ec082ee24aea41b9b16aca52a6d10cc2 root=/dev/mapper/fedora_tst063-root ro single
  echo 'Loading initial ramdisk ...'
  initrd /initramfs-0-rescue-ec082ee24aea41b9b16aca52a6d10cc2.img
  }
 }

 ### END /usr/local/etc/grub.d/10_linux ###

 ### BEGIN /usr/local/etc/grub.d/20_linux_xen ###

 root@tst063 grub]#

And no more.

This patch wraps the invocation of grub-file to be a in subshell
and to process the return value in a conditional. That fixes
the issue.

RH-BZ 1486002: grub2-mkconfig does not work if xen.gz is installed.

CC: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoFix compilation for x86_64-efi.
Vladimir Serbinenko [Thu, 7 Sep 2017 11:55:22 +0000 (13:55 +0200)]
Fix compilation for x86_64-efi.

6 years agoAdd a file missing in multiboot2 commit.
Vladimir Serbinenko [Tue, 5 Sep 2017 21:13:55 +0000 (23:13 +0200)]
Add a file missing in multiboot2 commit.

6 years agogzio: fix unaligned access
Vladimir Serbinenko [Wed, 30 Aug 2017 18:46:14 +0000 (20:46 +0200)]
gzio: fix unaligned access

6 years agogrub-fs-tester: Fix bashism
Vladimir Serbinenko [Wed, 30 Aug 2017 15:22:58 +0000 (17:22 +0200)]
grub-fs-tester: Fix bashism

6 years agoRegenerate checksum.h with newer unifont.
Vladimir Serbinenko [Wed, 30 Aug 2017 15:12:04 +0000 (17:12 +0200)]
Regenerate checksum.h with newer unifont.

Old link is broken. New unifont is
http://ftp.de.debian.org/debian/pool/main/u/unifont/xfonts-unifont_9.0.06-2_all.deb

6 years agoprintf_unit_test: Disable Wformat-truncation on GCC >= 7
Vladimir Serbinenko [Wed, 30 Aug 2017 14:59:25 +0000 (16:59 +0200)]
printf_unit_test: Disable Wformat-truncation on GCC >= 7

We intentionally pass NULL as argument to format, hence disable the warning.

6 years agoqemu, coreboot, multiboot: Change linking address to 0x9000.
Vladimir Serbinenko [Wed, 30 Aug 2017 14:29:59 +0000 (16:29 +0200)]
qemu, coreboot, multiboot: Change linking address to 0x9000.

It's common for distros to use a defective ld which links at 0x9000. Instead
of fighting it, just move link target to 0x9000.

6 years agoImplement checksum verification for gunzip
Stefan Fritsch [Sun, 1 May 2016 12:32:30 +0000 (14:32 +0200)]
Implement checksum verification for gunzip

This implements the crc32 check for the gzip format. Support for zlib's
adler checksum is not included, yet.

6 years agoxfs: Don't attempt to iterate over empty directory.
Vladimir Serbinenko [Wed, 30 Aug 2017 13:56:19 +0000 (15:56 +0200)]
xfs: Don't attempt to iterate over empty directory.

Reported by: Tuomas Tynkkynen

6 years agounix exec: avoid atexit handlers when child exits
Patrick Steinhardt [Mon, 28 Aug 2017 18:57:19 +0000 (20:57 +0200)]
unix exec: avoid atexit handlers when child exits

The `grub_util_exec_redirect_all` helper function can be used to
spawn an executable and redirect its output to some files. After calling
`fork()`, the parent will wait for the child to terminate with
`waitpid()` while the child prepares its file descriptors, environment
and finally calls `execvp()`. If something in the children's setup
fails, it will stop by calling `exit(127)`.

Calling `exit()` will cause any function registered via `atexit()` to be
executed, which is usually the wrong thing to do in a child. And
actually, one can easily observe faulty behaviour on musl-based systems
without modprobe(8) installed: executing `grub-install --help` will call
`grub_util_exec_redirect_all` with "modprobe", which obviously fails if
modprobe(8) is not installed. Due to the child now exiting and invoking
the `atexit()` handlers, it will clean up some data structures of the
parent and cause it to be deadlocked in the `waitpid()` syscall.

The issue can easily be fixed by calling `_exit(127)` instead, which is
especially designed to be called when the atexit-handlers should not be
executed.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
6 years agoarc: Do not create spurious variable grub_arc_memory_type_t.
Vladimir Serbinenko [Wed, 30 Aug 2017 13:18:24 +0000 (15:18 +0200)]
arc: Do not create spurious variable grub_arc_memory_type_t.

6 years agoSet have_exec to y on cygwin so we have grub_mkrescue.
Xuan Guo [Mon, 14 Aug 2017 14:27:53 +0000 (16:27 +0200)]
Set have_exec to y on cygwin so we have grub_mkrescue.

6 years agoenforcing fixup
Vladimir Serbinenko [Mon, 14 Aug 2017 14:27:10 +0000 (16:27 +0200)]
enforcing fixup

6 years agomultiboot fixup
Vladimir Serbinenko [Mon, 14 Aug 2017 14:24:05 +0000 (16:24 +0200)]
multiboot fixup

6 years agolinux fixup
Vladimir Serbinenko [Mon, 14 Aug 2017 14:23:52 +0000 (16:23 +0200)]
linux fixup

6 years agoyylex: Explicilty cast fprintf to void.
Vladimir Serbinenko [Mon, 14 Aug 2017 12:11:43 +0000 (14:11 +0200)]
yylex: Explicilty cast fprintf to void.

It's needed to avoid warning on recent GCC.

6 years agogenmoddep: Check that no modules provide the same symbol.
Vladimir Serbinenko [Mon, 14 Aug 2017 12:10:48 +0000 (14:10 +0200)]
genmoddep: Check that no modules provide the same symbol.

The semantics of 2 modules providing the same symbol are undefined. So
ensure that it doesn't happen.

6 years agoFix symbols appearing in several modules in linux*.
Vladimir Serbinenko [Mon, 14 Aug 2017 12:09:30 +0000 (14:09 +0200)]
Fix symbols appearing in several modules in linux*.

If same symbol is provided by 2 modules its semantics are undefined.
Avoid this by depending rather than double-including files.

6 years agomultiboot: disentangle multiboot and multiboot2.
Vladimir Serbinenko [Mon, 14 Aug 2017 10:51:26 +0000 (12:51 +0200)]
multiboot: disentangle multiboot and multiboot2.

Previously we had multiboot and multiboot2 declaring the same symbols.
This can potentially lead to aliasing and strange behaviours when e.g.
module instead of module2 is used with multiboot2.

Bug: #51137

6 years agohdparm: Depend on hexdump rather than having a second copy of hexdump.
Vladimir Serbinenko [Mon, 14 Aug 2017 10:48:58 +0000 (12:48 +0200)]
hdparm: Depend on hexdump rather than having a second copy of hexdump.

6 years agogrub.texi: Fix typo
Vladimir Serbinenko [Mon, 14 Aug 2017 09:36:50 +0000 (11:36 +0200)]
grub.texi: Fix typo

Reported by:  Ori Avtalion <saltyhorse>

6 years agoio: add a GRUB_GZ prefix to gzio specific defines
Pete Batard [Mon, 7 Aug 2017 15:23:12 +0000 (16:23 +0100)]
io: add a GRUB_GZ prefix to gzio specific defines

* This is done to avoid a conflict with a PACKED define in the EDK2

6 years agocore: use GRUB_TERM_ definitions when handling term characters
Pete Batard [Mon, 7 Aug 2017 15:20:30 +0000 (16:20 +0100)]
core: use GRUB_TERM_ definitions when handling term characters

* Also use hex value for GRUB_TERM_ESC as '\e' is not in the C standard and is not understood by some compilers

6 years agoefi: change heap allocation type to GRUB_EFI_LOADER_CODE
Leif Lindholm [Thu, 3 Aug 2017 10:04:32 +0000 (11:04 +0100)]
efi: change heap allocation type to GRUB_EFI_LOADER_CODE

With upcoming changes to EDK2, allocations of type EFI_LOADER_DATA may
not return regions with execute ability. Since modules are loaded onto
the heap, change the heap allocation type to GRUB_EFI_LOADER_CODE in
order to permit execution on systems with this feature enabled.

Closes: 50420

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoarm64 linux loader: improve type portability
Leif Lindholm [Thu, 3 Aug 2017 10:04:26 +0000 (11:04 +0100)]
arm64 linux loader: improve type portability

In preparation for turning this into a common loader for 32-bit and 64-bit
platforms, ensure the code will compile cleanly for either.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoefi: Add GRUB_PE32_MAGIC definition
Leif Lindholm [Thu, 3 Aug 2017 10:04:25 +0000 (11:04 +0100)]
efi: Add GRUB_PE32_MAGIC definition

Add a generic GRUB_PE32_MAGIC definition for the PE 'MZ' tag and delete
the existing one in arm64/linux.h.

Update arm64 Linux loader to use this new definition.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoefi: move fdt helper library
Leif Lindholm [Thu, 3 Aug 2017 10:04:24 +0000 (11:04 +0100)]
efi: move fdt helper library

There is nothing ARM64 (or even ARM) specific about the efi fdt helper
library, which is used for locating or overriding a firmware-provided
devicetree in a UEFI system - so move it to loader/efi for reuse.

Move the fdtload.h include file to grub/efi and update path to
efi/fdtload.h in source code referring to it.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoRemove grub_efi_allocate_pages.
Vladimir Serbinenko [Mon, 7 Aug 2017 16:33:29 +0000 (18:33 +0200)]
Remove grub_efi_allocate_pages.

grub_efi_allocate_pages Essentially does 2 unrelated things:
* Allocate at fixed address.
* Allocate at any address.

To switch between 2 different functions it uses address == 0 as magic
value which is wrong as 0 is a perfectly valid fixed adress to allocate at.

6 years agoefi: refactor grub_efi_allocate_pages
Leif Lindholm [Thu, 3 Aug 2017 10:04:23 +0000 (11:04 +0100)]
efi: refactor grub_efi_allocate_pages

Expose a new function, grub_efi_allocate_pages_real(), making it possible
to specify allocation type and memory type as supported by the UEFI
AllocatePages boot service.

Make grub_efi_allocate_pages() a consumer of the new function,
maintaining its old functionality.

Also delete some left-around #if 1/#else blocks in the affected
functions.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoFail if xorriso failed.
Vladimir Serbinenko [Mon, 7 Aug 2017 16:08:39 +0000 (18:08 +0200)]
Fail if xorriso failed.

If xorriso failed most likely we didn't generate a meaningful image.

6 years agomkrescue: Check xorriso presence before doing anything else.
Vladimir Serbinenko [Mon, 7 Aug 2017 16:05:17 +0000 (18:05 +0200)]
mkrescue: Check xorriso presence before doing anything else.

mkrescue can't do anything useful without xorriso, so abort early if it's
not available.

6 years ago* grub-core/fs/udf.c: Add support for UUID
Pali Rohár [Thu, 22 Jun 2017 12:42:16 +0000 (14:42 +0200)]
* grub-core/fs/udf.c: Add support for UUID

Use same algorithm as in libblkid from util-linux v2.30.

1. Take first 16 bytes from UTF-8 encoded string of VolumeSetIdentifier
2. If all bytes are hexadecimal digits, convert to lowercase and use as UUID
3. If first 8 bytes are not all hexadecimal digits, convert those 8 bytes
   to their hexadecimal representation, resulting in 16 bytes for UUID
4. Otherwise, compose UUID from two parts:
   1. part: converted first 8 bytes (which are hexadecimal digits) to lowercase
   2. part: encoded following 4 bytes to their hexadecimal representation (16 bytes)

So UUID would always have 16 hexadecimal digits in lowercase variant.

According to UDF specification, first 16 Unicode characters of
VolumeSetIdentifier should be unique value and first 8 should be
hexadecimal characters.

In most cases all 16 characters are hexadecimal, but e.g. MS Windows
format.exe set only first 8 as hexadecimal and remaining as fixed
(non-unique) which violates specification.

6 years agoudf: Fix reading label, lvd.ident is dstring
Pali Rohár [Thu, 22 Jun 2017 12:33:17 +0000 (14:33 +0200)]
udf: Fix reading label, lvd.ident is dstring

UDF dstring has stored length in the last byte of buffer. Therefore last
byte is not part of recorded characters. And empty string in dstring is
encoded as empty buffer, including first byte (compression id).

6 years agozfs: remove size_t typedef and use grub_size_t instead
Pete Batard [Thu, 3 Aug 2017 14:46:15 +0000 (15:46 +0100)]
zfs: remove size_t typedef and use grub_size_t instead

* Prevents some toolchains from issuing a warning on size_t redef.

6 years agoFix a segfault in lsefi
Rob Clark [Wed, 19 Jul 2017 19:47:41 +0000 (15:47 -0400)]
Fix a segfault in lsefi

when protocols_per_handle returns error, we can't use the pointers we
passed to it, and that includes trusting num_protocols.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agofdt: silence clang warning.
Vladimir Serbinenko [Mon, 10 Jul 2017 01:34:22 +0000 (01:34 +0000)]
fdt: silence clang warning.

6 years agoarm-efi: Fix compilation
Vladimir Serbinenko [Sun, 9 Jul 2017 21:48:37 +0000 (21:48 +0000)]
arm-efi: Fix compilation

6 years agocrypto: Fix use after free.
AppChecker [Sun, 9 Jul 2017 19:57:35 +0000 (21:57 +0200)]
crypto: Fix use after free.

Reported by: AppChecker
Transformed to patch by: Satish Govindarajan

6 years agoehci: Fix compilation on i386
Vladimir Serbinenko [Sun, 9 Jul 2017 19:31:19 +0000 (21:31 +0200)]
ehci: Fix compilation on i386

6 years agocache: Fix compilation for ppc, sparc and arm64
phcoder [Sun, 9 Jul 2017 18:59:15 +0000 (20:59 +0200)]
cache: Fix compilation for ppc, sparc and arm64

6 years agoehci: Fix compilation for amd64
phcoder [Sun, 9 Jul 2017 18:58:31 +0000 (20:58 +0200)]
ehci: Fix compilation for amd64

6 years agoAllow GRUB to mount ext2/3/4 filesystems that have the encryption feature.
Eric Biggers [Thu, 29 Jun 2017 13:27:49 +0000 (13:27 +0000)]
Allow GRUB to mount ext2/3/4 filesystems that have the encryption feature.

On such a filesystem, inodes may have EXT4_ENCRYPT_FLAG set.
For a regular file, this means its contents are encrypted; for a
directory, this means the filenames in its directory entries are
encrypted; and for a symlink, this means its target is encrypted.  Since
GRUB cannot decrypt encrypted contents or filenames, just issue an error
if it would need to do so.  This is sufficient to allow unencrypted boot
files to co-exist with encrypted files elsewhere on the filesystem.

(Note that encrypted regular files and symlinks will not normally be
encountered outside an encrypted directory; however, it's possible via
hard links, so they still need to be handled.)

Tested by booting from an ext4 /boot partition on which I had run
'tune2fs -O encrypt'.  I also verified that the expected error messages
are printed when trying to access encrypted directories, files, and
symlinks from the GRUB command line.  Also ran 'sudo ./grub-fs-tester
ext4_encrypt'; note that this requires e2fsprogs v1.43+ and Linux v4.1+.

Signed-off-by: Eric Biggers <ebiggers@google.com>
6 years agosparc64: Don't use devspec to determine the OBP path
Eric Snowberg [Thu, 18 May 2017 23:10:22 +0000 (17:10 -0600)]
sparc64: Don't use devspec to determine the OBP path

Don't use devspec to determine the OBP path on SPARC hardware.  Within all
versions of Linux on SPARC, the devspec returns one of three values:
"none", "vnet-port", or "vdisk".  Unlike on PPC, none of these values
are useful in determining the OBP path.

Before this patch grub-ofpathname always returned the wrong value
for a virtual disk. For example:

% grub-ofpathname /dev/vdiskc2
vdisk/disk@2:b

After this patch it now returns the correct value:

% grub-ofpathname /dev/vdiskc2
/virtual-devices@100/channel-devices@200/disk@2:b

Orabug: 24459765

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64: Update the introduction of Xen boot commands in docs/grub.texi
Fu Wei [Sun, 14 May 2017 07:43:47 +0000 (15:43 +0800)]
arm64: Update the introduction of Xen boot commands in docs/grub.texi

delete: xen_linux, xen_initrd, xen_xsm
add: xen_module

This update bases on
    commit 0edd750e50698854068358ea53528100a9192902
    Author: Vladimir Serbinenko <phcoder@gmail.com>
    Date:   Fri Jan 22 10:18:47 2016 +0100

        xen_boot: Remove obsolete module type distinctions.

Also bases on the module loading mechanism of Xen code:
488c2a8 docs/arm64: clarify the documention for loading XSM support
67831c4 docs/arm64: update the documentation for loading XSM support
ca32012 xen/arm64: check XSM Magic from the second unknown module.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoutil/grub.d/20_linux_xen.in: Add xen_boot command support for aarch64
Fu Wei [Sun, 14 May 2017 07:43:46 +0000 (15:43 +0800)]
util/grub.d/20_linux_xen.in: Add xen_boot command support for aarch64

This patch adds the support of xen_boot command for aarch64:
    xen_hypervisor
    xen_module
These two commands are only for aarch64, since it has its own protocol and
commands to boot xen hypervisor and Dom0, but not multiboot.

For other architectures, they are still using multiboot and module
commands.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64: Add "--nounzip" option support in xen_module command
Fu Wei [Sun, 14 May 2017 07:43:45 +0000 (15:43 +0800)]
arm64: Add "--nounzip" option support in xen_module command

This patch adds "--nounzip" option support in order to
be compatible with the module command of multiboot on other architecture,
by this way we can simplify grub-mkconfig support code.

This patch also allow us to use zip compressed module(like Linux kernel
for Dom0).

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64/xen_boot: Fix Xen boot using GRUB2 on AARCH64
Julien Grall [Fri, 19 Feb 2016 16:28:52 +0000 (16:28 +0000)]
arm64/xen_boot: Fix Xen boot using GRUB2 on AARCH64

Xen is currently crashing because of malformed compatible property for
the boot module. This is because the property string is not
null-terminated as requested by the ePAR spec.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Tested-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agosparc64: Close cdboot ihandle
Eric Snowberg [Fri, 12 May 2017 01:42:23 +0000 (18:42 -0700)]
sparc64: Close cdboot ihandle

The ihandle is left open with a cd-core image.  This will cause a delay
booting grub from a virtual cdrom in a LDOM.  It will also cause problems
as Linux boots, since it expects the ihandle to be closed during init.

Orabug: 25911275

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoat_keyboard: Fix falco chromebook case.
Vladimir Serbinenko [Tue, 9 May 2017 12:27:52 +0000 (14:27 +0200)]
at_keyboard: Fix falco chromebook case.

EC is slow, so we need few delays for it to toggle the bits correctly.

Command to enable clock and keyboard were not sent.

6 years agocoreboot: Changed cbmemc to support updated console format from coreboot.
Julius Werner [Tue, 9 May 2017 07:03:02 +0000 (09:03 +0200)]
coreboot: Changed cbmemc to support updated console format from coreboot.

6 years agoMissing parts of previous commit
Vladimir Serbinenko [Tue, 9 May 2017 07:02:15 +0000 (09:02 +0200)]
Missing parts of previous commit