Blame SOURCES/0029-pc-bios-s390-ccw-fix-non-sequential-boot-entries-eck.patch

26ba25
From c0577fcb360841afe54f76deee37ea4a52761bf3 Mon Sep 17 00:00:00 2001
26ba25
From: Collin Walling <walling@linux.ibm.com>
26ba25
Date: Tue, 8 May 2018 09:01:15 +0000
26ba25
Subject: pc-bios/s390-ccw: fix non-sequential boot entries (eckd)
26ba25
26ba25
zIPL boot menu entries can be non-sequential. Let's account
26ba25
for this issue for the s390 zIPL boot menu. Since this boot
26ba25
menu is actually an imitation and is not completely capable
26ba25
of everything the real zIPL menu can do, let's also print a
26ba25
different banner to the user.
26ba25
26ba25
Signed-off-by: Collin Walling <walling@linux.ibm.com>
26ba25
Reported-by: Vasily Gorbik <gor@linux.ibm.com>
26ba25
Reviewed-by: Thomas Huth <thuth@redhat.com>
26ba25
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
26ba25
Signed-off-by: Thomas Huth <thuth@redhat.com>
26ba25
(cherry picked from commit 7385e947fc65a44dd05abb86c874beb915c1989c)
26ba25
---
26ba25
 pc-bios/s390-ccw/menu.c | 29 ++++++++++++++++++++---------
26ba25
 1 file changed, 20 insertions(+), 9 deletions(-)
26ba25
26ba25
diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c
26ba25
index 96eec81..aaf5d61 100644
26ba25
--- a/pc-bios/s390-ccw/menu.c
26ba25
+++ b/pc-bios/s390-ccw/menu.c
26ba25
@@ -158,7 +158,7 @@ static void boot_menu_prompt(bool retry)
26ba25
     }
26ba25
 }
26ba25
 
26ba25
-static int get_boot_index(int entries)
26ba25
+static int get_boot_index(bool *valid_entries)
26ba25
 {
26ba25
     int boot_index;
26ba25
     bool retry = false;
26ba25
@@ -168,7 +168,8 @@ static int get_boot_index(int entries)
26ba25
         boot_menu_prompt(retry);
26ba25
         boot_index = get_index();
26ba25
         retry = true;
26ba25
-    } while (boot_index < 0 || boot_index >= entries);
26ba25
+    } while (boot_index < 0 || boot_index >= MAX_BOOT_ENTRIES ||
26ba25
+             !valid_entries[boot_index]);
26ba25
 
26ba25
     sclp_print("\nBooting entry #");
26ba25
     sclp_print(uitoa(boot_index, tmp, sizeof(tmp)));
26ba25
@@ -176,7 +177,8 @@ static int get_boot_index(int entries)
26ba25
     return boot_index;
26ba25
 }
26ba25
 
26ba25
-static void zipl_println(const char *data, size_t len)
26ba25
+/* Returns the entry number that was printed */
26ba25
+static int zipl_print_entry(const char *data, size_t len)
26ba25
 {
26ba25
     char buf[len + 2];
26ba25
 
26ba25
@@ -185,12 +187,15 @@ static void zipl_println(const char *data, size_t len)
26ba25
     buf[len + 1] = '\0';
26ba25
 
26ba25
     sclp_print(buf);
26ba25
+
26ba25
+    return buf[0] == ' ' ? atoui(buf + 1) : atoui(buf);
26ba25
 }
26ba25
 
26ba25
 int menu_get_zipl_boot_index(const char *menu_data)
26ba25
 {
26ba25
     size_t len;
26ba25
-    int entries;
26ba25
+    int entry;
26ba25
+    bool valid_entries[MAX_BOOT_ENTRIES] = {false};
26ba25
     uint16_t zipl_flag = *(uint16_t *)(menu_data - ZIPL_FLAG_OFFSET);
26ba25
     uint16_t zipl_timeout = *(uint16_t *)(menu_data - ZIPL_TIMEOUT_OFFSET);
26ba25
 
26ba25
@@ -202,19 +207,25 @@ int menu_get_zipl_boot_index(const char *menu_data)
26ba25
         timeout = zipl_timeout * 1000;
26ba25
     }
26ba25
 
26ba25
-    /* Print and count all menu items, including the banner */
26ba25
-    for (entries = 0; *menu_data; entries++) {
26ba25
+    /* Print banner */
26ba25
+    sclp_print("s390-ccw zIPL Boot Menu\n\n");
26ba25
+    menu_data += strlen(menu_data) + 1;
26ba25
+
26ba25
+    /* Print entries */
26ba25
+    while (*menu_data) {
26ba25
         len = strlen(menu_data);
26ba25
-        zipl_println(menu_data, len);
26ba25
+        entry = zipl_print_entry(menu_data, len);
26ba25
         menu_data += len + 1;
26ba25
 
26ba25
-        if (entries < 2) {
26ba25
+        valid_entries[entry] = true;
26ba25
+
26ba25
+        if (entry == 0) {
26ba25
             sclp_print("\n");
26ba25
         }
26ba25
     }
26ba25
 
26ba25
     sclp_print("\n");
26ba25
-    return get_boot_index(entries - 1); /* subtract 1 to exclude banner */
26ba25
+    return get_boot_index(valid_entries);
26ba25
 }
26ba25
 
26ba25
 
26ba25
-- 
26ba25
1.8.3.1
26ba25