This article illustrates how to build an Embedded Debian Linux bootable SD card for SAMA5D3 Xplained board.
- Linux PC (tested on Lubuntu 13.10 installed in VirtualBox)
- ARM cross toolchain
- AT91Bootstrap for SC card
- Linux Kernel + Device Tree
- 4GB+ SD Card and SAMA5D3 Xplained to test
1. Cross toolchain
You could build cross toolchain using buildroot or simply install:
$sudo apt-get install emdebian-archive-keyring
$sudo apt-get install libc6-armel-cross libc6-dev-armel-cross
$sudo apt-get install binutils-arm-linux-gnueabi
$sudo apt-get install gcc-arm-linux-gnueabi
$sudo apt-get install g++-arm-linux-gnueabi
$sudo apt-get install u-boot-tools
$sudo apt-get install libncurses5-dev
You could also use gnueabihf:
$sudo apt-get install gcc-arm-linux-gnueabihf
$sudo apt-get install g++-arm-linux-gnueabihf
2. AT91Bootstrap
more details
$git clone git://github.com/linux4sam/at91bootstrap.git
$cd at91bootstrap/
$make mrproper
$make sama5d3_xplainedsd_linux_zimage_dt_defconfig
$#make menuconfig #if you want to change something
$make CROSS_COMPILE=arm-linux-gnueabi-
$cd ..
3.Kernel
Get kernel source and compile details
$git clone git://github.com/linux4sam/linux-at91.git
$cd linux-at91/
$ls arch/arm/configs/+(at91|sam)*
$make ARCH=arm sama5d3_xplained_defconfig
$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage
$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- dtbs
$make modules ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
$make modules_install INSTALL_MOD_PATH=./modules ARCH=arm
$cd ..
4.Build an Embedded Debian root filesystem
Install tools:
sudo apt-get install multistrap
sudo apt-get install qemu
sudo apt-get install qemu-user-static
sudo apt-get install binfmt-support
sudo apt-get install dpkg-cross
Then:
$mkdir emdebian
$cd emdebian
Create file multistrap.conf and paste this inside:
[General]
arch=armhf
directory=target-rootfs
cleanup=true
noauth=true
unpack=true
debootstrap=Emdebian Net Utils Php Python
aptsources=Emdebian
[Emdebian]
packages=apt
source=http://www.emdebian.org/grip
keyring=emdebian-archive-keyring
suite=wheezy-grip
[Net]
#Basic packages to enable the networking
packages=netbase net-tools ethtool udev iproute iputils-ping ifupdown isc-dhcp-client ssh
source=http://www.emdebian.org/grip
[Utils]
#General purpose utilities
packages=locales adduser nano less wget vim rsyslog dialog sudo
source=http://www.emdebian.org/grip
[Php]
packages=php5-cgi lighttpd
source=http://ftp.debian.org/debian
suite=wheezy
#Python language
[Python]
packages=python python-serial
source=http://www.emdebian.org/grip
then run:
$sudo multistrap -f multistrap.conf
$sudo cp /usr/bin/qemu-arm-static target-rootfs/usr/bin
$sudo LC_ALL=C LANGUAGE=C LANG=C chroot target-rootfs dpkg --configure -a
Create file fsupdate.sh
#!/bin/sh
TARGET_ROOTFS_DIR="target-rootfs"
#Directories used to mount some SD card partitions
echo "Create mount directories"
mkdir $TARGET_ROOTFS_DIR/media/kernel
#Set the target board hostname
filename=$TARGET_ROOTFS_DIR/etc/hostname
echo Creating $filename
echo SAMA5D3_Xplained > $filename
#Set the default name server
filename=$TARGET_ROOTFS_DIR/etc/resolv.conf
echo Creating $filename
echo nameserver 8.8.4.4 > $filename
echo nameserver 8.8.8.8 >> $filename
#Set the default network interfaces
filename=$TARGET_ROOTFS_DIR/etc/network/interfaces
echo Updating $filename
echo allow-hotplug eth0 >> $filename
echo iface eth0 inet dhcp >> $filename
#Set the eth0 interface MAC address
echo hwaddress ether 12:34:56:78:90:12 >> $filename
#Set a terminal to the debug port
filename=$TARGET_ROOTFS_DIR/etc/inittab
echo Updating $filename
echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $filename
#Set how to mount the SD partitions
filename=$TARGET_ROOTFS_DIR/etc/fstab
echo Creating $filename
echo /dev/mmcblk0p1 /media/mmc_p1 vfat noatime 0 1 > $filename
echo /dev/mmcblk0p2 / ext4 noatime 0 1 >> $filename
echo proc /proc proc defaults 0 0 >> $filename
#Add the standard Debian repositories.
filename=$TARGET_ROOTFS_DIR/etc/apt/sources.list
echo Creating $filename
echo deb http://ftp.uk.debian.org/debian wheezy main > $filename
echo deb http://security.debian.org/ wheezy/updates main >> $filename
Then run and enter root password:
$sudo chmod +x fsupdate.sh
$sudo ./fsupdate.sh
$sudo chroot target-rootfs passwd
4. Format SD
details are here
Run: System -> Administration -> Gparted
- select sd card device /dev/sdb or similar (It is very important to select correct device!!!)
- unmount
- delete
- new partition:
- New size: 64MB
- File system: FAT16
- Label: kernel
- newnev partition:
- Leave size default
- File system: EXT4
- Label: rootfs
- Apply changes
- Close program GParted
Remove SD card from computer, wait 5 seconds and insert again.
SD card should be mounted as:
/media/$USER/KERNEL
/media/$USER/rootfs
where $USER will be replaced with your user name.
Copy Kernel AT91Bootstrap and Device tree file to SD card:
cp at91bootstrap/binaries/sama5d3_xplained-sdcardboot-linux-zimage-dt-3.6.2.bin /media/$USER/kernel/BOOT.BIN
cp linux-at91/arch/arm/boot/at91-sama5d3_xplained.dtb /media/$USER/kernel/
cp linux-at91/arch/arm/boot/zImage /media/$USER/kernel/
Copy root filesystem and kernel modules to SD card:
sudo rsync -axHAX --progress embedian/target-rootfs/ /media/$USER/rootfs/
sudo rsync -avc linux-at91/modules/lib/. /media/$USER/rootfs/lib/.
sync
Unmount SD card and remove from PC and inset into SAMA5D3 Xplained.
There ia also prebuild SD card image.
References:
Very good information. Thank you for this!
However: Is there some steps missing when it comes to formating the SD card?
The reason I wonder is because I downloaded your prebuild and flashed with win32 diskimager and it worked fine. I then removed your bootstrap (BOOT.BIN) and put my own in and it worked (my bootstrap was loaded as expected). The problem comes when I setup anouther SD-card with GParted. This SD-card is not detected by the MCU (or at least the BOOT.bin isn’t).
Note that I use GParded via a virtualbox ubuntu (client) on a windows7 (host) but I can not see why that should make a difference in this case…
Thanks!
LikeLike
After many hours I found out what the problem was… The housing for the SD card is bad… I have 3 SD cards I work with and when ever I did a test it didnt work… but when I tried shifting the SD card and pressing reset some times it worked. Either I have a bad example or the housing for the SD card is not very good… The future will tell….
LikeLiked by 1 person
I have similar problem with SD card once or twice and I also suspect SD card holder.
LikeLike
A SD card is specified with up to 250ms power up delay before ready and the ACT8865 on the Xplained only generate a reset for about 64ms. I suspect that sometimes it’s not long enough.
LikeLiked by 1 person
Thank you, the best tutorial!
But, how to do for boot Debian on board flash ?
LikeLike
It should work if you simple replace existing filesystem in flash with Debian filesystem (it should be minimal).
Problem could be amount of flash memory on the board. – I just testing Debian with X11 – lxde and there is 1.2GB of files on sd card. X11 work just fine on SAMA5D3 xplained.
LikeLike
Thank you very much. It is a great tutorial. And I have a small problem at the last step. When I run the rsync -axHAX –progress…. There is an error:
xuez@ubuntu:~$ sudo rsync -axHAX –progress embedian/target-rootfs /media/$USER/rootfs/
sending incremental file list
rsync: change_dir “/home/xuez//embedian” failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]
I tried to Google it and didn’t find anything that really helpful. So I came here seeking for help.
Thank you
Zhihao
LikeLike
rsync is fast file copy tool. (copy files to sd-card)
Usage: rsync [OPTION…] [destination]
In your case you should check the location of sd card partition mount. ‘Automount’ location is different in different linux distribution.
I usually use mount comand which print all mount devices with mount location…..
Thank you
Borut
LikeLike