Thursday, February 25, 2016

Building latest bluez with pbuilder

Wanted to learn how to use pbuilder to create bluez (which I am calling 5.37) from the latest code.

First I have Mint Debian Betsy (http://www.linuxmint.com/download_lmde.php) running under vmware fusion.

To get pbuilder installed I followed this blog (https://jodal.no/2015/03/08/building-arm-debs-with-pbuilder/). So first you create .pbuilderrc and put it in the home directory. One challenge I found is that sudo would require that .pbuilderrc in /root as well. So put it in both or I read to just put it in /etc/pbuilderrc. I simplified the file since I only care about arm:
#!/bin/sh

set -e

if [ "$OS" == "debian" ]; then
MIRRORSITE="http://ftp.debian.org/debian/"
COMPONENTS="main contrib non-free"
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
"--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
: ${DIST:="jessie"}
: ${ARCH:="armhf"}
else
echo "Unknown OS: $OS"
exit 1
fi

if [ "$DIST" == "" ]; then
echo "DIST is not set"
exit 1
fi

if [ "$ARCH" == "" ]; then
echo "ARCH is not set"
exit 1
fi

NAME="$OS-$DIST-$ARCH"

if [ "$ARCH" == "armel" ] && [ "$(dpkg --print-architecture)" != "armel" ]; then
DEBOOTSTRAP="qemu-debootstrap"
fi
if [ "$ARCH" == "armhf" ] && [ "$(dpkg --print-architecture)" != "armhf" ]; then
DEBOOTSTRAP="qemu-debootstrap"
fi

DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--arch=$ARCH")
BASETGZ="/var/cache/pbuilder/$NAME-base.tgz"
DISTRIBUTION="$DIST"
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
BUILDPLACE="/var/cache/pbuilder/build"
#HOOKDIR="/var/cache/pbuilder/hook.d/"
With that in place, install the required debian packages:
apt-get install pbuilder qemu-user-static
And I only need the debian keyring:
apt-get install debian-archive-keyring
Which is installed here:
/usr/share/keyrings/
I also ran the following to get the bluez dependencies:
apt-get build-dep bluez
Now create the virtual image:
OS=debian DIST=jessie ARCH=armhf pbuilder --create
The image is created here:
/var/cache/pbuilder
With pbuilder ready I can now prepare bluez by first grabbing the latest git (will create a bluez folder in the current directory):
git clone git://git.kernel.org/pub/scm/bluetooth/bluez.git
We want to get the 5.37 release so we checkout as follows:
git checkout tags/5.37
Now some debian package pieces are needed and can be retrieved from http://http.debian.net/debian/pool/main/b/bluez/:
wget http://http.debian.net/debian/pool/main/b/bluez/bluez_5.36.orig.tar.xz
wget http://http.debian.net/debian/pool/main/b/bluez/bluez_5.36-1.dsc
wget http://http.debian.net/debian/pool/main/b/bluez/bluez_5.36-1.debian.tar.xz
now uncompress the debian folder and place in the bluez folder
tar xJvf bluez_5.36-1.debian.tar.xz -C ./bluez
Now we want to create a new number for our purposes, which we be 5.37. To get pbuilder to work, change the version of the downloaded files from 5.36 to 5.37:
cp bluez_5.36.orig.tar.xz bluez_5.37.orig.tar.xz
cp bluez_5.36-1.dsc bluez_5.37-1.dsc
Now use an editor (like vim) to modify the changelog in bluez/debian to a new version.
vim ./debian/changelog
It is important that the change match the previous entries and there is no leading spaces. Something like this will suffice:
bluez (5.37-1) unstable; urgency=medium

  * Update to 5.37. 

-- Name email Sat, 07 Jan 2016 11:47:02 +0900
The changes made in the latest bluez have to be made into a patch, quilt is the tool to do this properly. However, for a quick and dirty method just run the build (want to be in the bluez folder when running this command):
cd bluez
OS=debian DIST=jessie ARCH=armhf pdebuild --debbuildopts "-j4 -b -uc -us"
Which results in an error similar to the following:
dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/bluez_5.37-1.diff.XW1beT
dpkg-source: info: you can integrate the local changes with dpkg-source --commit
dpkg-buildpackage: error: dpkg-source -b bluez gave error exit status 2
So copy the differences into a patch and add it to patch series file as follows:
cp /tmp/bluez_5.37-1.diff.XW1beT debian/patches/latestmods.patch
echo latestmods.patch >> debian/patches/series
Now run the command again and wait:
OS=debian DIST=jessie ARCH=armhf pdebuild --debbuildopts "-j4 -b -uc -us"
The end result will be the creation of a bunch of debian bluez packages in /var/cache/pbuilder/debian-jessie-armhf/result:
bluetooth_5.37-1_all.deb
bluez-cups_5.37-1_armhf.deb
bluez-dbg_5.37-1_armhf.deb
bluez-hcidump_5.37-1_armhf.deb
bluez-obexd_5.37-1_armhf.deb
bluez-test-scripts_5.37-1_all.deb
bluez_5.37-1_armhf.deb
libbluetooth-dev_5.37-1_armhf.deb
libbluetooth3-dbg_5.37-1_armhf.deb
libbluetooth3_5.37-1_armhf.deb

Wednesday, February 10, 2016

Building Bluez 5.37 on Debian Jessie

Working on an Emtrion sbc-sama5d36 ARM Cortex-A5 setup using Debian Jessie. With Emtrion support, Elbe was used to build the base debian system. Then a bunch of build packages were added to the build (any easy way to add these packages is the apt-get build-dep bluez):
build-essential perl flex bison python3 autoconf automake dh-autoreconf autotools-dev debhelper dh-make dh-systemd devscripts fakeroot check libdbus-glib-1-dev libglib2.0-dev libcap-ng-dev libudev-dev libreadline-dev libical-dev file git lintian patch patchutils pbuilder vim
Once booted I was then ready to build bluez 5.37, first step was to clone the bluez git repository:
git clone git://git.kernel.org/pub/scm/bluetooth/bluez.git
Change into the bluez folder:
cd bluez
We want to get the 5.37 release so we checkout as follows:
git checkout tags/5.37
Then get the debian folder from the previous version of bluez, this is what is used to build bluez and is placed in the bluez folder created by the git clone.

Thus, get the compressed tar file:
wget http://http.debian.net/debian/pool/main/b/bluez/bluez_5.36-1.debian.tar.xz
and then uncompress and place in the bluez folder
tar xJvf bluez_5.36-1.debian.tar.xz -C ./
now use your favorite editor (like vim) to modify the changelog to a new version.
vim ./debian/changelog
It is important that you match the previous entries and there is no leading spaces. Something like this will suffice:
bluez (5.37-1) unstable; urgency=medium

  * Update to 5.37. 

-- Name  Sat, 07 Jan 2016 11:47:02 +0900
I also had to modify the rules file to avoid a dpkg-shlibdeps error. To do this just modify the rules file.
vim ./debian/rules
By adding the following in the %: section as follows (where the dh $@ --with systemd,autoreconf already exists) :
%:
 dh $@ --with systemd,autoreconf

override_dh_shlibdeps:
 dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
Note, you want a tab not a space before dh_shlibdeps.
Now just run buildpackage command and wait forever.
dpkg-buildpackage -j4 -b -uc -us
The end result will be the creation of a bunch of debian bluez packages in the directory above bluez:
bluetooth_5.37-1_all.deb
bluez-cups_5.37-1_armhf.deb
bluez-dbg_5.37-1_armhf.deb
bluez-hcidump_5.37-1_armhf.deb
bluez-obexd_5.37-1_armhf.deb
bluez-test-scripts_5.37-1_all.deb
bluez_5.37-1_armhf.deb
libbluetooth-dev_5.37-1_armhf.deb
libbluetooth3-dbg_5.37-1_armhf.deb
libbluetooth3_5.37-1_armhf.deb