Blame SOURCES/0019-fcoe-add-FCoE-UEFI-boot-device-support.patch

712866
From 1b827040f8b3e1e4fec19de76526fe0620654502 Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Mon, 7 Oct 2013 14:24:36 +0200
712866
Subject: [PATCH] fcoe: add FCoE UEFI boot device support
712866
712866
---
712866
 modules.d/95fcoe/module-setup.sh   |   1 +
712866
 modules.d/95fcoe/parse-uefifcoe.sh |  35 +++++++++
712866
 modules.d/99base/module-setup.sh   |   1 +
712866
 modules.d/99base/uefi-lib.sh       | 155 +++++++++++++++++++++++++++++++++++++
712866
 4 files changed, 192 insertions(+)
712866
 create mode 100755 modules.d/95fcoe/parse-uefifcoe.sh
712866
 create mode 100755 modules.d/99base/uefi-lib.sh
712866
712866
diff --git a/modules.d/95fcoe/module-setup.sh b/modules.d/95fcoe/module-setup.sh
5c6c2a
index d3c58cc6..08ba4eac 100755
712866
--- a/modules.d/95fcoe/module-setup.sh
712866
+++ b/modules.d/95fcoe/module-setup.sh
712866
@@ -32,6 +32,7 @@ install() {
712866
     inst "$moddir/fcoe-up.sh" "/sbin/fcoe-up"
712866
     inst "$moddir/fcoe-edd.sh" "/sbin/fcoe-edd"
712866
     inst "$moddir/fcoe-genrules.sh" "/sbin/fcoe-genrules.sh"
712866
+    inst_hook cmdline 20 "$moddir/parse-uefifcoe.sh"
712866
     inst_hook cmdline 99 "$moddir/parse-fcoe.sh"
712866
     dracut_need_initqueue
712866
 }
