- rebased to 2.5.0

This commit is contained in:
Dan Horák 2018-06-11 13:24:22 +02:00
parent 6aab78b451
commit dbc645a2c4
7 changed files with 10 additions and 826 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ src_vipa-2.0.4.tar.gz
/s390-tools-2.2.0.tar.gz
/s390-tools-2.3.0.tar.gz
/s390-tools-2.4.0.tar.gz
/s390-tools-2.5.0.tar.gz

View File

@ -1,19 +0,0 @@
commit d87a3499ac4bb3f834982506c5b00d6470e1f015
Author: Dan Horák <dan@danny.cz>
Date: Fri Apr 13 10:51:00 2018 +0200
compute the bootloader stage size to workaround PIE
diff --git a/zipl/src/boot.c b/zipl/src/boot.c
index 9daf47b..279d246 100644
--- a/zipl/src/boot.c
+++ b/zipl/src/boot.c
@@ -21,7 +21,7 @@
#include "error.h"
#include "misc.h"
-#define DATA_SIZE(x) ((size_t) (&_binary_##x##_bin_size))
+#define DATA_SIZE(x) ((size_t) (&_binary_##x##_bin_end - &_binary_##x##_bin_start))
#define DATA_ADDR(x) (&_binary_##x##_bin_start)
#define STAGE2_MAX_SIZE 0x3000

View File

