Monday, August 18, 2014

Compile Debian for SAMA5D3 Xplained

This post has been updated and fixed in the following post.  This post has issues.

Working on making a Debian build for the SAMA5D3 Xplained board.  I started with this tutorial link (http://www.element14.com/community/community/designcenter/sama5d3xplained/blog/2014/04/25/debian-on-the-sama5d3-xplained) which was taken from Robert C Nelson eewiki (http://eewiki.net/display/linuxonarm/ATSAMA5D3+Xplained).

So I start by grabbing the ARM cross compiler Linaro (I put mine in /opt):

cd /opt
sudo wget -c https://releases.linaro.org/14.04/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz
sudo tar xf gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz
export CC=/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/arm-linux-gnueabihf-

Before this will work I need to download the 32 bit library libstdc++.so.6:

sudo apt-get install lib32stdc++6

Now you can check that it installed properly by checking the version of Linaro GCC:

${CC}gcc --version

which gives the following output:

arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.04 - Linaro GCC 4.8-2014.04) 4.8.3 20140401 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

So now that we have that working we want to patch U-boot so that it will work with the SAMA5D3
(I ran this from my home directory, cd ~):

git clone git://git.denx.de/u-boot.git
cd u-boot/
git checkout v2014.07 -b tmp
wget -c https://raw.githubusercontent.com/eewiki/u-boot-patches/master/v2014.07/0001-sama5d3_xplained-uEnv.txt-bootz-n-fixes.patch
patch -p1 < 0001-sama5d3_xplained-uEnv.txt-bootz-n-fixes.patch
make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} sama5d3_xplained_mmc_config
make ARCH=arm CROSS_COMPILE=${CC}

After this we build the kernel, installing dependencies first (if necessary):
Note: change back to home directory first, cd ~
sudo apt-get update
sudo apt-get install build-essential device-tree-compiler lzma lzop u-boot-tools libncurses5-dev:amd64 libncurses5:i386 libstdc++6:i386
git clone https://github.com/RobertCNelson/armv7_devel.git
cd armv7_devel/
git checkout origin/v3.16.x-sama5-armv7 -b tmp
./build_kernel.sh

Worth noting that the build script will download the Linaro again making the first step obsolete except for the check it makes of the system before running the script.

Now we acquire the root system for debian:
Change to home again cd ~
wget -c https://rcn-ee.net/deb/minfs/wheezy/debian-7.5-minimal-armhf-2014-07-07.tar.xz 
tar x -f debian-7.5-minimal-armhf-2014-07-07.tar.xz
Now we put it all on an SD card.  Insert the SD card and in my case I choose to connect it to my parallels Ubuntu.  You may wish to monitor dmesg to identify the SD card.  Mine was /dev/sdb.  The sfdisk command will change the terminal prompt which should be expected just type in the last three lines.
export DISK=/dev/sdb
sudo dd if=/dev/zero of=${DISK} bs=1M count=16
sudo sfdisk --in-order --Linux --unit M ${DISK} <<-__EOF__
1,48,0xE,*
,,,-
__EOF__
After that setup the partitions as follows:
sudo mkfs.vfat -F 16 ${DISK}1 -n boot
sudo mkfs.ext4 ${DISK}2 -L rootfs
sudo mkdir -p /media/boot/
sudo mkdir -p /media/rootfs/
sudo mount ${DISK}1 /media/boot/
sudo mount ${DISK}2 /media/rootfs/
and then create a text file uEnv.txt and place it in your base directory where you have been putting everything else
(my files are all in my home directory ~).
cd ~ vim uEnv.txt
<insert the following>
#Enable systemd in Debian Wheezy
optargs=quiet init=/lib/systemd/systemd
console=ttyS0,115200
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=ext4 rootwait fixrtc
Now we want to copy everything over to our SD card.  Your location for these files may be different depending on where you placed them in your file system.
Check the file location before running these commands.
Note: The Robert Nelson Wiki has you copying u-boot.bin instead of u-boot-spl.bin.  My tests showed that it doesn't start up without the u-boot-spl.bin.

sudo cp -v ~/u-boot/spl/u-boot-spl.bin /media/boot/BOOT.BIN
sudo cp -v ~/u-boot/u-boot.img /media/boot/
sudo cp -v ~/uEnv.txt /media/boot/
export kernel_version=3.16.1-sama5-armv7-r6
sudo tar -xvp --same-owner --numeric-owner -f ~/*-*-*-armhf-*/armhf-rootfs-*.tar -C /media/rootfs/
sudo cp -v ~/armv7_devel/deploy/${kernel_version}.zImage /media/boot/zImage
sudo mkdir -p /media/boot/dtbs/
sudo tar xvo -f ~/armv7_devel/deploy/${kernel_version}-dtbs.tar.gz -C /media/boot/dtbs/
sudo tar xv -f ~/armv7_devel/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/
Now we modify /media/rootfs/etc/fstab using the following:
sudo sh -c "echo '/dev/mmcblk0p2 / auto errors=remount-ro 0 1' >> /media/rootfs/etc/fstab"
sudo sh -c "echo '/dev/mmcblk0p1 /boot/uboot auto defaults 0 2' >> /media/rootfs/etc/fstab"
and we modify /media/rootfs/etc/inittab using the following:
sudo sh -c "echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt102' >> /media/rootfs/etc/inittab"

Now we want to modify the network interfaces:

sudo vim /media/rootfs/etc/network/interfaces

and add the following:
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet dhcp
After that just unmount the SD card with the following:
sync
sudo umount /media/boot
sudo umount /media/rootfs
And then remove the SD card, power down the SAMA5D3 Xplained and pull jumper JP5.  Then insert the SD card into the SAMA5D3 and power up.  User the USB or a serial cable to connect to the SAMA5D3 board and watch it boot up.  login and password is root.















No comments:

Post a Comment