Commit Graph

221 Commits

Author SHA1 Message Date
Peter Oberparleiter
5768d55a08 zipl/boot: add secure boot trailer
This patch enhances the zipl stage3 loader image adding a trailer as
required for secure boot by future firmware versions.

Note: with the change in this patch the padding via objcopy command line
options is replaced by padding via linker script directives with the
same effect.

Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Marc Hartmayer
da9b96fb12 lib/zt_common.h: consolidate ROUNDUP macro
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Acked-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-10-22 20:27:16 +02:00
Benjamin Block
71461d80bf Makefile: use common Make definition for DRACUTDIR
The dracut installation directory is referenced from `chreipl-fcp-mpath`,
`zdev`, and `zipl`; in each with its own individual definition and
variable name. This makes it unnecessarily hard to change it when
installing from the top level directory of s390-tools and passing
variable overwrites via the command line.

Fix this by defining a common `DRACUTDIR` variable in the shared
`common.mak` file, and referencing this in each tool as base directory.
With this a user can simply pass `DRACUTDIR=/foo/bar/baz` on the
commandline and change the installation for all three tools.

Further, also derive common `DRACUTCONFDIR` and `DRACUTMODDIR` variables
from `DRACUTDIR` in `common.mak`, so that `zdev` and `zipl` don't use
different variable names for the same directory anymore, and all these
are defined together in a common place.

Semantically nothing changes for a default build/installation.

Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-08-16 18:28:21 +02:00
Steffen Eiden
6ff8202fa9 zipl: Add missing check for a nullpointer.
Fixes a bug that leads to a segmentation fault when no parmline is
provided.

Fixes: 11b401b5 ("zipl: move and make check for maximum command line length dynamic")
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-08-16 18:28:21 +02:00
Sven Schnelle
1bd73c68f9 zipl/boot: don't use lt to test value in tape0.S
This instruction is not present on older machines, therefore
use ltr.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Fixes: 1627c6a39f ("zipl: Support command lines longer than 896 bytes in bootloader")
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-07-21 15:57:17 +02:00
Alexander Egorenkov
a66f6bb075 zipl: Adapt man pages for NVMe stand-alone dump
From user perspective, there is no difference between SCSI stand-alone
dump and NVMe one.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
2b015183aa zipl: Implement NGDump
This commit finalizes the implementation of the new stand-alone dump -
Next Gen Dump (NGDump).

NGDump stand-alone dump is a universal stand-alone dump which works for both
SCSI and NVMe disks. But currently can be used only with NVMe disks
and SCSI stand-alone dump remains the default for SCSI disks.

Currently, this stand-alone dump can be used only on IBM z15 or newer
machine generations because it requires larger amount of HSA memory offered
by firmware only on IBM z15 machines. Whereas SCSI stand-alone dump is able
to work with HSA memory of 32M, the new stand-alone dump requires 512M HSA
memory at the moment.

NGDump stand-alone dump installation is initiated by passing a path to
a NVMe disk partition to zipl via the command-line -d, similar to SCSI
stand-alone dump. zipl will then:
- build a dumper initramfs with either dracut (Fedora/RHEL/SLES) or
  initramfs-tools (Ubuntu/Debian)
- format the given NVMe partition with ext4 file system
- create a bootmap file on the newly created file system using the built
  initramfs and the currently active kernel image
- install a boot loader on the disk the given dump partition belongs to

The operations described above are destructive for the given NVMe dump
partition and the boot record(s) of its disk.

After the installation step, users can configure the dumpconf to IPL
the dumper automatically on panic or trigger a dump manually via HMC
interface.

When activated, the dumper will create a dump ELF file named "dump.elf"
on the given NVMe dump partition by using the makedumpfile tool. The kdump
compressed file format is not supported yet due to zgetdump not being able
to read such a file format. Therefore, the dumper is restricted to write
the dump only in ELF format but only kernel pages which are in use.
This will usually make the dump smaller than the original size of
/proc/vmcore and the whole dump process faster as well.

Example configuration for dumpconf:

ON_PANIC=dump   # or dump_reipl
DUMP_TYPE=nvme
FID=0x00000001
NSID=0x00000001
BOOTPROG=0
BR_LBA=0

