-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30_android-prober
executable file
·230 lines (185 loc) · 5.22 KB
/
30_android-prober
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
set -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
. "$pkgdatadir/grub-mkconfig_lib"
. /etc/default/grub
export TEXTDOMAIN=grub
export TEXTDOMAINDIR="${datarootdir}/locale"
CLASS="--class android --class os"
OS="Android"
sub_indent() { echo -e "$submenu_indentation$*"; }
android_entry() {
local \
title=$1 \
menuentry_id=$2 \
kernel=$3 \
initrd=$4 \
disk=$5 \
cmdline=$6
sub_indent "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option '$menuentry_id' {"
save_default_entry | grub_add_tab
# Use ELILO's generic "efifb" when it's known to be available.
# FIXME: We need an interface to select vesafb in case efifb can't be used.
if [ ! "$GRUB_GFXPAYLOAD_LINUX" ]; then
sub_indent " load_video"
grep -qx "CONFIG_FB_EFI=y" "${config}" 2>/dev/null &&
grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2>/dev/null &&
sub_indent " set gfxpayload=keep"
else
[ "$GRUB_GFXPAYLOAD_LINUX" = text ] ||
sub_indent " load_video"
sub_indent " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX"
fi
sub_indent " insmod gzio"
echo "$disk" | sed "s/^/$submenu_indentation /gm"
sub_indent " linux $kernel $cmdline root=/dev/ram0"
sub_indent " initrd $initrd"
sub_indent "}\n"
}
gen_entry() {
local entry_string=$1 \
device \
src \
os \
detected_type \
initrds \
ucodes \
system \
data \
cmdline
shift
i=1
while read -rd $'\0' arg; do
case $i in
1) device=$arg ;;
2) src=$arg ;;
3) os=$arg ;;
4) detected_type=$arg ;;
5) initrds=$arg ;;
6) ucodes=$arg ;;
7) system=$arg ;;
8) data=$arg ;;
9) cmdline=${arg:-$GRUB_CMDLINE_ANDROID} ;;
*) break ;;
esac
i=$((i + 1))
done < <(sed 's/\xFF0/\xFF\x00/g; s/\xFF\(.\)/\1/g' <<<"$entry_string")
ucode_list=""
ucode=""
disk="$(prepare_grub_to_access_device "$device")"
boot_device_id="$(grub_get_device_id "$device")"
unset IFS
echo "Found $os on $device" >&2
local type=default \
MAIN_ENTRY \
EXTENDED_ENTRIES
# Extra indentation to add to menu entries in a submenu. We're not in a submenu
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
local title
entry() {
android_entry \
"$title" \
"${OS}-${src##*/}-${1##*/}-${2##*/}-${type}-${boot_device_id}" \
"${src}/${1}" \
"${ucode_list# } ${src}/${2}" \
"$disk" \
"$cmdline"
}
parse_to_entry() {
if [ "$type" = "default" ]; then
MAIN_ENTRY=$(entry "$@")
type=extended
submenu_indentation=$grub_tab
fi
EXTENDED_ENTRIES="$EXTENDED_ENTRIES\n$(entry "$@")"
}
local ucode
if [ "$src" ]; then
cmdline="$cmdline SRC=$src"
fi
IFS=","
case "$detected_type" in
gearlock*)
for ucode in $ucodes; do
ucode_list="$ucode_list $src/boot/$ucode"
done
ROOT_DEVICE=$device
if [ "$GRUB_DISABLE_LINUX_UUID" != "true" ]; then
ROOT_UUID=$(${grub_probe} --device "$device" --target=fs_uuid 2>/dev/null)
[ "$ROOT_UUID" ] &&
ROOT_DEVICE="UUID=$ROOT_UUID"
fi
cmdline="$cmdline ROOT=$ROOT_DEVICE SYSTEM=$system DATA=$data GEARLOCK=$detected_type"
local kver
for kver in $initrds; do
[ "$type" = "default" ] || title="$os, with kernel-$kver - $system"
parse_to_entry "boot/kernel-$kver" "boot/initrd-$kver.img"
done
;;
*)
for ucode in $ucodes; do
ucode_list="$ucode_list $src/$ucode"
done
if [ "$data" ]; then
cmdline="$cmdline DATA=$data"
fi
case "$detected_type" in
ab | fstab)
ROOT_DEVICE=$device
case "$detected_type" in
fstab) if [ "$GRUB_DISABLE_LINUX_UUID" != "true" ]; then
ROOT_UUID=$(${grub_probe} --device "$device" --target=fs_uuid 2>/dev/null)
[ "$ROOT_UUID" ] && ROOT_DEVICE="UUID=$ROOT_UUID"
fi ;;
*) ;;
esac
cmdline="$cmdline ROOT=$ROOT_DEVICE"
local slot
for slot in a b; do
[ "$type" = "default" ] || title="$os - Slot ${slot^}"
cmdline="$cmdline androidboot.slot_suffix=_$slot"
parse_to_entry "kernel_$slot" "initrd_$slot.img"
done
;;
*)
if [ "$system" ]; then
cmdline="$cmdline SYSTEM=$system"
fi
cmdline="$cmdline ROOT=$device"
local kernels=$detected_type kernel initrd
for kernel in $kernels; do
for initrd in $initrds; do
[ "$type" = "default" ] || title="$title, with ${kernel##*/}, and ${initrd##*/}"
parse_to_entry "$kernel" "$initrd"
done
done
;;
esac
;;
esac
unset IFS
cat <<EOF
$(echo -e "$MAIN_ENTRY")
submenu '$(echo "Advanced options for $os" | grub_quote)' --class submenu ${CLASS} \$menuentry_id_option '${OS}-${src##*/}-${type}-${boot_device_id}' {
$(echo -e "$EXTENDED_ENTRIES")
}
EOF
}
while read -r detect_entry; do
gen_entry "$detect_entry"
done < <(grub-android-prober)