network: don't use "ifup -m"
[dracut.git] / modules.d / 99uefi-lib / uefi-lib.sh
blob6b2639902c8a88ce716de55ede95131cd71a9836
1 #!/bin/bash
3 # Copyright 2013 Red Hat, Inc. All rights reserved.
4 # Copyright 2013 Harald Hoyer <harald@redhat.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 getbyte () {
21 local IFS= LC_CTYPE=C res c
22 read -r -n 1 -d '' c
23 res=$?
24 # the single quote in the argument of the printf
25 # yields the numeric value of $c (ASCII since LC_CTYPE=C)
26 [[ -n $c ]] && c=$(printf '%u' "'$c") || c=0
27 printf "$c"
28 return $res
31 getword () {
32 local b1 b2 val
33 b1=$(getbyte) || return 1
34 b2=$(getbyte) || return 1
35 (( val = b2 * 256 + b1 ))
36 echo $val
37 return 0
40 # Acpi(PNP0A08,0x0)/Pci(0x3,0x0)/Pci(0x0,0x0)/MAC(90E2BA265ED4,0x0)/Vlan(172)/Fibre(0x4EA06104A0CC0050,0x0)
41 uefi_device_path()
43 local IFS= LC_CTYPE=C res tt len type hextype first
44 first=1
46 while :; do
47 type=$(getbyte) || return 1
48 subtype=$(getbyte) || return 1
49 len=$(getword) || return 1
50 hextype=$(printf "%02x%02x" "$type" "$subtype")
51 if [[ $first == 1 ]]; then
52 first=0
53 elif [[ $hextype != "7fff" ]]; then
54 printf "/"
56 case $hextype in
57 0101)
58 # PCI
59 tt=$(getword)
60 printf "PCI(0x%x,0x%x)" $(($tt / 256)) $(($tt & 255))
62 0201)
63 # ACPI
64 printf "Acpi(0x%x,0x%x)" $(($(getword) + $(getword) * 65536)) $(($(getword) + $(getword) * 65536))
66 0303)
67 # FIBRE
68 getword &>/dev/null
69 getword &>/dev/null
70 printf "Fibre(0x%x%x%x%x%x%x%x%x,0x%x)" \
71 $(getbyte) $(getbyte) $(getbyte) $(getbyte) \
72 $(getbyte) $(getbyte) $(getbyte) $(getbyte) \
73 $(( $(getword) + $(getword) * 65536 + 4294967296 * ( $(getword) + $(getword) * 65536 ) ))
75 030b)
76 # MAC
77 printf "MAC(%02x%02x%02x%02x%02x%02x," $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte)
78 read -r -N 26 tt || return 1
79 printf "0x%x)" $(getbyte)
81 0314)
82 # VLAN
83 printf "VLAN(%d)" $(getword)
85 7fff)
86 # END
87 printf "\n"
88 return 0
91 printf "Unknown(Type:%d SubType:%d len=%d)" "$type" "$subtype" "$len"
92 read -r -N $(($len-4)) tt || return 1
94 esac
95 done
98 get_fcoe_boot_mac()
100 data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data}
101 [ -f $data ] || return 1
102 local IFS= LC_CTYPE=C tt len type hextype
103 first=1
105 while :; do
106 type=$(getbyte) || return 1
107 subtype=$(getbyte) || return 1
108 len=$(getword) || return 1
109 hextype=$(printf "%02x%02x" "$type" "$subtype")
110 case $hextype in
111 030b)
112 # MAC
113 printf "%02x:%02x:%02x:%02x:%02x:%02x" $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte) $(getbyte)
114 read -r -N 27 tt || return 1
116 7fff)
117 # END
118 return 0
121 read -r -N $(($len-4)) tt || return 1
123 esac
124 done < $data
127 get_fcoe_boot_vlan()
129 data=${1:-/sys/firmware/efi/vars/FcoeBootDevice-a0ebca23-5f9c-447a-a268-22b6c158c2ac/data}
130 [ -f $data ] || return 1
131 local IFS= LC_CTYPE=C tt len type hextype
132 first=1
134 while :; do
135 type=$(getbyte) || return 1
136 subtype=$(getbyte) || return 1
137 len=$(getword) || return 1
138 hextype=$(printf "%02x%02x" "$type" "$subtype")
139 case $hextype in
140 0314)
141 # VLAN
142 printf "%d" $(getword)
144 7fff)
145 # END
146 return 0
149 read -r -N $(($len-4)) tt || return 1
151 esac
152 done < $data