$ systemctl enable --now dumpconf

To install the dracut support on Fedora/RHEL/SUSE:

$ make -C zipl/dracut HAVE_DRACUT=1 install

To install the initramfs-tools support on Ubuntu/Debian:

$ make -C zipl/initramfs-tools HAVE_INITRAMFS=1 install

Example of NGDump console output on SLES during dump
----------------------------------------------------

         Starting NGDump...
[    8.932343] ngdump.sh[327]: NGDump started
[    8.934739] ngdump.sh[336]: Checking for memory holes                         : [  0.0 %] /
[    8.967536] ngdump.sh[336]: Checking for memory holes                         : [100.0 %] |
[    9.076976] ngdump.sh[336]: Excluding unnecessary pages                       : [100.0 %] \
[   11.721157] ngdump.sh[336]: Copying data                                      : [  0.0 %] -
[   12.317319] ngdump.sh[336]: Copying data                                      : [ 22.5 %] /           eta: 2s
[   13.273000] ngdump.sh[336]: Copying data                                      : [100.0 %] |           eta: 0s
[   13.273244] ngdump.sh[336]: The kernel version is not supported.
[   13.273263] ngdump.sh[336]: The makedumpfile operation may be incomplete.
[   13.273281] ngdump.sh[336]: The dumpfile is saved to /ngdump/dump.elf.
[   13.273299] ngdump.sh[336]: makedumpfile Completed.

Example of NGDump console output on Ubuntu during dump
-------------------------------------------------------

[    3.240078] zdump: The dump process started for a 64-bit operating system
Loading, please wait...
Starting version 245.4-4ubuntu3.17
Begin: Starting firmware auto-configuration ... done.
Begin: Loading essential drivers ... done.
Begin: Running /scripts/init-premount ...
Begin: NGDump ...
Checking for memory holes                         : [  0.0 %] /
Checking for memory holes                         : [100.0 %] |
Excluding unnecessary pages                       : [100.0 %] \
Copying data                                      : [  0.0 %] -
Copying data                                      : [ 40.7 %] /           eta: 1s
Copying data                                      : [100.0 %] |           eta: 0s
The kernel version is not supported.
The makedumpfile operation may be incomplete.
The dumpfile is saved to /ngdump/dump.elf.
makedumpfile Completed.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
b4142a9966 zipl: Implement zipl helper script for NGDump
The purpose of the new zipl helper script is to build a dumper initramfs
for NGDump stand-alone dump. zipl executes the helper script when
preparing a NVMe dump partition for stand-alone dump.

The zipl helper script expects a single parameter - a path to the dump
partition to store a dump on. The helper script terminates with 0 on
success and a positive value otherwise.

The zipl helper script performs the following steps:
- It builds an initramfs image suitable for dumping. To perform this step,
  the script employs the dracut tool on Fedora/RHEL/SLES and
  the initramfs-tools on Ubuntu/Debian.
- It outputs the path to the newly built initramfs image and the currently
  active kernel bzImage on the standard output.
- It prints the kernel command-line to be used by the dumper on
  the standard output.

On success, zipl expects the helper script to return at least three lines
containing:
- initrd=<path to an initramfs image>
- kernel=<path to a kernel bzImage>
- cmdline=<kernel command-line parameters>

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
c1d08e1380 zipl: Add initramfs-tools module for NGDump
The NGDump initramfs-tools module is required to build an initramfs image
to be used with NGDump stand-alone dump. NGDump stand-alone dump does not
use a pre-built initramfs image in contrast to SCSI stand-alone dump.
Instead, an initramfs image is built with initramfs-tools if NGDump
stand-alone dump is installed on a NVMe partition.

The NGDump initramfs-tools module ensures that all necessary tools are
present within the built initramfs and a dump of /proc/vmcore is initiated
to the chosen NVMe partition when the installed dumper is IPLed.

The NGDump intramfs-tools module installs a configuration file and
a dump script into dumper initramfs. This dump script starts at boot
shortly after the initialization of the dump target device. It reads
the aforementioned configuration file that contains the name of a dump
partition to store a dump on. The dump script reads the configuration file,
mounts then the dump target device, creates a copy of /proc/vmcore with
the makedumpfile tool on it, and then shuts down the system.

