File grub2-s390x-05-grub2-mkconfig.patch of Package grub2

From: Raymund Will <rw@suse.com>
Subject: Enable grub2-mkconfig for s390x-emu
References: fate#314213, bnc#868909
Patch-Mainline: no

V2:
  * omit subvolume-prefix for platform "emu"
V3:
  * add 'conmode=' to command-line if GRUB_CONMODE exists.  [bnc#868909]
V4:
  * remove 's' from possible hot-keys for "bootable snapshots".  [bnc#885668]

---
 util/grub.d/10_linux.in |   63 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 51 insertions(+), 12 deletions(-)

Index: grub-2.02~beta2/util/grub.d/10_linux.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/10_linux.in
+++ grub-2.02~beta2/util/grub.d/10_linux.in
@@ -51,6 +51,10 @@ else
   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
 fi
 
+if [ "x$GRUB_CONMODE" != "x" ]; then
+  GRUB_CMDLINE_LINUX="conmode=${GRUB_CONMODE} ${GRUB_CMDLINE_LINUX}"
+fi
+
 case x"$GRUB_FS" in
     xbtrfs)
 	rootsubvol="`make_system_path_relative_to_its_root /`"
@@ -67,6 +71,21 @@ esac
 
 title_correction_code=
 
+hotkey=1
+incr_hotkey()
+{
+  [ -z "$hotkey" ] && return
+  expr $hotkey + 1
+}
+print_hotkey()
+{
+  keys="123456789abdfgijklmnoprtuvwyz"
+  if [ -z "$hotkey" ]||[ $hotkey -eq 0 ]||[ $hotkey -gt 30 ]; then
+    return
+  fi
+  echo "--hotkey=$(expr substr $keys $hotkey 1)"
+}
+
 linux_entry ()
 {
   os="$1"
@@ -96,9 +115,11 @@ linux_entry ()
 	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
 	  grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
       fi
-      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      echo "menuentry '$(echo "$title" | grub_quote)' $(print_hotkey) ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      hotkey=$(incr_hotkey)
   else
-      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      echo "menuentry '$(echo "$os" | grub_quote)' $(print_hotkey) ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      hotkey=$(incr_hotkey)
   fi      
   if [ x$type != xrecovery ] ; then
       save_default_entry | grub_add_tab
@@ -121,6 +142,7 @@ linux_entry ()
 
   echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
 
+ if [ $PLATFORM != emu ]; then # 'search' does not work for now
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then
       prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
@@ -132,6 +154,7 @@ linux_entry ()
     fi
     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   fi
+ fi
   message="$(gettext_printf "Loading Linux %s ..." ${version})"
   if [ -d /sys/firmware/efi ] && [ "x${GRUB_USE_LINUXEFI}" = "xtrue" ]; then
     sed "s/^/$submenu_indentation/" << EOF
@@ -166,17 +189,15 @@ EOF
 
 machine=`uname -m`
 case "x$machine" in
-    xi?86 | xx86_64)
-	list=
-	for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
-	    if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
-	done ;;
-    *) 
-	list=
-	for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
-                  if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
-	done ;;
+    xi?86 | xx86_64) klist="/boot/vmlinuz-* /vmlinuz-* /boot/kernel-*" ;;
+    xs390 | xs390x)  klist="/boot/image-* /boot/kernel-*" ;;
+    *) klist="/boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* \
+		/boot/kernel-*" ;;
 esac
+list=
+for i in $klist ; do
+    if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
+done
 
 case "$machine" in
     i?86) GENKERNEL_ARCH="x86" ;;
@@ -186,6 +207,15 @@ case "$machine" in
     *) GENKERNEL_ARCH="$machine" ;;
 esac
 
+PLATFORM="native"
+if [ -d /sys/firmware/efi ]&&[ "x${GRUB_USE_LINUXEFI}" = "xtrue" ]; then
+    PLATFORM="efi"
+else
+    case "$machine" in
+        s390*) PLATFORM="emu" ;;
+    esac
+fi
+
 prepare_boot_cache=
 prepare_root_cache=
 boot_device_id=
@@ -202,6 +232,11 @@ while [ "x$list" != "x" ] ; do
   basename=`basename $linux`
   dirname=`dirname $linux`
   rel_dirname=`make_system_path_relative_to_its_root $dirname`
+  if [ $PLATFORM != "emu" ]; then
+    hotkey=0
+  else
+    rel_dirname=$dirname
+  fi
   version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`
   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
@@ -286,7 +321,8 @@ while [ "x$list" != "x" ] ; do
 	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
     fi
     # TRANSLATORS: %s is replaced with an OS name
-    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' $(print_hotkey) \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+    hotkey=$(incr_hotkey)
     is_top_level=false
   fi