Friday, August 29, 2014

Debian Wheezy root files system from scratch

Wanted to experiment with making a Debian Wheezy root file system for my SAMA5D3 XPLAIN from scratch.  I followed this link mostly but it is missing pieces so I used this link to fill in the gaps.

First is to install all the necessary packages (I am still using Ubuntu 14.04 via parallels on my Mac).  I think this list is a little overkill but I saw no reason to try and figure out which I did not need to install (most were already installed).

sudo apt-get install emdebian-archive-keyring
sudo apt-get update
sudo apt-get install libc6-armel-cross libc6-dev-armel-cross
sudo apt-get install binutils-arm-linux-gnueabi
sudo apt-get install gcc-4.7-arm-linux-gnueabi
sudo apt-get install g++-4.7-arm-linux-gnueabi
sudo apt-get install uboot-mkimage
sudo apt-get install libncurses5-dev
sudo apt-get install git bc curl
sudo apt-get install debootstrap dpkg-dev
sudo apt-get install qemu binfmt-support gemu-user-static dpkg-cross

With everything installed we can now start to create the root file system

mkdir armel-root
cd armel-root
debootstrap --foreign --arch armel wheezy .

This will take a bit to download all basic packages.  The next steps continue with the second stage:

cp /usr/bin/qemu-arm-static usr/bin
LC_ALL=C LANGUAGE=C LANG=C chroot . /debootstrap/debootstrap --second-stage
LC_ALL=C LANGUAGE=C LANG=C chroot . dpkg --configure -a

This setups the basic root file system, now it is just a matter of making modifications and additions to meet your needs.  First lets add a password for root:

sudo chroot . passwd

setup the package repository (/etc/apt/sources.list) which will vary based on your needs:

deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free #deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free #deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free deb http://security.debian.org/ wheezy/updates main contrib non-free #deb-src http://security.debian.org/ wheezy/updates main contrib non-free #deb http://ftp.debian.org/debian wheezy-backports main contrib non-free ##deb-src http://ftp.debian.org/debian wheezy-backports main contrib non-free #Kernel source: https://github.com/RobertCNelson deb [arch=armhf] http://repos.rcn-ee.net/debian/ wheezy main

and install some packages (these will be different depending on your needs):

LC_ALL=C LANGUAGE=C LANG=C chroot . apt-get install <package_name>

Some packages to add include python3, vim, etc.

Then you can modify different files to file your build as well.  For example:
modify etc/fstab using the following:
sudo sh -c "echo '/dev/mmcblk0p2 / auto errors=remount-ro 0 1' >> etc/fstab"
sudo sh -c "echo '/dev/mmcblk0p1 /boot/uboot auto defaults 0 2' >> etc/fstab"
and modify etc/inittab using the following:
sudo sh -c "echo 'T0:23:respawn:/sbin/getty -L ttyS0 115200 vt102' >> etc/inittab"

Or modify the network interfaces:

sudo vim etc/network/interfaces

and add the following:
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet dhcp
After this you can make other changes and modifications as needed, just remember to always use chroot . when calling an application. To copy your root file system to an SD card just do the following (where target-rootfs is top level folder and /media/rootfs is the mounted SD card):

sudo rsync -axHAX --progress target-rootfs/ /media/rootfs/

Enjoy


Wednesday, August 27, 2014

Making option.ko available to install novatel modem driver

Wanted to use a Verizon cell modem from Novatel Wireless (USB760) on my SAMA5D3 XPLAIN board. To use it I need to install a driver package as referenced in a previous post.  When I tried to install the package (dpkg -i novatel_modem_drivers_config_1.1_6.deb) I got an error saying the following "The option kernel module (option.ko) or the usbserial kernel module (usbserial.ko) must be present".

To install these you need them setup in the kernel configuration as modules (M) instead of built-ins (*).  My challenge was figuring out which option would enable option.ko.  This link and this one helped figure out that USB driver for GSM and CDMA modems enabled option.ko.  I also enabled a few more settings (or made sure they were enabled) as shown below:

Code: [Select]
Device Drivers  --->
  [*] USB support  --->
    <*>   USB Modem (CDC ACM) support
    <*>   USB Serial Converter support  --->
      [*]   USB Generic Serial Driver
      <M>   USB driver for GSM and CDMA modems
  [*] Network device support  --->
    <M>   PPP (point-to-point protocol) support
    <M>     PPP support for async serial ports


