pentoo-livecd: check if fglrx supports hardware before building module. Add OSS fallback for binary modules.

This commit is contained in:
Zero_Chaos 2014-09-16 03:40:15 +00:00
parent 549e4d21fb
commit 37b73e910d
4 changed files with 106 additions and 301 deletions

View file

@ -1,5 +1,4 @@
AUX binary-driver-handler.initd-2014.3-r5 7875 SHA256 4611d47211f7ff5de4dc1f90e3b8e46e1e086473b8f336007ebb1d374a89f3b7 SHA512 6caa2824c85a4efbeadd407eac35a9f4b230095da9992eca9ab029475166bf081e7113e441f3d69089efcf92fa9b8528c9110f2681184653b4d49bdc3078bebd WHIRLPOOL 85ed5978936bf6feecbfa41c5d88c00b8d478a1bcf7b082eabea52c31de4844b140c758e71f16688ea874e0d859b616a0363d927f1b5054e962a9d55ccde4360
AUX binary-driver-handler.initd-2014.3-r6 7824 SHA256 79a06ebca02b4152aec9a1dfbc7c74add6cdb6a15deab90b1b9a88fd9d97e08a SHA512 8c0b129a26534eb1922e997bd3a31b654111b881f34b1cd032c7a8c552b9720b094c06890dc059906723a962b1d520311932a5ba41d96959a9e7aff23b6b1573 WHIRLPOOL 9de9cf953d38b71ecbf78f15d5065efb26a975f38c5a7ec2be7017844186cfe6db9ef91c37999c787a8a29e182d25072fcce56107b3dfbbef6f1c01e8f7a6c89
AUX binary-driver-handler.initd-2014.3-r8 9869 SHA256 44c681d8ab9d6447c9bcf2193c2dfd62031929e1d9ed4af5079131e8a70a19ac SHA512 c5dfcb80cb417f736e998cc1317d2adc37b81b9e5c602b5adf16b45c664b07c7f4a3358502bf8e9605063c02cc1102bf7c5d33ffedc714a7cf72b0895ef0ac2f WHIRLPOOL ecbfb0f3395ef2e8b1ed05b6fd19a06c07110dec11158ed5065163079807023c0f1a2ae0dc3895bb43a19380ec61a0c2943030fee530c658dfcc4f376bb5a674
AUX flushchanges-2014.3-r5 1874 SHA256 0a229f43ccd2c158cb872c8f1f6efd5f177d199ad77a807657cfb83e95a19d62 SHA512 72816d6f157bfcd92138f47cc54d114ea2572e85d383f3b423c5ab77a6535e1ac3c259ace3258d3a9c49c332677be6408bc96610914a4abff8f62780c6fec7ed WHIRLPOOL 1bf74ccdf9c203e943ad5a8fd98a1c56fe1ede1ba9b44171e700fd2a40fa08973bfeff315d79a8efa0ca1d6af7e88cc94022e8bebf9fd06cf3ab95d9d1178a96
AUX makemo-2014.3-r7 2316 SHA256 1ddf98020a975eec0ab21ec17d21e9171f39f7990e80cd3ff2d7657365a1ab6a SHA512 fc9ed8fe94100d007da576513e6fe3421bb3aa8873cc58a53397b626e492e0ead5d1091254104698e7412e92c1b819d020d3f89172caf06c55f63cf2f0876aaa WHIRLPOOL 1fb610869094168092bc4682a816cbdf316192698952b8c8345d88d88fae3de1e3177438e7fad24a4be985249f0b29189fb2096d075dacaca7c9aec47deb7de0
EBUILD pentoo-livecd-2014.3-r7.ebuild 938 SHA256 e7bd637f9a8d222662ce5c91f4a92cd179e83cd72834c8925ce0e9747eb048ee SHA512 d8ed1d5123670560d8ed1a5189e8f7537807ac584bf2973a679b022539297f99e792daa4c6c12d43900b413ae384eddf1d99bcff44aba3076a18c6a9ea16f81e WHIRLPOOL a0beaec53b0e6d573708e8d5915e6aa1033d231dac9d9cbe91500cb54bbeea554bc44abf91be19595394f03c07af60446f3467132622e6eb0eb829234194af83
EBUILD pentoo-livecd-2014.3-r8.ebuild 938 SHA256 64a6d08cef6c8f458e6fcef54ea916e9245e2ef83a6be4e10a6d4895b6d8b126 SHA512 a47754402dda0ae3379e6e629b368cea0cd4f7124d2d4c0779eee5c7c01753a678ab597c442169e7b79b2dfb15ec7aefe5c80ec6520ba2736ae817a4a4b6e2a5 WHIRLPOOL 90bb226432aa693927df7e952d7bbf61f5a28216e2179c7f3e221bcad6b50a66b8aac3809886d0a25c7866d7e67b4eacd5f6f6bd4a10140235b4024adcc9dee2

