Thursday, 12 December 2013

AMD Catalyst fglrx driver and Open Source Radeon driver: Enjoy both on Gentoo Linux- Part 2


[Visit my earlier post for part 1]

In this post we will see how to install catalyst binary driver without uninstalling the open source driver and keeping both the drivers. Catalyst fglrx legacy driver is not support by Xorg higher than 1.12 and kernel versions 3.5. Although with specific kernel patch you can go till kernel 3.8 3 3.10.32.

Note: This post is updated to use with kernel 3.10.32 catalyst fglrx support. Depending on the kernel version used for the build, you should make necessary version changes in the scripts as applicable.

Configurations used for Catalyst fglrx binary driver

x11-base/xorg-server : 1.12.4-r1
x11-drivers/xf86-input-synaptics : 1.6.4
ati-drivers : 13.1_pre897
Linux kernel  : 3.8.13 to 3.10.32
Note : Portage already had patch for kernel 3.8.x to 3.10.x and it is pulled by the ebuild when you emerge ati-driver

Configurations used for Open Source Radeon Driver

x11-base/xorg-server : 1.14.2
x11-drivers/xf86-input-synaptics : 1.7.1
Linux kernel : version 3.12 (vanilla source build)

The key point to note is while emerging Xorg for fglrx , you need to specify a separate root and emerge by ignoring all dependencies. Just enough of the core Xorg-1.12 server package and input drivers(either evdev or synaptics).

While your actual system root is untouched and unaware of the older Xorg, eselect opengl does the rest by appropriately adjusting the symlinks of opengl libraries.

Now we can proceed with the installation.

Prepare for chroot :
mkdir /mnt/GENTOO
mount /dev/sda<partition no> /mnt/GENTOO
cd /mnt/GENTOO
mount -t proc proc proc/
mount -t sysfs sys sys/
mount --rbind /dev /mnt/GENTOO/dev
mount -t devpts pts dev/pts/
chroot /mnt/GENTOO /bin/bash
Note: Now from here onwards you are in chroot environment i.e. Gentoo Linux.
source /etc/profile

Create a separate root directory for fglrx & xorg-1.12 related packages
mkdir /mnt/fglrx
Portage configuration to enable legacy driver:
echo 'x11-drivers/ati-drivers:1' >> /etc/portage/package.mask 
Now emerge xorg-server
ROOT="/mnt/fglrx" CPPFLAGS="-I/mnt/fglrx/usr/include/xorg" emerge --nodeps =x11-base/xorg-server-1.12.4 x11-drivers/xf86-input-evdev x11-drivers/xf86-input-synaptics --oneshot --ask
Point default linux symlink to the kernel source(version 3.8.13 3.10.32)
cd /usr/src/linux
ln -s /usr/src/linux-3.10.32/ linux
Now you are ready to emerge catalyst legacy drivers, it will build against kernel-3.10.32
emerge -v ati-drivers:legacy --nodeps  --oneshot --ask

Note : If you get build fail while building fgl_glxgears, it is because of some missing header files & changes in newer version of mesa ATI files. Ensure you have mesa package installed.
Catalyst fglrx doesn't build with mesa version >8. If you are on Mesa-9 most likely the build will fail with the below error message:
x11-drivers/ati-drivers-13.1_pre897::gentoo failed (compile phase):
 *   fgl_glxgears build failed
The specific snippet of code:
 *       "$(tc-getCC)" -o fgl_glxgears ${CFLAGS} ${LDFLAGS} -DUSE_GLU -I"${S}"/${FOLDER_PREFIX}usr/include fgl_glxgears.c -lGL -lGLU -lX11 -lm || die "fgl_glxgears build failed";

Workaround for this problem is to provide Mesa-8 openGL files. To build the fglrx module with Mesa 8 without downgrading your current setup follow below steps:
emerge -v =media-libs/mesa-8.0.4-r1 --fetchonly
It will download MesaLib & associated mesa-patch files in portage directory.
cd to /usr/portage/distfiles
extract include/GL folder from MesaLib-8.0.4.tar.bz2.
Backup existing Mesa library header files
mv /usr/include/GL /usr/include/GL_Original_BAK
Now copy GL header files from Mesa 8 to /usr/include/ folder

Try emerge again. This time it should successfully build the module. If the build is successful, you can restore the original Mesa openGL libraries:
mv /usr/include/GL_Original_BAK  /usr/include/GL

Generate Xorg configuration files:
/opt/bin/aticonfig -i /dev/null -o /etc/X11/fglrx.conf --initial
Add the below section for fglrx modules in fglrx.conf:
Section "Files"
        ModulePath "/mnt/fglrx/usr/lib64/xorg/modules"
        ModulePath "/usr/lib/xorg/modules"
EndSection

Xserver rc file (OpenRC based but works also with systemd )
Now we need to tweak xserverrc file, so it points to correct xserver modules when we change opengl through eselect opengl

If you are on full systemd support, you may not be having xserverrc file. If it does not exists, create it with the below content:

File: /etc/X11/xinit/xserverrc
#!/bin/sh
if lsmod | grep -q "^fglrx\b"; then
eselect opengl set ati
exec /mnt/fglrx/usr/bin/X -config fglrx.conf -nolisten tcp "$@"
else
eselect opengl set xorg-x11
exec /usr/bin/X -nolisten tcp "$@"
fi

Next you need to change the GDM scripts.

Ligthdm is the default GDM in Gentoo, change the configuration file to point to the modified xserverrc file

File /etc/lightdm/lightdm.conf:
[SeatDefaults]
xserver-command=/etc/X11/xinit/xserverrc
Module blacklisting and Grub configuration
Now we need to blacklist opensource radeon driver module to prevent it from loading, when booting with kernel 3.8. Add the following commandline parameter to grub.conf .
linux   /vmlinuz-3.8.13.gentoo resume=/dev/sda15 root=/dev/sda8 modprobe.blacklist=drm,radeon ro init=/usr/lib/systemd/systemd
initrd  /initramfs-gentoo-x86_64-3.8.13
Note : The preferred way to generate grub2 is using grub-mkconfig -o /boot/grub/grub.cfg. I usually add it manually for my setup keeping in mind other linux distro and Windows OS that I have. If you run grub-mkcofig your changes will be gone, so keep that in mind.

Now you are ready to boot into Gentoo with Catalyst fglrx driver, but before that exit from chroot environment with the below cleanup stuffs for a clean shutdown behavior!
sync
umount {proc,sys,dev/pts,dev}
sync
umount /dev/sda8

Now boot into your Gentoo system with kernel 3.8.13 fglrx enabled, if all goes well you should have the X startup & GDM login window.

Check fglrx kernel module loaded properly and you have opengl working properly:
lsmod | grep -i fglrx
Check direct rendering:
glxinfo | grep -i direct
Check fglrx gears:
fgl_glxgears

Hope this post helps if someone is trying to have both the Open Source version & Catalyst fglrx drivers together.

Share This!


Powered By Blogger · Designed By Seo Blogger Templates