If you don't choose module (M) instead of built-in (*), then option.ko doesn't exist and the driver won't load.


Monday, August 25, 2014

SAMA5D3 XPLAINED Serial Pin Out

Here is the pinout for the serial ports running by default on the SAMA5D3 XPLAINED board (same for Yocto/Poky and Debian):

/dev/ttyS0    pins 20(tx)/21(rx) - used by Console
/dev/ttyS1    pins 18(tx)/19(rx) - available
/dev/ttyS2    pins 16(tx)/17(rx) - available
/dev/ttyS5    pins 0(rx)/1(tx) - available

Friday, August 22, 2014

OSXFUSE and SSHFS for mounting

Tried to get NFS server working on an NFS system which didn't seem that bad but could never get my Apple Mac to access it.  Always gave me an error.  So I found reference to a mounting method that just uses ssh.  This link describes the process well: https://blogs.law.harvard.edu/acts/2013/11/08/the-newbie-how-to-set-up-sshfs-on-mac-os-x/

To restate, just download and install OSXFUSE and SSHFS from http://osxfuse.github.io.  That should be all you have to install as long as you can ssh into the other computer (in my case a debian embedded device).

Now you make a directory on the server (mkdir /exports) and client side (mkdir ~/exports) for the sharing.  For example if I want to share /exports on the debian side and mount it at ~/exports on the mac side I do the following:

sshfs -p 22 root@xxx.xxx.xxx.xxx:/exports ~/exports -o auto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName

I found that sshfs doesn't work without the extra options, at least it is read only without the options.  A little experimentation and this reference, I found the only one that was really needed was defer_permissions, thus leaving me with the following:

sshfs root@xxx.xxx.xxx.xxx:/exports ~/exports -o defer_permissions

Good luck.

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.















Tuesday, August 5, 2014

Program Atmel SAMA5D3 XPLAINED with fresh linux


Got an Atmel SAMA5D3 XPLAINED board, it started and ran Yokto/Poky no problem.  Wanted to figure out how to re-install the Yocto/Poky if I messed things up before I got playing too much.  I found the demo archive for this board at http://www.at91.com/linux4sam/bin/view/Linux4SAM/GettingStarted with instructions found here.  I downloaded and unzipped the folder using Ubuntu 14.04.  In the folder there are a bunch of .sh script files, along with other things.  The one to use to recreate what was shipped is demo_linux_nandflash.sh.  Before running the script remove jumper JP5, reset using button BP2 and wait for it to boot, then replace jumper JP5 and run the script.

For this to work you need SAM BA installed as described in a previous post.  I found that with ubuntu I need more permissions so I added sudo and added the full path to first line in the script as follows:
sudo /opt/sam-ba_cdc_cdc_linux/sam-ba /dev/ttyACM0 at91sama5d3x-ek demo_linux_nandflash.tcl > logfile.log 2>&1
The script then ran without issues (it did take several minutes to complete).  One thing to note is that the serial port can change at may end up being something other than 0.  If so just modify ttyACM0 in the above script line accordingly.

Installing Atmel SAM-BA on Ubuntu 14.04

Playing with a SAMA5D3 XPLAINED board and want to setup the ATMEL SAM-BA tool so I can update the linux version.  The following steps are taking from this pdf link and this link.  You will need an Atmel account or a guest account to download the SAM-BA tool and the patch (patch7).

First install 32 bit libraries:
# sudo dpkg --add-architecture i386
# sudo apt-get update
# sudo apt-get install libxss1:i386 libxft2:i386
now add your ubuntu username to group for dialout so you can access the USB (last line checks that it got added) 
# cd ~
# sudo adduser <username> dialout
# cat /etc/group | grep dialout
now install SAM-BA either by downloading from the ATMEL website or using the ftp link below, I cd into the /opt directory before this step but you can save it wherever you like.
# wget ftp://ftp.linux4sam.org/pub/sam-ba/sam-ba_2.12.zip
unzip the file, cd into the samba_cdc_cdc_linux folder  and then patch it with the patch file (patch 7) from the website (ftp doesn't have the latest patch file).
# sudo patch -pl < patch7.diff
logout or restart to get the USB dialout to work and then execute with the following (make sure the file is executable (chmod +x samba):

Mine was saved in /opt but just put the patch where you placed it.  Also remove jumper JP5 and reset your SAMA5D3 XPLAINED board before running samba.
# sudo /opt/sam-ba_cdc_cdc_linux/sam-ba
then play as you like.