@ -1,300 +0,0 @@
From 24369c7677048518858dfbc6d5e609f64a42eff6 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Wed, 2 May 2018 12:27:05 +0200
Subject: [PATCH] scripts: Add script to switch zipl config to a
BootLoaderSpec setup
Add a zipl-switch-to-blscfg script that can be used to switch the zipl
configuration in a system to use the BootLoaderSpec (BLS) config files
to define the IPL sections instead of having them defined in zipl.conf.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
scripts/Makefile | 4 +-
scripts/zipl-switch-to-blscfg | 207 ++++++++++++++++++++++++++++++++
scripts/zipl-switch-to-blscfg.1 | 45 +++++++
3 files changed, 254 insertions(+), 2 deletions(-)
create mode 100755 scripts/zipl-switch-to-blscfg
create mode 100644 scripts/zipl-switch-to-blscfg.1
diff --git a/scripts/Makefile b/scripts/Makefile
index dc5b0f0dbe7..1a33e319693 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -1,7 +1,7 @@
include ../common.mak
-SCRIPTS = dbginfo.sh zfcpdbf scsi_logging_level
-MAN_PAGES = dbginfo.sh.1 zfcpdbf.1
+SCRIPTS = dbginfo.sh zfcpdbf zipl-switch-to-blscfg scsi_logging_level
+MAN_PAGES = dbginfo.sh.1 zfcpdbf.1 zipl-switch-to-blscfg.1
all:
diff --git a/scripts/zipl-switch-to-blscfg b/scripts/zipl-switch-to-blscfg
new file mode 100755
index 00000000000..871935c783f
--- /dev/null
+++ b/scripts/zipl-switch-to-blscfg
@@ -0,0 +1,207 @@
+#!/bin/bash
+#
+# zipl-switch-to-blscfg - Switch zipl to use BootLoaderSpec configuration
+#
+# Copyright 2018 Red Hat, Inc.
+#
+# s390-tools is free software; you can redistribute it and/or modify
+# it under the terms of the MIT license. See LICENSE for details.
+#
+
+readonly SCRIPTNAME="${0##*/}"
+
+declare -A zipl_to_bls
+zipl_to_bls["image"]="linux"
+zipl_to_bls["ramdisk"]="initrd"
+zipl_to_bls["parameters"]="options"
+
+print_error() {
+ echo "$1" >&2
+ exit 1
+}
+
+function on_exit() {
+ if ! rm -rf $TMP; then
+ echo "Delete temporary files failed!" >&2
+ exit 1
+ fi
+}
+
+if ! TMP="$(mktemp -d)"; then
+ print_error "Creating a temporary dir for config files failed!"
+fi
+
+trap 'on_exit' EXIT
+
+print_version() {
+ cat <<EOF
+${SCRIPTNAME}: version %S390_TOOLS_VERSION%
+Copyright Red Hat, Inc. 2018
+EOF
+}
+
+print_usage()
+{
+ print_version
+
+ cat <<EOF
+
+Usage: ${SCRIPTNAME} [OPTIONS]
+
+Switches the zipl boot-loader configuration to use BootLoaderSpec files.
+
+Options:
+
+ -h, --help print this help and exit
+ -v, --version print version information and exit
+ --backup-suffix=SUFFIX suffix used for backup files, defaults to .bak
+ --bls-directory=DIR path to generate BLS files, defaults to /boot/loader/entries
+ --config-file=FILE path to zipl configuration file, defaults to /etc/zipl.conf
+ --ignore-default ignore the default option from the zipl configuration file
+ --use-version-name use the section kernel version as the BLS file name
+
+EOF
+}
+
+OPTS="$(getopt -o hv --long help,version,backup-suffix:,bls-directory:,config-file:,\
+ignore-default,use-version-name -n \'$SCRIPTNAME\' -- "$@")"
+eval set -- "$OPTS"
+
+BACKUP_SUFFIX=.bak
+BLS_DIR="/boot/loader/entries"
+CMDLINE_LINUX_DEBUG=" systemd.log_level=debug systemd.log_target=kmsg"
+LINUX_DEBUG_VERSION_POSTFIX="_with_debugging"
+LINUX_DEBUG_TITLE_POSTFIX=" with debugging"
+CONFIG="/etc/zipl.conf"
+
+while [ ${#} -gt 0 ]; do
+ case "$1" in
+ --help|-h)
+ print_usage
+ exit 0
+ ;;
+ --version|-v)
+ print_version
+ exit 0
+ ;;
+ --backup-suffix)
+ BACKUP_SUFFIX=${2}
+ shift
+ ;;
+ --bls-directory)
+ BLS_DIR=${2}
+ shift
+ ;;
+ --config-file)
+ CONFIG=${2}
+ shift
+ ;;
+ --ignore-default)
+ ignore_default=true
+ ;;
+ --use-version-name)
+ version_name=true
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ echo >&2
+ echo "${SCRIPTNAME}: invalid option \"${1}\"" >&2
+ echo "Try '${SCRIPTNAME} --help' for more information" >&2
+ echo >&2
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+TMP_CONFIG="${TMP}/${CONFIG##*/}"
+
+[[ -d "$BLS_DIR" ]] || mkdir -m 0700 -p "$BLS_DIR"
+
+if [ -f /etc/machine-id ]; then
+ read MACHINE_ID < /etc/machine-id
+ MACHINE_ID=${MACHINE_ID}-
+fi
+
+count=0
+OUTPUT=""
+TARGET=""
+while IFS='= ' read key val; do
+ # for BLS the default kernel is always the latest one
+ if [[ $key == \#* ]] || [[ $key == "default" && $ignore_default == true ]]; then
+ continue
+ fi
+
+ # remove spaces
+ key="$(echo $key | sed -e 's/^[ \t"]*//;s/[ \t"]*$//')"
+
+ if [[ $key = \[*] ]]; then
+ if [[ $key == "[defaultboot]" ]]; then
+ OUTPUT=${TMP_CONFIG}
+ echo $key >> ${OUTPUT}
+ else
+ key="${key%\]}"
+ key="${key#\[}"
+ OUTPUT=${BLS_DIR}/${MACHINE_ID}${key}.conf
+ if [ -f "${OUTPUT}" ]; then
+ print_error "BLS file ${OUTPUT} already exists"
+ fi
+ fi
+ elif [[ $val ]]; then
+ val="$(echo $val | sed -e 's/^[ \t"]*//;s/[ \t"]*$//')"
+ if [[ $key == "target" ]]; then
+ if [ -z ${TARGET} ]; then
+ echo $key=$val >> ${TMP_CONFIG}
+ TARGET=$val
+ else if [ "${TARGET}" != "${val}" ]; then
+ print_error "BLS is only supported if all sections have the same target"
+ fi
+ fi
+ else
+ if [ -n "${zipl_to_bls[$key]}" ]; then
+ if [[ $key = "image" ]]; then
+ if [[ $val = *"vmlinuz-"* ]]; then
+ version="${val##*/vmlinuz-}"
+ else
+ version="${val##*/}"
+ fi
+ echo "version $version" >> ${OUTPUT}
+ if [[ $version = *"rescue"* ]]; then
+ FILENAME=${BLS_DIR}/${MACHINE_ID}0-rescue.conf
+ else
+ FILENAME=${BLS_DIR}/${MACHINE_ID}${version}.conf
+ fi
+
+ if [[ ${OUTPUT} != ${FILENAME} && $version_name == true ]]; then
+ mv ${OUTPUT} ${FILENAME}
+ if [ ! $? -eq 0 ]; then
+ print_error "Creating BLS file ${FILENAME} failed"
+ fi
+ OUTPUT=${FILENAME}
+ fi
+ fi
+
+ echo "${zipl_to_bls[$key]} ${val}" >> ${OUTPUT}
+ else
+ echo $key=$val >> ${TMP_CONFIG}
+ fi
+ fi
+ fi
+done < "${CONFIG}"
+
+if [ -f "${CONFIG}${BACKUP_SUFFIX}" ]; then
+ print_error "Backup file ${CONFIG}${BACKUP_SUFFIX} already exists"
+fi
+
+cp -af "${CONFIG}" "${CONFIG}${BACKUP_SUFFIX}"
+mv "${TMP_CONFIG}" "${CONFIG}"
+
+zipl > /dev/null
+if [ ! $? -eq 0 ]; then
+ mv "${CONFIG}${BACKUP_SUFFIX}" "${CONFIG}"
+fi
+
+exit 0
diff --git a/scripts/zipl-switch-to-blscfg.1 b/scripts/zipl-switch-to-blscfg.1
new file mode 100644
index 00000000000..6bd14d00d14
--- /dev/null
+++ b/scripts/zipl-switch-to-blscfg.1
@@ -0,0 +1,45 @@
+.TH ZIPL-SWITCH-TO-BLSCFG 1 "April 2018" "s390-tools"
+
+.SH NAME
+zipl-switch-to-blscfg \- Switch zipl to use BootLoaderSpec configuration
+
+.SH SYNOPSIS
+.br
+\fBzipl-switch-to-blscfg\fP [OPTIONS]
+.br
+\fBzipl-switch-to-blscfg\fP {\-h|\-v}
+
+.SH DESCRIPTION
+This script switches the zipl boot-loader configuration to use BootLoaderSpec files
+to define IPL sections. For each Linux kernel defined in the zipl.conf config file,
+a BLS fragment is generated in the BLS directory specified. Also, the zipl.conf is
+modified it only contains global configurations, all IPL sections comes from BLS.
+
+.SH OPTIONS
+.TP
+\fB\-h\fP, \fB\-\-help\fP
+Print this help and exit
+
+.TP
+\fB\-v\fP, \fB\-\-version\fP
+Print version information and exit
+
+.TP
+\fB\-\-backup-suffix <SUFFIX>\fP
+The suffix used for backup files, defaults to .bak.
+
+.TP
+\fB\-\-bls-directory <DIRECTORY>\fP
+The DIRECTORY where the BLS fragments will be generated. The directory is created if it doesn't exists, by default /boot/loader/entries is used.
+
+.TP
+\fB\-\-config-file <FILE>\fP
+The FILE used for zipl configuration file, defaults to /etc/zipl.conf.
+
+.TP
+\fB\-\-ignore-default\fP
+Ignore the default option from the zipl configuration file
+
+.TP
+\fB\-\-use-version-name\fP
+Use the section kernel version as the BLS file name
--
2.17.0