View file

@ -1,248 +0,0 @@
#!/bin/bash
#!/sbin/runscript
#seriously, fuck you AMD and Nvidia. Write a sane license that permits redistribution, we just want your shitty hardware to work
#todo: detect if the drivers should work *BEFORE* building and switching to them.
extra_commands="aufs_module"
depend() {
before xdm
}
start() {
BLACKLIST_FILE="/etc/modprobe.d/blacklist.conf"
blacklist() {
grep -q "${1}" "${BLACKLIST_FILE}" || \
echo "blacklist ${1}" >> "${BLACKLIST_FILE}"
}
unblacklist() {
sed -i "/${1}/d" "${BLACKLIST_FILE}"
}
switch_to_nvidia() {
#remove oss
if $(lsmod | grep -iq nouveau) ; then
modprobe -r nouveau || eerror "Unable to unload nouveau driver."
fi
if [ ! -f /lib/modules/$(uname -r)/video/nvidia.ko ]; then
einfo "Building evil binary nvidia driver..."
eval ${run_merge} --nodeps nvidia-drivers
fi
modprobe nvidia || NVIDIA_FAILURE=yes
if [ "${NVIDIA_FAILURE}" = "yes" ]; then
eerror "Nvidia drivers failed to load, something went wrong. Please try open source drivers."
eend 1
else
einfo "Enabling evil binary nvidia driver..."
#blacklist the open drivers
#check for nvidia in the blacklist and remove it
unblacklist nvidia
#check for nouveau in the blacklist and add it
blacklist nouveau
fi
#check for intel gpu
if $(lspci -d8086: | grep -q VGA); then
ewarn "nvidia and intel are both detected, using intel for video"
eend 0
elif [ "${NVIDIA_FAILURE}" != "yes" ]; then
/opt/bin/nvidia-xconfig
#eselect opengl set nvidia
[ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11
eselect opencl set nvidia
einfo "Enabled evil NVIDIA binary GPU driver"
eend 0
fi
}
switch_to_nouveau() {
modprobe nouveau || NOUVEAU_FAILURE=yes
if [ "${NOUVEAU_FAILURE}" = "yes" ]; then
eerror "Nouveau drivers failed to load, something went wrong. Please try the binary nvidia driver."
eend 1
else ! $(lspci -d8086: | grep -q VGA); then
einfo "Enabling open source nouveau driver..."
#blacklist the binary drivers
#check for nouveau in the blacklist and remove it
unblacklist nouveau
#check for nvidia in the blacklist and add it
blacklist nvidia
eend 0
fi
}
handle_nvidia() {
einfo "Detected: nvidia gpu, please stand by..."
if [ "${NOBINDRIVERS}" = 1 ]; then
#remove the binary driver and insert oss
if $(lsmod | grep -iq nvidia) ; then
modprobe -r nvidia || eerror "Unable to unload nvidia driver."
fi
if $(lspci -d8086: | grep -q VGA); then
ewarn "Intel GPU detected, if you wish to use nouveau please disable optimus or manually setup bumblebee."
einfo "Using Intel GPU."
eend 0
else
switch_to_nouveau
fi
else
#first we detect if the nvidia binary driver can actually support the hardware
NV_TARBALL="$(FETCHCOMMAND="false" RESUMECOMMAND="false" emerge --color=n -f nvidia-drivers --nodeps 2> /dev/zero | \
grep "SHA256 SHA512 WHIRLPOOL size ;-) ..." | awk '{print $2}')"
if [ -n "${NV_TARBALL}" ]; then
cd $(mktemp -d -t nvidia-detectXXXX)
#stolen from unpacker.eclass
exe="tail -n +$(grep -a ^skip= "$(portageq envvar DISTDIR)/${NV_TARBALL}" | cut -d= -f2) '$(portageq envvar DISTDIR)/${NV_TARBALL}'"
eval ${exe} | pixz -d | tar --no-same-owner -xf - --wildcards --no-anchored 'README.txt'
if [ -f README.txt ]; then
#stolen from debian's nvidia-detect rules file
sed -e '0,/A. Supported\|APPENDIX A: SUPPORTED/d' \
-e '0,/Appendix A. Supported\|APPENDIX A: SUPPORTED/d' \
-e '0,/^Below\|APPENDIX B/{/ 0x/s/.* 0x\([0-9a-fA-F]\{4\}\).*/10de\1/p};d' \
README.txt \
| tr a-f A-F | sort -u > list.txt
if [ -f list.txt ]; then
#stolen from nvidia-detect code
NVIDIA_VGA=$(sudo lspci -mmn -d 10de: | awk '{ gsub("\"",""); print $3 $4 }')
for pciid in ${NVIDIA_VGA^^}
do
if $(grep -q ${pciid} list.txt) ; then
switch_to_nvidia
else
eerror "NVIDIA binary driver requested but doesn't support this hardware, trying nouveau"
switch_to_nouveau
fi
done
else
eerror "Failed to extract or sort PCIIDs from NVIDIA README.txt, please report this."
eend 1
fi
else
eerror "Failed to unpack README from NVIDIA drivers, please report this."
eend 1
fi
else
eerror "Missing nvidia-drivers distfile, please download it first or run \"/etc/init.d/binary-driver-handler aufs-module\""
eerror "before making the livecd to create an aufs-module which contains the needed distfiles."
eend
fi
fi
}
handle_amd() {
einfo "Detected: amd gpu, please stand by..."
if [ "${NOBINDRIVERS}" = 1 ]; then
#remove binary and insert oss
if $(lsmod | grep -iq radeon) ; then
modprobe -r fglrx || eerror "Unable to unload fglrx."
fi
modprobe radeon || RADEON_FAILURE=yes
if [ "${RADEON_FAILURE}" = "yes" ]; then
eerror "Radeon drivers failed to load, something went wrong. Please try the binary drivers."
eend 1
else
einfo "Enabling open source radeon driver..."
#blacklist the binary driver
#check for radeon in the blacklist and remove it
unblacklist radeon
#check for fglrx in the blacklist and add it
blacklist fglrx
eend 0
fi
else
#remove oss
if $(lsmod | grep -iq radeon) ; then
modprobe -r radeon || eerror "Unable to unload radeon"
fi
if [ ! -f /lib/modules/$(uname -r)/video/fglrx.ko ]; then
einfo "Building evil binary AMD driver..."
eval ${run_merge} --nodeps ati-drivers
fi
modprobe fglrx || FGLRX_FAILURE=yes
if [ "${FGLRX_FAILURE}" = "yes" ]; then
eerror "FGLRX drivers failed to load, something went wrong. Please try open source drivers."
eend 1
else
einfo "Enabling evil binary ati driver..."
#blacklist the open drivers
#check for fglrx in the blacklist and remove it
unblacklist fglrx
#check for radeon in the blacklist and add it
blacklist radeon
/opt/bin/aticonfig --initial
#eselect opengl set ati
[ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11
eselect opencl set amd
einfo "Successfully switched to AMD binary GPU driver"
eend 0
fi
fi
}
#parse kernel commandline to see what we are doing
if grep -q nobindrivers /proc/cmdline; then
NOBINDRIVERS=1
else
NOBINDRIVERS=0
fi
if [ ! -w /mnt/cdrom/modules ]; then
#something is horribly wrong, even if it should be rw, /mnt/cdrom is remounted ro
#the lazyiest hack way to handle this is to just try and remount it rw
mount -o remount,rw /mnt/cdrom > /dev/zero 2>&1
fi
#check environment to see if we can make modules or not
if [ -w /mnt/cdrom/modules ] && [ -x /usr/sbin/makemo ]; then
run_merge="echo y | makemo --jobs=2"
else
run_merge="emerge --jobs=2"
fi
ebegin "Setting up GPU drivers requested by user, this may take a few minutes"
#check for nvidia GPU
#lspci | grep -iq "VGA.*NVIDIA"
if $(lspci -d10de: | grep -q VGA); then
handle_nvidia
#check for AMD GPU
#lspci | grep -iq "VGA.*Radeon"
elif $(lspci -d1002: | grep -q VGA); then
handle_amd
else
[ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11
eend 0
fi
eend 0
}
aufs_module() {
ebegin "Making aufs module with needed distfiles for binary drivers"
#temp dir
T="/dev/shm"
#target dir
DEST=/usr/src/pentoo/livecd/trunk/isoroot/modules
mkdir -p "${T}"/distfiles/rootfs/usr/portage/distfiles/
DISTDIR="${T}"/distfiles/ emerge -FO ati-drivers
DISTDIR="${T}"/dev/shm/distfiles/ emerge -FO nvidia-drivers
cp "${T}"/distfiles/{*[Ll]inux*,xvba*} "${T}"/distfiles/rootfs/usr/portage/distfiles
chown portage.portage -R "${T}"/distfiles/rootfs/usr/portage
mksquashfs "${T}"/distfiles/rootfs/ "${DEST}"/zdistfiles-`date "+%Y%m%d"`.lzm -comp xz -b 1048576 -Xdict-size 1048576 -no-recovery -noappend
eend 0
}

View file

@ -34,8 +34,8 @@ start() {
modprobe nvidia || NVIDIA_FAILURE=yes
if [ "${NVIDIA_FAILURE}" = "yes" ]; then
eerror "Nvidia drivers failed to load, something went wrong. Please try open source drivers."
eend 1
eerror "Nvidia binary driver failed to load, something went wrong. Falling back to open source nouveau driver..."
switch_to_nouveau
else
einfo "Enabling evil binary nvidia driver..."
#blacklist the open drivers
@ -61,8 +61,11 @@ start() {
switch_to_nouveau() {
modprobe nouveau || NOUVEAU_FAILURE=yes
if [ "${NOUVEAU_FAILURE}" = "yes" ]; then
eerror "Nouveau drivers failed to load, something went wrong. Please try the binary nvidia driver."
if [ "${NOUVEAU_FAILURE}" = "yes" ] && [ "${NVIDIA_FAILURE}" = "yes" ]; then
eerror "Both nvidia binary driver and open source nouveau both failed to load, something went wrong. Please report this"
eend 1
elif [ "${NOUVEAU_FAILURE}" = "yes" ]; then
eerror "Nouveau driver failed to load, something went wrong. Please try the binary nvidia driver."
eend 1
else
einfo "Enabling open source nouveau driver..."
@ -135,60 +138,111 @@ start() {
else
eerror "Missing nvidia-drivers distfile, please download it first or run \"/etc/init.d/binary-driver-handler aufs-module\""
eerror "before making the livecd to create an aufs-module which contains the needed distfiles."
eend
eend 1
fi
fi
}
switch_to_fglrx() {
#remove oss
if $(lsmod | grep -iq radeon) ; then
modprobe -r radeon || eerror "Unable to unload radeon"
fi
if [ ! -f /lib/modules/$(uname -r)/video/fglrx.ko ]; then
einfo "Building evil binary AMD driver..."
eval ${run_merge} --nodeps ati-drivers
fi
modprobe fglrx || FGLRX_FAILURE=yes
if [ "${FGLRX_FAILURE}" = "yes" ]; then
eerror "FGLRX binary driver failed to load, something went wrong. Falling back to open source radeon driver."
switch_to_radeon
else
einfo "Enabling evil binary ati driver..."
#blacklist the open drivers
#check for fglrx in the blacklist and remove it
unblacklist fglrx
#check for radeon in the blacklist and add it
blacklist radeon
/opt/bin/aticonfig --initial
#eselect opengl set ati
[ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11
eselect opencl set amd
einfo "Successfully switched to AMD binary GPU driver"
eend 0
fi
}
switch_to_radeon() {
#remove binary and insert oss
if $(lsmod | grep -iq radeon) ; then
modprobe -r fglrx || eerror "Unable to unload fglrx."
fi
modprobe radeon || RADEON_FAILURE=yes
if [ "${RADEON_FAILURE}" = "yes" ] && [ "${FGLRX_FAILURE}" = "yes" ]; then
eerror "Both FGLRX binary driver and open source radeon driver failed. Please report this."
eend 1
elif [ "${RADEON_FAILURE}" = "yes" ]; then
eerror "Radeon driver failed to load, something went wrong. Please try the binary drivers."
eend 1
else
einfo "Enabling open source radeon driver..."
#blacklist the binary driver
#check for radeon in the blacklist and remove it
unblacklist radeon
#check for fglrx in the blacklist and add it
blacklist fglrx
eend 0
fi
}
handle_amd() {
einfo "Detected: amd gpu, please stand by..."
if [ "${NOBINDRIVERS}" = 1 ]; then
#remove binary and insert oss
if $(lsmod | grep -iq radeon) ; then
modprobe -r fglrx || eerror "Unable to unload fglrx."
fi
modprobe radeon || RADEON_FAILURE=yes
if [ "${RADEON_FAILURE}" = "yes" ]; then
eerror "Radeon drivers failed to load, something went wrong. Please try the binary drivers."
eend 1
else
einfo "Enabling open source radeon driver..."
#blacklist the binary driver
#check for radeon in the blacklist and remove it
unblacklist radeon
#check for fglrx in the blacklist and add it
blacklist fglrx
eend 0
fi
switch_to_radeon
else
#remove oss
if $(lsmod | grep -iq radeon) ; then
modprobe -r radeon || eerror "Unable to unload radeon"
fi
if [ ! -f /lib/modules/$(uname -r)/video/fglrx.ko ]; then
einfo "Building evil binary AMD driver..."
eval ${run_merge} --nodeps ati-drivers
fi
modprobe fglrx || FGLRX_FAILURE=yes
if [ "${FGLRX_FAILURE}" = "yes" ]; then
eerror "FGLRX drivers failed to load, something went wrong. Please try open source drivers."
eend 1
if [ "$(uname -m)" = "x86_64" ]; then
amd_dcm="amd_dcm64"
elif [ "$(uname -m)" = "x86" ]; then
amd_dcm="amd_dcm32"
else
einfo "Enabling evil binary ati driver..."
#blacklist the open drivers
#check for fglrx in the blacklist and remove it
unblacklist fglrx
#check for radeon in the blacklist and add it
blacklist radeon
/opt/bin/aticonfig --initial
#eselect opengl set ati
[ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11
eselect opencl set amd
einfo "Successfully switched to AMD binary GPU driver"
eend 0
eerror "Unsupported arch."
fi
ATI_TARBALL="$(FETCHCOMMAND="false" RESUMECOMMAND="false" emerge --color=n -f ati-drivers --nodeps 2> /dev/zero | \
grep "SHA256 SHA512 WHIRLPOOL size ;-) ..." | awk '{print $2}' | head -n1)"
if [ -n "${ATI_TARBALL}" ]; then
cd $(mktemp -d -t ati-detectXXXX)
unzip -p "$(portageq envvar DISTDIR)/${ATI_TARBALL}" fglrx*/amd-driver-installer-*.run > amd-driver-installer.run
chmod +x amd-driver-installer.run
./amd-driver-installer.run --extract ati-drivers
if [ -f ati-drivers/"${amd_dcm}" ]; then
cd ati-drivers
AMD_DCM_OUTPUT="$(./${amd_dcm} 2>&1)"
if [ "${AMD_DCM_OUTPUT}" = "Supported adapter detected." ]; then
switch_to_fglrx
elif [ "${AMD_DCM_OUTPUT}" = "./${amd_dcm}: No supported adapters detected" ]; then
eerror "User requested binary fglrx but there is no supported hardware present."
eerror "Falling back to OSS radeon driver."
switch_to_radeon
else
eerror "${amd_dcm} output is not as expected, please report this."
fi
else
eerror "Failed to unpack ${amd_dcm} from ati-drivers, please report this."
eend 1
fi
else
eerror "Missing ati-drivers distfile, please download it first or run \"/etc/init.d/binary-driver-handler aufs-module\""
eerror "before making the livecd to create an aufs-module which contains the needed distfiles."
eend 1
fi
fi
}

View file

@ -33,7 +33,7 @@ pkg_setup() {
src_install() {
#/usr/sbin
newsbin "${FILESDIR}"/flushchanges-${PV}-r5 flushchanges
newsbin "${FILESDIR}"/makemo-${PVR} makemo
newsbin "${FILESDIR}"/makemo-${PV}-r7 makemo
newinitd "${FILESDIR}"/binary-driver-handler.initd-${PV}-r6 binary-driver-handler
newinitd "${FILESDIR}"/binary-driver-handler.initd-${PVR} binary-driver-handler
}