Ubuntu and Debian are the main Linux distributions targeted by this
initramfs-tools module.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
85c9a49e63 zipl: Add dracut module for NGDump
The NGDump dracut module is required to build an initramfs image to be used
with NGDump stand-alone dump. NGDump stand-alone dump does not
use a pre-built initramfs image in contrast to SCSI stand-alone dump.
Instead, an initramfs image is built with dracut if NGDump stand-alone dump
is installed on a NVMe partition.

The NGDump dracut module ensures that all necessary tools are present
within the built initramfs and a dump of /proc/vmcore is initiated
to the chosen NVMe partition when the installed dumper is IPLed.

The NGDump dracut module installs a new systemd service and a dump script
into dumper initramfs. The systemd init process starts the NGDump service
at boot shortly after the initialization of the dump target device.
The NGDump systemd service, in its turn, starts the dump script provided
by the new dracut module. The dump script mounts then the dump target
device, creates a copy of /proc/vmcore with the makedumpfile tool on it,
and then shuts down the system.

The NGDump dracut module can be used on any Linux distribution which
supports dracut. But the primary targets are:
- Fedora
- RHEL
- SLES

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
4939531fe5 zipl: Add bootmap directory parameter to bootmap_create_file()
This change adds a new parameter to the function bootmap_create_file()
that requires the caller to specify a path to the directory where
a bootmap file will be created. The primary motivation for this change is
to support NVMe stand-alone dump, in that case the job's bootmap directory
is not set.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
84abb27077 zipl: Extract SCSI dump partition check from bootmap_create_device()
The purpose of this change is to simplify the function
bootmap_create_device() and make it more readable. Furthermore,
the dump partition check can be reused for NVMe dump partitions later on.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
6826316350 zipl: Extract SCSI dump size estimation from bootmap_create_device()
The purpose of this change is to simplify the function
bootmap_create_device() and to make it more readable.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
b95a3c24b8 zipl: Extract SCSI superblock writing from bootmap_create_device()
The purpose of this change is to simplify the function
bootmap_create_device() and make it more readable.
Furthermore, make bootmap_create_device() more robust by checking the return
value of disk_write_block_aligned().

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
1f8496aa92 zipl: Extract SCSI dump partition handling from bootmap_create()
The purpose of this change is to simplify the function bootmap_create(),
make it more readable and prepare for new changes that will follow.
The original function bootmap_create() tried to handle two different cases
and, therefore, contained many conditional statements which had a negative
effect on readability.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
9aa59bfc4b zipl: Fix stage2 disk block memory leaks in bootmap_install_stages()
This commit fixes a bug that fails to release stage2 disk blocks in case
the installation of stage1b disk blocks has failed.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Suggested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
fa111404cb zipl: Extract stage2 loader handling from bootmap_create()
The purpose of this change is to simplify the function bootmap_create(),
make it more readable and prepare for new changes that will follow.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
5094354c39 zipl: Implement helper function disk_is_nvme()
The new function disk_is_nvme() is a convenience function that indicates
whether the given path to a device file represents a NVMe disk.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:05 +02:00
Alexander Egorenkov
844058bf4d zipl: Extend disk_get_info() to recognize NVMe disks
Until now, NVMe disks were handled by zipl as SCSI disks. To support
NVMe stand-alone dump, it became necessary to further differentiate between
both types of disks.

There are two cases that must be handled:
1. A non-device-mapper device is a NVMe disk if it is assigned to the blkext
   device driver.
