-
Notifications
You must be signed in to change notification settings - Fork 0
/
getedid
executable file
·259 lines (219 loc) · 7.37 KB
/
getedid
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/sh
################################################################################
# This file is part of LibreELEC - https://libreelec.tv
# Copyright (C) 2016 Team LibreELEC
#
# LibreELEC 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 2 of the License, or
# (at your option) any later version.
#
# LibreELEC 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 LibreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
#
#
# exit 1 = unsupported GPU
# exit 2 = dual boot system
# exit 3 = no backup for syslinux.cfg or extlinux.conf
# exit 4 = extlinux.conf and syslinux.cfg are available
# exit 5 = changes are already made either to extlinux.conf or syslinux.cfg
# exit 6 = xorg.conf already exists in /storage/.config
# exit 7 = more than a single device detected
# Help message and usage explanation
help() {
echo "This script generates a custom EDID depending on your GPU"
echo ""
echo "To check which GPU you are using, use: getedid gpu"
echo ""
echo "To create a custom EDID, just use this script like: getedid create"
echo ""
echo "If you don't want to use the created EDID file anymore use: getedid delete"
echo ""
echo "If you hardware has changed and you want to have a custom EDID again, then you have to delete the old EDID first."
echo "For this use: getedid delete "
echo "And then use: getedid create"
}
# check for GPU and store string
check_gpu() {
if lspci | grep -i vga | grep -i -q intel ; then
gpu="intel"
elif lspci | grep -i vga | grep -i -q nvidia; then
gpu="nvidia"
else
echo "GPU is not supported"
exit 1
fi
}
# run this first if the user already has a custom EDID but want to create a new one (TV or AVR change)
del_edid() {
if [ "$gpu" = "intel" ]; then
check_file
if [ -f "$file".old ]; then
mount_rw
rm "$file"
mv "$file".old "$file"
rm -f /flash/edid.cpio
mount_ro
rm -fr /storage/.config/firmware
sys_reboot
else
echo "You don't have a backup file for $file. You did not use this script to create the custom EDID"
echo "Therefore we can't be sure the script is working prooerly. Exiting"
exit 3
fi
else
rm -f /storage/.config/xorg.conf
rm -f /storage/.config/xorg.le.backup
systemctl restart xorg.service
echo -n "nvidia success"
fi
}
# run main script depending on the GPU
run() {
if [ "$gpu" = "intel" ]; then
intel
elif [ "$gpu" = "nvidia" ]; then
nvidia
fi
}
# mounting /flash to rw
mount_rw() {
mount -o remount,rw /flash
}
# mounting /flash to ro
mount_ro() {
mount -o remount,ro /flash
}
# remount /flash to ro and reboot
sys_reboot() {
mount_ro
echo -n "intel success"
}
# check syslinux.cfg and/or extlinux.conf
check_file() {
# check boot system
if [ -d /sys/firmware/efi ]; then
sys_boot="UEFI"
sys_path="/flash/EFI/BOOT"
else
sys_boot="BIOS"
sys_path="/flash"
fi
#check which file is available
if [ -f "$sys_path/syslinux.cfg" -a -f "$sys_path/extlinux.conf" ]; then
echo "Your system contains both a /flash/syslinux.cfg and a /flash/extlinux.conf file"
echo "Something is wrong on your system. Exiting"
exit 4
elif [ -f "$sys_path/extlinux.conf" ]; then
file="$sys_path/extlinux.conf"
elif [ -f "$sys_path/syslinux.cfg" ]; then
file="$sys_path/syslinux.cfg"
else
echo "You neither have a extlinux.conf nor do you have a syslinux.cfg."
echo "Dual boot systems aren't supported"
exit 2
fi
}
check_content() {
# check if changes are already made to $file and exit if yes
if grep -q "initrd=/edid.cpio drm_kms_helper.edid_firmware=" $file ; then
echo "$file has been modified. Exiting."
exit 5
fi
}
intel() {
#check which output is connnected:
counter=0
for i in /sys/class/drm/*; do
if [ "$(cat "$i"/status 2>/dev/null)" = "connected" ]; then
counter=$((counter + 1))
if [ $counter -gt 0 -a $counter -lt 2 ]; then
card="$(echo "$i" | cut -d / -f 5)"
hdmi="$(echo "$i" | cut -d / -f 5 | sed 's/card[0-9]-//g')"
else
echo "More than a single device connected. Probably enable \"Disable all other monitors\" at Kodi settings. Aborting!"
exit 7
fi
fi
done
#create edid
mkdir -p /storage/.config/firmware/edid
cat "/sys/class/drm/$card/edid" > /storage/.config/firmware/edid/edid.bin
#create cpio archive
cd /storage
mkdir -p cpio/lib/firmware/edid
cp /storage/.config/firmware/edid/edid.bin /storage/cpio/lib/firmware/edid/
cd cpio/
find . -print | cpio -ov -H newc > /storage/edid.cpio
cd /storage
rm -rf cpio
#check extlinux.conf and syslinux.cfg
check_file
check_content
#remount /flash to rw
mount_rw
mv /storage/edid.cpio /flash
# make a backup of $file
cp "$file" "$file".old
#add things to $file
sed -i "/ APPEND/s/$/ initrd=\/edid.cpio drm_kms_helper.edid_firmware=$hdmi:edid\/edid.bin video=$hdmi:D/" "$file"
#reboot
sys_reboot
}
nvidia() {
# check if xorg.conf already exists
if [ -f /storage/.config/xorg.conf -o -f /storage/.config/xorg-nvidia.conf ]; then
echo "Existing /storage/.config/xorg.conf detected. Aborting!"
exit 6
fi
# check for multi-montior setup
monitors="$(grep -i -w "connected" /var/log/Xorg.0.log | grep -i -o "dfp-[0-9]" | sort -u | wc -l)"
if [ "$monitors" -gt "1" ]; then
echo "You have more than a single monitor connected. The script doesn't support a multi-monitor setup. Aborting!"
exit 7
fi
# set debug and restart Xorg
cp /etc/X11/xorg-nvidia.conf /storage/.config/xorg.conf
sed -i 's/"ModeDebug" "false"/"ModeDebug" "true"/g' /storage/.config/xorg.conf
systemctl restart xorg.service
# get port
nv_port="$(grep -i -w connected /var/log/Xorg.0.log | grep -i -o "dfp-[0-9]" | sort -u)"
nvidia-xconfig --extract-edids-from-file=/var/log/Xorg.0.log --extract-edids-output-file=/storage/.config/edid.bin 1>/dev/null
# set mode debug back to false
sed -i 's/"ModeDebug" "true"/"ModeDebug" "false"/g' /storage/.config/xorg.conf
# set port and uncomment lines
sed -i "s/# Option \"ConnectedMonitor\" \"DFP-0\"/ Option \"ConnectedMonitor\" \"$nv_port\"/g" /storage/.config/xorg.conf
sed -i "s/# Option \"CustomEDID\" \"DFP-0:\/storage\/.config\/edid.bin\"/ Option \"CustomEDID\" \"\"$nv_port\":\/storage\/.config\/edid.bin\"/g" /storage/.config/xorg.conf
sed -i "s/# Option \"IgnoreEDID\" \"false\"/ Option \"IgnoreEDID\" \"false\"/g" /storage/.config/xorg.conf
sed -i "s/# Option \"UseEDID\" \"true\"/ Option \"UseEDID\" \"true\"/g" /storage/.config/xorg.conf
# restart xorg.service
systemctl restart xorg.service
echo -n "nividia success"
}
# start script from here
case "$1" in
'create')
check_gpu
run
;;
'gpu')
check_gpu
echo -n "$gpu"
;;
'delete')
check_gpu
del_edid
;;
'help')
help
;;
*)
echo "Usage $0 { create | gpu | delete | help }"
;;
esac