712866
diff --git a/modules.d/95fcoe/parse-uefifcoe.sh b/modules.d/95fcoe/parse-uefifcoe.sh
712866
new file mode 100755
5c6c2a
index 00000000..e03bcb39
712866
--- /dev/null
712866
+++ b/modules.d/95fcoe/parse-uefifcoe.sh
712866
@@ -0,0 +1,35 @@
712866
+#!/bin/bash
712866
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
712866
+# ex: ts=8 sw=4 sts=4 et filetype=sh
712866
+
712866
+command -v getarg >/dev/null          || . /lib/dracut-lib.sh
712866
+command -v get_fcoe_boot_mac >/dev/null || . /lib/uefi-lib.sh
712866
+command -v set_ifname >/dev/null || . /lib/net-lib.sh
712866
+
712866
+print_fcoe_uefi_conf()
712866
+{
712866
+    local mac dev vlan
712866
+    mac=$(get_fcoe_boot_mac)
712866
+    [ -z "$mac" ] && continue
712866
+    dev=$(set_ifname fcoe $mac)
712866
+    vlan=$(get_fcoe_boot_vlan)
712866
+    if [ "$vlan" -ne "0" ]; then
712866
+        case "$vlan" in
712866
+            [0-9]*)
712866
+                printf "%s\n" "vlan=$dev.$vlan:$dev"
712866
+                dev="$dev.$vlan"
712866
+                ;;
712866
+            *)
712866
+                printf "%s\n" "vlan=$vlan:$dev"
712866
+                dev="$vlan"
712866
+                ;;
712866
+        esac
712866
+    fi
712866
+    # fcoe=eth0:nodcb
712866
+    printf "%s\n" "$dev:nodcb"
712866
+}
712866
+
712866
+
712866
+if [ -e /sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data ]; then
712866
+    print_fcoe_uefi_conf > /etc/cmdline.d/40-fcoe-uefi.conf
712866
+fi
712866
diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh
5c6c2a
index 52ce4004..d33a0fb4 100755
712866
--- a/modules.d/99base/module-setup.sh
712866
+++ b/modules.d/99base/module-setup.sh
712866
@@ -42,6 +42,7 @@ install() {
712866
     mkdir -p ${initdir}/tmp
712866
 
712866
     inst_simple "$moddir/dracut-lib.sh" "/lib/dracut-lib.sh"
712866
+    inst_simple "$moddir/uefi-lib.sh" "/lib/uefi-lib.sh"
712866
 
712866
     if ! dracut_module_included "systemd"; then
712866
         inst_multiple switch_root || dfatal "Failed to install switch_root"
712866
diff --git a/modules.d/99base/uefi-lib.sh b/modules.d/99base/uefi-lib.sh
712866
new file mode 100755
5c6c2a
index 00000000..faedbac5
712866
--- /dev/null
712866
+++ b/modules.d/99base/uefi-lib.sh
712866
@@ -0,0 +1,155 @@
712866
+#!/bin/bash
712866
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
712866
+# ex: ts=8 sw=4 sts=4 et filetype=sh
712866
+#
712866
+# Copyright 2013 Red Hat, Inc.  All rights reserved.
712866
+# Copyright 2013 Harald Hoyer <harald@redhat.com>
712866
+#
712866
+# This program is free software; you can redistribute it and/or modify
712866
+# it under the terms of the GNU General Public License as published by
712866
+# the Free Software Foundation; either version 2 of the License, or
712866
+# (at your option) any later version.
712866
+#
712866
+# This program is distributed in the hope that it will be useful,
712866
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
712866
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
712866
+# GNU General Public License for more details.
712866
+#
712866
+# You should have received a copy of the GNU General Public License
712866
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
712866
+#
712866
+
712866
+getbyte () {
712866
+    local IFS= LC_CTYPE=C res c
712866
+    read -r -n 1 -d '' c
712866
+    res=$?
712866
+    # the single quote in the argument of the printf
712866
+    # yields the numeric value of $c (ASCII since LC_CTYPE=C)
712866
+    [[ -n $c ]] && c=$(printf '%u' "'$c") || c=0
712866
+    printf "$c"
712866
+    return $res
712866
+}
712866
+
712866
+getword () {
712866
+    local b1 b2 val
712866
+    b1=$(getbyte) || return 1
712866
+    b2=$(getbyte) || return 1
712866
+    (( val = b2 * 256 + b1 ))
712866
+    echo $val
712866
+    return 0
712866
+}
712866
+
712866
+# Acpi(PNP0A08,0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)/MAC(90E2BA265ED4,0x0)/Vlan(172)/Fibre(0x4EA06104A0CC0050,0x0)
712866
+uefi_device_path()
712866
+{
712866
+    local IFS= LC_CTYPE=C res tt len type hextype first
712866
+    first=1
712866
+
712866
+    while :; do
712866
+        type=$(getbyte) || return 1
712866
+        subtype=$(getbyte) || return 1
712866
+        len=$(getword) || return 1
712866
+        hextype=$(printf "%02x%02x" "$type" "$subtype")
712866
+        if [[ $first == 1 ]]; then
712866
+            first=0
712866
+        elif [[ $hextype != "7fff" ]]; then
712866
+            printf "/"
712866
+        fi
712866
+        case $hextype in
712866
+            0101)
712866
+                # PCI
712866
+                tt=$(getword)
712866
+                printf "PCI(0x%x,0x%x)" $(($tt / 256)) $(($tt & 255))
712866
+                ;;
712866
+            0201)
712866
+                # ACPI
712866
+                printf "Acpi(0x%x,0x%x)" $(($(getword) + $(getword) * 65536)) $(($(getword) + $(getword) * 65536))
712866
+                ;;
712866
+            0303)
712866
+                # FIBRE
712866
+                getword &>/dev/null
712866
+                getword &>/dev/null
712866
+                printf "Fibre(0x%x%x%x%x%x%x%x%x,0x%x)" \
712866
+                    $(getbyte) $(getbyte) $(getbyte) $(getbyte) \
712866
+                    $(getbyte) $(getbyte) $(getbyte) $(getbyte) \
712866
+                    $(( $(getword) + $(getword) * 65536 + 4294967296 * ( $(getword) + $(getword) * 65536 ) ))
712866
+                ;;
712866
+            030b)
712866
+                # MAC
712866
+                printf "MAC(%02x%02x%02x%02x%02x%02x," $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte)
712866
+                read -r -N 26  tt || return 1
712866
+                printf "0x%x)"  $(getbyte)
712866
+                ;;
712866
+            0314)
712866
+                # VLAN
712866
+                printf "VLAN(%d)" $(getword)
712866
+                ;;
712866
+            7fff)
712866
+                # END
712866
+                printf "\n"
712866
+                return 0
712866
+                ;;
712866
+            *)
712866
+                printf "Unknown(Type:%d SubType:%d len=%d)" "$type" "$subtype" "$len"
712866
+                read -r -N $(($len-4))  tt || return 1
712866
+                ;;
712866
+        esac
712866
+    done
712866
+}
712866
+
712866
+get_fcoe_boot_mac()
712866
+{
712866
+    data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data}
712866
+    [ -f $data ] || return 1
712866
+    local IFS= LC_CTYPE=C tt len type hextype
712866
+    first=1
712866
+
712866
+    while :; do
712866
+        type=$(getbyte) || return 1
712866
+        subtype=$(getbyte) || return 1
712866
+        len=$(getword) || return 1
712866
+        hextype=$(printf "%02x%02x" "$type" "$subtype")
712866
+        case $hextype in
712866
+            030b)
712866
+                # MAC
712866
+                printf "%02x:%02x:%02x:%02x:%02x:%02x" $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte)
712866
+                read -r -N 27  tt || return 1
712866
+                ;;
712866
+            7fff)
712866
+                # END
712866
+                return 0
712866
+                ;;
712866
+            *)
712866
+                read -r -N $(($len-4))  tt || return 1
712866
+                ;;
712866
+        esac
712866
+    done < $data
712866
+}
712866
+
712866
+get_fcoe_boot_vlan()
712866
+{
712866
+    data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data}
712866
+    [ -f $data ] || return 1
712866
+    local IFS= LC_CTYPE=C tt len type hextype
712866
+    first=1
712866
+
712866
+    while :; do
712866
+        type=$(getbyte) || return 1
712866
+        subtype=$(getbyte) || return 1
712866
+        len=$(getword) || return 1
712866
+        hextype=$(printf "%02x%02x" "$type" "$subtype")
712866
+        case $hextype in
712866
+            0314)
712866
+                # VLAN
712866
+                printf "%d" $(getword)
712866
+                ;;
712866
+            7fff)
712866
+                # END
712866
+                return 0
712866
+                ;;
712866
+            *)
712866
+                read -r -N $(($len-4))  tt || return 1
712866
+                ;;
712866
+        esac
712866
+    done < $data
712866
+}