busybox: add getedid script

This commit is contained in:
DaVukovic 2016-12-18 17:00:49 +01:00 committed by Christian Hewitt
parent ba1c7002cd
commit cce01587e7
2 changed files with 294 additions and 0 deletions

View File

@ -155,6 +155,7 @@ makeinstall_host() {
makeinstall_target() {
mkdir -p $INSTALL/usr/bin
[ $TARGET_ARCH = x86_64 ] && cp $PKG_DIR/scripts/getedid $INSTALL/usr/bin
cp $PKG_DIR/scripts/createlog $INSTALL/usr/bin/
cp $PKG_DIR/scripts/lsb_release $INSTALL/usr/bin/
cp $PKG_DIR/scripts/apt-get $INSTALL/usr/bin/

View File

@ -0,0 +1,293 @@
#!/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 file, therefore no restore
# 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 = no xorg.conf in /storage/.config
# exit 8 = more than a single device detected
# Help message and usage explanation
help() {
clear
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 custon EDID, just use this script like: getedid create"
echo ""
echo "If you have already used this script and wish to restore original behaviour, use: getedid default"
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
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 "The system is rebooting in 15 seconds"
sleep 15
reboot
}
# 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
}
# restore the backup done by the script and depending on the GPU
restore() {
if [ "$gpu" = "intel" ]; then
check_file
if [ -f "$file".old ]; then
mount_rw
cp "$file".old "$file" # cp because of keeping the backup...just in case
sys_reboot
else
echo "You have not created a custom EDID yet, or you did not use this script for this task."
echo "Therefore we can't ensure the script is working properly."
echo "Exiting"
exit 3
fi
elif [ "$gpu" = "nvidia" ]; then
if [ -f /storage/.config/xorg.conf ]; then
mv /storage/.config/xorg.conf /storage/.config/xorg.le.backup
systemctl restart xorg.service
else
echo "You don't have a xorg.conf in your .config folder. Everything is already at default. Exiting"
exit 7
fi
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 8
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 8
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
}
# start script from here
case "$1" in
'create')
check_gpu
run
;;
'default')
check_gpu
restore
;;
'gpu')
check_gpu
echo "$gpu"
;;
'delete')
check_gpu
del_edid
;;
'help')
help
;;
*)
echo "Usage $0 { create | default | gpu | delete | help }"
;;
esac