Updating Ubuntu 12.04 LTS kernel to 3.15.8 with latest ddbridge DVB drivers

# Updating Ubuntu 12.04 LTS kernel to 3.15.8 with latest ddbridge DVB drivers

# Download vanilla kernel with basic ubuntu config
mkdir -p /opt/src/3.15.8-dvb
cd /opt/src/3.15.8-dvb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.15.8-utopic/linux-headers-3.15.8-031508-generic_3.15.8-031508.201407311933_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.15.8-utopic/linux-headers-3.15.8-031508_3.15.8-031508.201407311933_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.15.8-utopic/linux-image-3.15.8-031508-generic_3.15.8-031508.201407311933_amd64.deb
dpkg -i *.deb

# Reboot now

# DVB driver part
mkdir -p /opt/src/3.15.8-dvb/ddbridge
cd /opt/src/3.15.8-dvb/ddbridge

# Download branch with ddbridge drivers
hg clone http://linuxtv.org/hg/~endriss/media_build_experimental
cd media_build_experimental
hg update -r 329

# Fresh kernel DVB support
sed -i.bak linux/Makefile \
    -e's|^LATEST_TAR :=.*|LATEST_TAR := http://linuxtv.org/downloads/drivers/linux-media-2014-07-29-27dcb00.tar.bz2|g' \
    -e's|^LATEST_TAR_MD5 :=.*|LATEST_TAR_MD5 := http://linuxtv.org/downloads/drivers/linux-media-2014-07-29-27dcb00.tar.bz2.md5|g'

# Download
make download

# Allow fuzzy warm feeling while patching since we want to watch the world burn
sed -i.bak experimental/add-drivers \
    -e's|patch -d..|patch -d.. -l -F3|g'

# Unpack and download more
make untar

# More fixups
mv backports/api_version.patch backports/api_version.patch.bak
touch backports/api_version.patch

# Even more
mv backports/pr_fmt.patch backports/pr_fmt.patch.bak
touch backports/pr_fmt.patch

# smp_mb__after_atomic & friends are only present in 3.16 yet it's not possible to compile these pos DVB drivers with newer than 3.15
sed -i.bak -e's|smp_mb__after_atomic|smp_mb__after_clear_bit|g' linux/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
sed -i.bak -e's|smp_mb__after_atomic|smp_mb__after_clear_bit|g' linux/sound/pci/bt87x.c

# Finally time to compile

# And install in unlikely case that it worked
make install

# Reboot since it's not possible to unload and reload ddbridge driver without crashing kernel