View File

@ -1,411 +0,0 @@
From 4d3fb60159566dfb011a855d899425e972ed951a Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Wed, 2 May 2018 12:26:58 +0200
Subject: [PATCH] zipl: Add BootLoaderSpec support
The BootLoaderSpec (BLS) defines a file format for boot configurations,
so bootloaders can parse these files and create their boot menu entries
by using the information provided by them [0].
This allow to configure the boot items as drop-in files in a directory
instead of having to parse and modify a bootloader configuration file.
If the /boot/loader/entries exists and there are BLS files there, then
these are parsed and configuration sections are added without the need
to have these in a zipl.conf file.
A different BLS directory can be specified from the command line using
the --blsdir option.
[0]: https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
zipl/include/scan.h | 1 +
zipl/include/zipl.h | 1 +
zipl/man/zipl.8 | 12 ++-
zipl/man/zipl.conf.5 | 21 +++++
zipl/src/job.c | 24 +++++-
zipl/src/scan.c | 179 +++++++++++++++++++++++++++++++++++++++++++
zipl/src/zipl.c | 1 +
7 files changed, 237 insertions(+), 2 deletions(-)
diff --git a/zipl/include/scan.h b/zipl/include/scan.h
index f2c7b1b094a..0fe415c9b2d 100644
--- a/zipl/include/scan.h
+++ b/zipl/include/scan.h
@@ -119,6 +119,7 @@ extern enum scan_key_state scan_key_table[SCAN_SECTION_NUM][SCAN_KEYWORD_NUM];
int scan_file(const char* filename, struct scan_token** array);
+int scan_bls(const char* blsdir, struct scan_token** token, int scan_size);
void scan_free(struct scan_token* array);
char* scan_keyword_name(enum scan_keyword_id id);
int scan_check_defaultboot(struct scan_token* scan);
diff --git a/zipl/include/zipl.h b/zipl/include/zipl.h
index 8dc6b6db1a5..2aed54fb2b5 100644
--- a/zipl/include/zipl.h
+++ b/zipl/include/zipl.h
@@ -43,6 +43,7 @@
#define ZIPL_CONF_VAR "ZIPLCONF"
#define ZIPL_DEFAULT_CONF "/etc/zipl.conf"
+#define ZIPL_DEFAULT_BLSDIR "/boot/loader/entries"
#define MENU_DEFAULT_PROMPT 0
#define MENU_DEFAULT_TIMEOUT 0
diff --git a/zipl/man/zipl.8 b/zipl/man/zipl.8
index 873d680465a..989197590e4 100644
--- a/zipl/man/zipl.8
+++ b/zipl/man/zipl.8
@@ -25,7 +25,7 @@ loading a data file to initialize named saved segments (NSS)
Each of these operations is characterized by a boot configuration, i.e. a
set of required parameters.
.B zipl
-supports two ways of specifying a boot configuration:
+supports three ways of specifying a boot configuration:
.IP " -"
.B command line:
all parameters are provided through the command line switches described below.
@@ -37,6 +37,11 @@ parameters are provided by sections defined in a configuration file (see
Using a configuration file, you can either specify a single boot configuration
or a menu, i.e. a list of configurations from which users can choose at boot
time.
+.IP " -"
+.B BLS config files:
+boot configurations are specified using BootLoaderSpec (BLS) configuration files. The
+.BR zipl.conf (5)
+configuration file is still used to specify parameters or aditional boot configurations.
.PP
To use a single boot configuration section, provide its name as parameter to
@@ -117,6 +122,11 @@ Print version information, then exit.
Use the specified <CONFIG FILE>. If none is supplied, the environment
variable ZIPLCONF is evaluated if set, otherwise /etc/zipl.conf is used.
+.TP
+.BR "\-b <BLS DIRECTORY>" " or " "\-\-blsdir=<BLS DIRECTORY>"
+Use the specified <BLS DIRECTORY> to parse BootLoaderSpec config files.
+If none is supplied, the /boot/loader/entries directory is used.
+
.TP
.BR "\-t <TARGET DIRECTORY>" " or " "\-\-target=<TARGET DIRECTORY>"
Use the specified <TARGET DIRECTORY>.
diff --git a/zipl/man/zipl.conf.5 b/zipl/man/zipl.conf.5
index 8c454cd01e6..d4877d884fc 100644
--- a/zipl/man/zipl.conf.5
+++ b/zipl/man/zipl.conf.5
@@ -117,6 +117,27 @@ timeout = 0
.br
.PP
+.B BootLoaderSpec configuration files
+
+Another way to specify IPL sections is to use BLS config files. These are
+configuration files located by default at /boot/loader/entries, but another
+location can be specified using the '\-\-blsdir' option of zipl.
+
+.IP
+# An example for a BLS configuration file
+.br
+
+version 4.15.9
+.br
+linux /vmlinuz-4.15.9
+.br
+initrd /initramfs-4.15.9
+.br
+options root=/dev/dasda1 console=ttyS0
+.PP
+
+The location of the linux and initrd has to be specified relative to the boot partition. The BLS config files are only used to specify the IPL sections, a zipl.conf configuration files is still needed for global parameters.
+
.B Boot menu
The
diff --git a/zipl/src/job.c b/zipl/src/job.c
index 9d5f00b6bdc..e6d298188d5 100644
--- a/zipl/src/job.c
+++ b/zipl/src/job.c
@@ -27,6 +27,7 @@
/* Command line options */
static struct option options[] = {
{ "config", required_argument, NULL, 'c'},
+ { "blsdir", required_argument, NULL, 'b'},
{ "target", required_argument, NULL, 't'},
{ "targetbase", required_argument, NULL, 0xaa},
{ "targettype", required_argument, NULL, 0xab},
@@ -55,11 +56,12 @@ static struct option options[] = {
};
/* Command line option abbreviations */
-static const char option_string[] = "-c:t:i:r:p:P:d:D:M:s:m:hHnVvaT:fk:";
+static const char option_string[] = "-c:b:t:i:r:p:P:d:D:M:s:m:hHnVvaT:fk:";
struct command_line {
char* data[SCAN_KEYWORD_NUM];
char* config;
+ char *blsdir;
char* menu;
char* section;
int help;
@@ -197,6 +199,14 @@ get_command_line(int argc, char* argv[], struct command_line* line)
} else
cmdline.config = optarg;
break;
+ case 'b':
+ if (cmdline.blsdir != NULL) {
+ error_reason("Option 'blsdir' specified more "
+ "than once");
+ rc = -1;
+ } else
+ cmdline.blsdir = optarg;
+ break;
case 'm':
if (cmdline.menu != NULL) {
error_reason("Option 'menu' specified more "
@@ -1731,6 +1741,7 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job)
struct scan_token* scan;
struct scan_token* new_scan;
char* filename;
+ char *blsdir;
char* source;
int rc, scan_size;
@@ -1755,6 +1766,17 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job)
error_text("Config file '%s'", filename);
return scan_size;
}
+ /* Check if a BLS directory was provided on command line */
+ if (cmdline->blsdir != NULL) {
+ blsdir = cmdline->blsdir;
+ } else {
+ blsdir = ZIPL_DEFAULT_BLSDIR;
+ }
+ rc = scan_bls(blsdir, &scan, scan_size);
+ if (rc) {
+ error_text("BLS parsing '%s'", blsdir);
+ return rc;
+ }
if ((cmdline->menu == NULL) && (cmdline->section == NULL)) {
rc = scan_check_defaultboot(scan);
if (rc < 0) {
diff --git a/zipl/src/scan.c b/zipl/src/scan.c
index adb288e0626..fe72e9ab13d 100644
--- a/zipl/src/scan.c
+++ b/zipl/src/scan.c
@@ -16,13 +16,21 @@
#define __USE_ISOC99
#endif
+/* Need GNU function strverscmp() in dirent.h */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <ctype.h>
+#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+
#include "lib/util_base.h"
#include "boot.h"
@@ -633,6 +641,177 @@ scan_file(const char* filename, struct scan_token** token)
}
+static int
+bls_filter(const struct dirent *ent)
+{
+ int offset = strlen(ent->d_name) - strlen(".conf");
+
+ if (offset < 0)
+ return 0;
+
+ return strncmp(ent->d_name + offset, ".conf", strlen(".conf")) == 0;
+}
+
+
+static int
+bls_sort(const struct dirent **ent_a, const struct dirent **ent_b)
+{
+ return strverscmp((*ent_a)->d_name, (*ent_b)->d_name);
+}
+
+
+static int
+scan_append_section_heading(struct scan_token* scan, int* index, char* name);
+static int
+scan_append_keyword_assignment(struct scan_token* scan, int* index,
+ enum scan_keyword_id id, char* value);
+
+
+static int
+scan_bls_field(struct misc_file_buffer *file, struct scan_token* scan,
+ int* index)
+{
+ int current;
+ int key_start, key_end;
+ int val_start, val_end;
+ char *val;
+
+ for (key_start = file->pos; ; file->pos++) {
+ current = misc_get_char(file, 0);
+
+ if (isblank(current)) {
+ key_end = file->pos;
+ skip_blanks(file);
+ val_start = file->pos;
+ break;
+ }
+
+ if (!isalnum(current) && current != '_' && current != '-')
+ return -1;
+ }
+
+ for (; ; file->pos++) {
+ current = misc_get_char(file, 0);
+
+ if (current == '\n' || current == EOF)
+ break;
+ }
+
+ val_end = file->pos;
+ file->buffer[key_end] = '\0';
+ file->buffer[val_end] = '\0';
+
+ if (strncmp("version", &file->buffer[key_start], key_end - key_start) == 0) {
+ scan_append_section_heading(scan, index, &file->buffer[val_start]);
+ }
+
+ if (strncmp("linux", &file->buffer[key_start], key_end - key_start) == 0) {
+ misc_asprintf(&val, "%s", &file->buffer[val_start]);
+ scan_append_keyword_assignment(scan, index, scan_keyword_image, val);
+ free(val);
+ }
+
+ if (strncmp("options", &file->buffer[key_start], key_end - key_start) == 0) {
+ scan_append_keyword_assignment(scan, index, scan_keyword_parameters,
+ &file->buffer[val_start]);
+ }
+
+ if (strncmp("initrd", &file->buffer[key_start], key_end - key_start) == 0) {
+ misc_asprintf(&val, "%s", &file->buffer[val_start]);
+ scan_append_keyword_assignment(scan, index, scan_keyword_ramdisk, val);
+ free(val);
+ }
+
+ return 0;
+}
+
+
+int
+scan_bls(const char* blsdir, struct scan_token** token, int scan_size)
+{
+ int count = 0;
+ int size, remaining = 0, n, current, rc = -1;
+ struct scan_token* buffer;
+ struct scan_token* array = *token;
+ struct dirent** bls_entries;
+ struct misc_file_buffer file;
+ struct stat sb;
+ char filename[PATH_MAX];
+
+ if (!(stat(blsdir, &sb) == 0 && S_ISDIR(sb.st_mode)))
+ return 0;
+
+ n = scandir(blsdir, &bls_entries, bls_filter, bls_sort);
+ if (n <= 0)
+ return n;
+
+ while (array[count].id != 0)
+ count++;
+
+ remaining = scan_size - count;
+
+ if (remaining < n) {
+ size = scan_size - remaining + n;
+ buffer = (struct scan_token *)misc_malloc(size * sizeof(struct scan_token));
+ if (!buffer)
+ goto err;
+ memset(buffer, 0, size * sizeof(struct scan_token));
+ memcpy(buffer, array, count * sizeof(struct scan_token));
+ } else {
+ buffer = array;
+ }
+
+ while (n--) {
+ sprintf(filename, "%s/%s", blsdir, bls_entries[n]->d_name);
+ printf("Using BLS config file '%s'\n", filename);
+
+ rc = misc_get_file_buffer(filename, &file);
+ if (rc)
+ goto err;
+
+ while ((size_t)file.pos < file.length) {
+ current = misc_get_char(&file, 0);
+ switch (current) {
+ case '#':
+ file.pos++;
+ skip_line(&file);
+ break;
+ case EOF:
+ break;
+ case '\t':
+ case '\0':
+ case ' ':
+ file.pos++;
+ break;
+ default:
+ rc = scan_bls_field(&file, buffer, &count);
+ if (rc) {
+ error_reason("Incorrect BLS field in "
+ "config file %s\n", filename);
+ goto err;
+ }
+ break;
+ }
+ }
+
+ misc_free_file_buffer(&file);
+ free(bls_entries[n]);
+ }
+
+ *token = buffer;
+ rc = 0;
+err:
+ if (n > 0) {
+ do {
+ free(bls_entries[n]);
+ } while (n-- > 0);
+ }
+
+ free(bls_entries);
+ return rc;
+}
+
+
/* Search scanned tokens SCAN for a section/menu heading (according to
* TYPE) of the given NAME, beginning at token OFFSET. Return the index of
* the section/menu heading on success, a negative value on error. */
diff --git a/zipl/src/zipl.c b/zipl/src/zipl.c
index 1eaa82b9f43..65eefdb2d99 100644
--- a/zipl/src/zipl.c
+++ b/zipl/src/zipl.c
@@ -54,6 +54,7 @@ static const char* usage_text[] = {
"-h, --help Print this help, then exit",
"-v, --version Print version information, then exit",
"-c, --config CONFIGFILE Read configuration from CONFIGFILE",
+"-b, --blsdir BLSDIR Parse BootLoaderSpec files from BLSDIR",
"-t, --target TARGETDIR Write bootmap file to TARGETDIR and install",
" bootloader on device containing TARGETDIR",
" --targetbase BASEDEVICE Install bootloader on BASEDEVICE",
--
2.17.0

View File

@ -1,81 +0,0 @@
From ccc3beeb9920ba2a1087ae828b9c1de1fc5fb135 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Wed, 2 May 2018 12:26:49 +0200
Subject: [PATCH] zipl: Return number of allocated tokens in scan_file()
The function returns 0 on success and a negative number on error but is
useful to know how many tokens were allocated. This will be used by the
BLS parsing code to determine if needs to allocate mor tokens or not to
parse the BLS fragments.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
zipl/src/job.c | 8 ++++----
zipl/src/scan.c | 16 +++++++++-------
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/zipl/src/job.c b/zipl/src/job.c
index b06a4824333..9d5f00b6bdc 100644
--- a/zipl/src/job.c
+++ b/zipl/src/job.c
@@ -1732,7 +1732,7 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job)
struct scan_token* new_scan;
char* filename;
char* source;
- int rc;
+ int rc, scan_size;
/* Read configuration file */
if (cmdline->config != NULL) {
@@ -1750,10 +1750,10 @@ get_job_from_config_file(struct command_line* cmdline, struct job_data* job)
source = "";
}
printf("Using config file '%s'%s\n", filename, source);
- rc = scan_file(filename, &scan);
- if (rc) {
+ scan_size = scan_file(filename, &scan);
+ if (scan_size <= 0) {
error_text("Config file '%s'", filename);
- return rc;
+ return scan_size;
}
if ((cmdline->menu == NULL) && (cmdline->section == NULL)) {
rc = scan_check_defaultboot(scan);
diff --git a/zipl/src/scan.c b/zipl/src/scan.c
index 7465d6ccb6c..adb288e0626 100644
--- a/zipl/src/scan.c
+++ b/zipl/src/scan.c
@@ -538,9 +538,9 @@ scan_free(struct scan_token* array)
#define INITIAL_ARRAY_LENGTH 40
-/* Scan file FILENAME for tokens. Upon success, return zero and set TOKEN
- * to point to a NULL-terminated array of scan_tokens, i.e. the token id
- * of the last token is 0. Return non-zero otherwise. */
+/* Scan file FILENAME for tokens. Upon success, return the number allocated
+ * tokens and set TOKEN to point to a NULL-terminated array of scan_tokens,
+ * i.e. the token id of the last token is 0. Return non-zero otherwise. */
int
scan_file(const char* filename, struct scan_token** token)
{
@@ -623,11 +623,13 @@ scan_file(const char* filename, struct scan_token** token)
}
}
misc_free_file_buffer(&file);
- if (rc)
+ if (rc) {
scan_free(array);
- else
- *token = array;
- return rc;
+ return rc;
+ }
+
+ *token = array;
+ return size;
}
--
2.17.0

View File

@ -4,8 +4,8 @@
Name: s390utils
Summary: Utilities and daemons for IBM z Systems
Group: System Environment/Base
Version: 2.4.0
Release: 2%{?dist}
Version: 2.5.0
Release: 1%{?dist}
Epoch: 2
License: MIT
ExclusiveArch: s390 s390x
@ -31,13 +31,8 @@ Source22: 20-zipl-kernel.install
Source23: 52-zipl-rescue.install
Source24: 91-zipl.install
# https://bugzilla.redhat.com/show_bug.cgi?id=1566140
Patch0: s390-tools-2.3.0-zipl-pie.patch
# https://github.com/ibm-s390-tools/s390-tools/pull/28
Patch1: s390-tools-zipl-Return-number-allocated-tokens.patch
Patch2: s390-tools-zipl-Add-BootLoaderSpec-support.patch
Patch3: s390-tools-add-zipl-switch-to-blscfg-script.patch
Patch4: s390-tools-zipl-invert-script-options.patch
# change the defaults to match Fedora environment
Patch0: s390-tools-zipl-invert-script-options.patch
Patch1000: cmsfs-1.1.8-warnings.patch
Patch1001: cmsfs-1.1.8-kernel26.patch
@ -64,11 +59,7 @@ be used together with the zSeries (s390) Linux kernel and device drivers.
%setup -q -n s390-tools-%{version} -a 4 -a 6
# Fedora/RHEL changes
%patch0 -p1 -b .zipl-pie
%patch1 -p1 -b .number-allocated-tokens
%patch2 -p1 -b .add-BootLoaderSpec-support
%patch3 -p1 -b .add-zipl-switch-to-blscfg
%patch4 -p1 -b .zipl-invert-script-options
%patch0 -p1 -b .zipl-invert-script-options
#
# cmsfs
@ -814,6 +805,9 @@ User-space development files for the s390/s390x architecture.
%changelog
* Mon Jun 11 2018 Dan Horák <dan[at]danny.cz> - 2:2.5.0-1
- rebased to 2.5.0
* Thu May 24 2018 Javier Martinez Canillas <javierm@redhat.com> - 2:2.4.0-2
- zipl: Add BootLoaderSpec support
- Add kernel-install scripts to create BLS fragment files

View File

@ -1,3 +1,3 @@
SHA512 (cmsfs-1.1.8c.tar.gz) = 2ba5687d378fdd9871283728e81f1399047e74f9bba3936726eda11a978fe6ced1a300f15acb871d5daa26e61069d89767c753cf584f2731f5e99985db96aef0
SHA512 (src_vipa-2.1.0.tar.gz) = 8f6048e82b4bcc479dfb09d62da64b9519f66efc31889ff795ee6ca107e262167df57628c305f1b899c41bb3f035e6309552d8548c890855d319e8e60d6a6cf7
SHA512 (s390-tools-2.4.0.tar.gz) = de4d89f505567fe313df3c9110242d9476d0e20ff9b6f31ecbaa99c8a4e2b4bc959ab29ec6faf8b47c4e669f2eaa736f29a9e9908c95ced2e33db25b1c620c84
SHA512 (s390-tools-2.5.0.tar.gz) = 6f4c27ba4cf49aa46b165b0b2c218d72cf3ff5b99cc498af5d7774f0077f333d333c5eda2c031f04982e2d441f1f48f8979da639d4a80f98468b91ceb276a38d