2. A device-mapper disk is a NVMe disk if the ioctl NVME_IOCTL_ID succeeds.
   This case is necessary to properly recognize NVMe disks which are
   DM devices and, therefore, not directly handled by the blkext device
   driver.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Acked-by: Stefan Haberland <sth@linux.ibm.com>
Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
647e8b5c37 zipl/boot: move zipl magic string definitions to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
953af2cc67 zipl/boot: move SCSI MBR struct definition to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
ba7bf2f6d3 zipl/boot: move boot info struct definitions to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
446ace09ad zipl/boot: move SCSI superblock struct definitions to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Alexander Egorenkov
fed12a71cf zipl/boot: move boot component struct definitions to boot_defs.h for reuse
To reduce duplication of definitions and facilitate reuse between zipl
and zgetdump.

Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-20 13:14:04 +02:00
Frank Heimes
901f082f1a s390-tools: Fix typos that were detected by lintian as 'typo-in-manual-page'
The static analysis tool for Debian packages 'lintian', especially if called
like 'lintian -EvIL +pedantic', checks manual pages for correctness and typos.
This commit fixes typos that were identified by lintian and marked with
'typo-in-manual-page' while s390-tools version 2.20.0 was packaged.

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/134
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
Acked-by: Steffen Maier maier@linux.ibm.com [ziomon]
Acked-by: Ingo Franzki ifranzki@linux.ibm.com [zkey]
[hoeppner@linux.ibm.com: fix commit message]
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Eduard Shishkin
f51dc05f7f zipl/Makefile: create an empty environment file /etc/ziplenv
Create an empty environment file /etc/ziplenv at make install
time if that file doesn't exist

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Eduard Shishkin
b4e4cd6cd5 zipl/man: update zipl-editenv man page
Add definitions of sites, namespaces and sections.
Document the new options --site (-S) and --effective-site (-E)

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Eduard Shishkin
e97c85bb80 zipl-editenv: added zIPL multienvironment support
. Support multiple namespaces in the installed environment block;
. Add option --site (-S) to specify a particular namespace
  when operating on the installed environment block;
. Add option --effective-site (-E) to specify a particular
  namespace. When using in a combination with the option -l
  (--list), it displays zIPL environment that would take place if
  the specified namespace was activated at boot time;
. Modify set/unset/reset/list operations over the installed
  environment block in the case when the option --site is specified

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Eduard Shishkin
c6443cf977 zipl/boot: added zIPL multienvironment support
. Parse LOADPARM specified by user to find out site-ID;
. Support multiple namespaces in the environment block. Use hash
  function on "extended" strings (i.e. strings with logical
  prefixes) for the key-value store implementation;
. Added logic to activate a particular namespace by site-ID passed
  by user via LOADPARM;
. Modify the logic of evaluation of zIPL environment variables in
  the kernel command line. Use the activated namespace for the
  evaluation

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Eduard Shishkin
6a439e6771 zipl/src: added zIPL multienvironment support
Support multiple namespaces in environment block. Use hash
function on "extended" strings for key-value store.
Support multiple sections in environment file.
Modify the import environment precedure to be "section-aware"

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
2134aff491 zipl/boot: kdump: remove static struct
Makes the code easier to read since it can have less side effects.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
b41ac66f36 zipl: consolidate boot and dump type definitions
Consolidate type definitions in order to avoid duplicated code, getting
better compiler support, and to avoid confusing namings for the same
thing - e.g. `blk_end` vs. `blockcnt` field name used in the old `struct
fba_dump_param` definitions. It also allows us to get rid of two
`uint64_t` casts.

While at it, fix the documentation of `struct eckd_blockptr`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
9aa368af54 zipl/boot: eckd2/fba: remove two superfluous casts
Remove two superfluous casts.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
2e6cf81c2a zipl/boot: stage3.lds.S: put notes section explicitly at the end
...otherwise `.note.gnu.build-id` will be put at 0x0 (location for s390x
lowcore) if the linker option `--build-id` is used (which is the default
if gcc is used for linking).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
ae27066c15 zipl/boot: add struct tpi_info to the lowcore struct
Use the `tpi_info` struct definition, similar to the Linux kernel, in
the lowcore struct. This change allows us to use simple assignments
instead of using casts. Additionally, there is the advantage that the
lowcore definition from the s390-tools now looks more similar to the
lowcore definition used by the Linux kernel.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
5ac171d224 genprotimg/zipl: boot: Makefile: small refactoring
Move the common `-nostdlib` and `$(NO_PIE_LINKFLAGS) linker options to
the actual linker call. This makes the code easier to maintain.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
67dbf094b2 genprotimg/zipl: boot: Makefile: do not link against shared libraries
It's pretty obvious that we don't want to link against shared libraries
therefore use `-static` for linking.

`ld` call before this change:

  /usr/bin/ld -v -plugin /usr/lib/gcc/s390x-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/s390x-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccLfGZu4.res --build-id --eh-frame-hdr -m elf64_s390 --hash-style=gnu --as-needed -dynamic-linker /lib/ld64.so.1 -z relro -o stage3.exec -L/usr/lib/gcc/s390x-linux-gnu/9 -L/usr/lib/gcc/s390x-linux-gnu/9/../../../../s390x-linux-gnu/lib/../lib -L/usr/lib/gcc/s390x-linux-gnu/9/../../../s390x-linux-gnu -L/usr/lib/gcc/s390x-linux-gnu/9/../../../../lib -L/lib/s390x-linux-gnu -L/lib/../lib -L/usr/lib/s390x-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/s390x-linux-gnu/9/../../../../s390x-linux-gnu/lib -L/usr/lib/gcc/s390x-linux-gnu/9/../../.. -T stage3.lds stage3.o head.o kdump3.o libc.o ebcdic.o ebcdic_conv.o sclp.o sclp_stage3.o kdump.o entry.o

`ld` call after this change:

  /usr/bin/ld -v -plugin /usr/lib/gcc/s390x-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/s390x-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccw0ELAp.res --build-id -m elf64_s390 --hash-style=gnu --as-needed -static -z relro -o stage3.exec -L/usr/lib/gcc/s390x-linux-gnu/9 -L/usr/lib/gcc/s390x-linux-gnu/9/../../../../s390x-linux-gnu/lib/../lib -L/usr/lib/gcc/s390x-linux-gnu/9/../../../s390x-linux-gnu -L/usr/lib/gcc/s390x-linux-gnu/9/../../../../lib -L/lib/s390x-linux-gnu -L/lib/../lib -L/usr/lib/s390x-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/s390x-linux-gnu/9/../../../../s390x-linux-gnu/lib -L/usr/lib/gcc/s390x-linux-gnu/9/../../.. -T stage3.lds stage3.o head.o kdump3.o libc.o ebcdic.o ebcdic_conv.o sclp.o sclp_stage3.o kdump.o entry.o

Fixes: b627b8d8e1 ("Initial s390-tools-2.0.0 import")
Fixes: 3356d6f4fa ("genprotimg: boot: initial bootloader support")
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-06-03 18:40:36 +02:00
Marc Hartmayer
8231ec5f38 zipl/boot/Makefile: fix cleanup of linker script dependency files
By default, the Bash file globbing pattern '*' doesn't list files prefixed by a
dot (see https://linux.die.net/man/1/bash). Let's fix this by using the pattern
`.*` instead. While at it, add `--` option to remove possible problems with
leading dashes in filenames.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-05-10 13:33:24 +02:00
Eduard Shishkin
a0dba6bfdb zipl/src: Implement sorting bls entries by versions
This patch implements an additional method of sorting bls entries
by version field and uses it as default one. If sorting by version
fails, then it falls back to the most robust method of sorting by
file names

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-05-10 13:33:24 +02:00
Eduard Shishkin
ebc3384b9f zipl/src: make blsdir variable global instead of local
It is used by the next patch.
Specifically, ->filter() and ->sort() callbacks of the scandir(3)
accept only short names of directory entries to be filtered/sorted,
while we need to know absolute names to perform filtering/sorting.

Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-05-10 13:33:24 +02:00
Javier Martinez Canillas
a28b396d9e zipl: make IPL sections defined with BLS to inherit a target field
The target field is required for IPL sections, but the ones populated from
BLS snippets did not have this field. This was only working when using BLS
snippets because IPL sections inherit the target field with "defaultauto".

But that's not the case when using a menu, for example the following zipl
configuration will fail if it's used along with BLS defined IPL sections:
fail when running the zipl tool:

  [defaultboot]
  defaultmenu = menu1

  :menu1
  target = /boot
  1 = linux
  2 = test
  default = 1
  prompt = 1
  timeout = 0

Because "linux" and "test" will be defined using BLS snippets and these
don't have an option to define target fields. Let's make these to always
inherit a target field, either from the [defaultboot] section or a menu
section if there's a defaultmenu defined.

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/111
Closes: https://github.com/ibm-s390-linux/s390-tools/pull/113
[hoeppner@linux.ibm.com: Fixed a couple of style issues]
Reported-by: Renaud Métrich <rmetrich@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Tested-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-03-18 14:41:43 +01:00
Jan Höppner
71fe58111c s390-tools: Clean up NO_PIE_* flags
Remove NO_PIE_LINKFLAGS and follow the naming convention by using
LDFLAGS for linker flags. Replace all occurrences accordingly.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-03-09 12:11:49 +01:00
Jan Höppner
5e46632767 zipl: Use the compiler for linking instead of ld
Instead of directly calling ld, it is recommended to call the compiler
to do the linking. Do that and adapt the linker flags accordingly.

This also fixes build issues with newer binutils as -no-pie has never
been a valid option for ld itself.

See:
https://sourceware.org/bugzilla/show_bug.cgi?id=27050
https://bugs.launchpad.net/ubuntu/+source/s390-tools/+bug/1907789

LD has no user anymore and is removed.

Closes: https://github.com/ibm-s390-tools/s390-tools/pull/106
Reported-by: Lukas Märdian <lukas.maerdian@canonical.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-03-09 12:11:49 +01:00
Philipp Kern
ee2c6d4160 zipl: Allow optional entries that are left out when files are missing.
Debian carried a patch forever that allowed zipl to run even if not all
menu items had files attached. If a required file is missing for an
entry (e.g. vmlinuz.old or initrd.img.old) and it is marked as
"optional" in the config, the section will be skipped. This allows
zipl to install after bootstrapping, as booting on s390 still relies
on the kernel/initrd symlinks in the root directory.

Closes: https://github.com/ibm-s390-linux/s390-tools/pull/2
Signed-off-by: Philipp Kern <pkern@debian.org>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
[sth@linux.ibm.com: adapted patches to latest changes, merged patches]
Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-02-21 12:54:34 +01:00
Marc Hartmayer
e1f174ae22 zipl/libc.h: declare start as __noreturn function
Declare `start` as __noreturn function since the function doesn't
return. Use the gcc/clang built-in function `__builtin_unreachable` to
make clear that `lpsw` and `diag308(DIAG390_IPL, NULL)` doesn't
return (see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html and
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-unreachable).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-02-02 11:54:30 +01:00
Marc Hartmayer
983233730c zipl: add missing static declarations
Fix Sparse findings like:

 warning: symbol 'hash_table_find' was not declared. Should it be static?

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-02-02 11:54:30 +01:00
Eduard Shishkin
e2843232d5 zipl/src: make gcc 11.2 happy
Add a prophylactic check that @filename is not NULL before its
dereference.

This addresses the following warning (which is a false positive,
since stat(2) is never called with NULL file name):

job.c:514:13: warning: argument 1 null where non-null expected
[-Wnonnull]
514 | if (stat(filename, &stats)) {
| ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/features.h:488,
from /usr/include/errno.h:25,
from job.c:13:
job.c: In function 'check_job_ipl_data':
/usr/include/sys/stat.h:227:12: note: in a call to function
'stat' declared 'nonnull'
227 | extern int __REDIRECT_NTH (stat, (const char *__restrict __file,

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/127
Reported-by: Mario Held <mario.held@de.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-01-20 09:35:02 +01:00
Sven Schnelle
11b401b599 zipl: move and make check for maximum command line length dynamic
The maximum command line length is now dependent on the kernel image
that is loaded. Therefore move the check to check_common_ipl_data().
This function now reads the new kernel image, and check whether the
command line length is in the allowed range.

The command line size limit in zipl is now set to 64k, which is hopefully
enough.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-01-20 09:35:02 +01:00
Sven Schnelle
69c5ee2e52 zipl: no need to check for NULL when calling free()
free() accepts NULL pointers, so no need for an extra check.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-01-20 09:35:02 +01:00
Sven Schnelle
3ee625d74f zipl: add check_common_ipl_data()
There are two places where we check whether the initrd and kernel image
is readably. Add one helper function that checks this. This is also a
preparation for the extended command line handling, so that we have to
add that code in only one location.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-01-20 09:35:02 +01:00