Install Debian on Terasic DE0-NANO-SoC

Terasic DE0-NANO-SoC (NANO-SoC) comes with the Yacto Linux on microSD Card as ready to go.  Since we have been using Debian for analytical instrument control software and firmware, it worth to take time to swich it to Debian Linux.  Here is the complete walk-through for install Debian Jessie onto NANO-SoC.

1. Prepare cross compile host

Setup Debian Jessie (amd64) on Oracle VirtualBox on Windows 8.1 (64bit), and setup MultiArch Cross Tools according to Debian CrossTools (armhf) 
Xfce4 desktop environment was used for operation by disabled USB automount feature by unchecking "Enable Volume Management" option on File Manager Preferences.

2. Make minimal Debian root filesystem (fs)

Make minimal ARM Debian root fs on amd64 Debian host according to "Debian ARM kernel install (Helio SOC FPGA)

Command walk through:

sudo apt-get install qemu-user-static debootstrap binfmt-support 
targetdir=arm-linux-gnueabihf-rootfs 
distro=jessie 
mkdir $targetdir 
sudo debootstrap --arch=armhf --foreign $distro $targetdir 
sudo cp /usr/bin/qemu-arm-static $targetdir/usr/bin/ 
sudo cp /etc/resolv.conf $targetdir/etc
sudo chroot $targetdir
distro=jessie
export LANG=C
/debootstrap/debootstrap --second-stage 
cat <<EOT > /etc/apt/sources.list
deb http://ftp.jaist.ac.jp/debian/ jessie main
deb-src http://ftp.jaist.ac.jp/debian/ jessie main
deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main
​EOT
apt-get update 
apt-get install locales dialog 
dpkg-reconfigure locales
apt-get install openssh-server ntpdate
echo <<EOT > /etc/network/interfaces
allow-hotplug eth0
iface eth0 inet dhcp
EOT
passwd <set root passwd>
echo nano > /etc/hostname
exit

3. Cross compile Linux kernel

tar xvf linux-4.4.6.tar.xz 
cd linux-4.4.6
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 socfpga_defconfig

Run following command, and then make sure "CONFIG_FHANDLE" is enabled that located on "Generic setup --->" "open by fhandle syscalls" otherwise, you have no login prompt after boot.  Disable CAN network support (due it it get me hand up during boot the target kernel).

References: http://unix.stackexchange.com/questions/169935/no-login-prompt-on-serial-consolehttps://github.com/wtfuzz/socfpga-debian


make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

Kernel cross build.

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 zImage
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 all

Mount microSD Card, which is a full image copy of NANO-SoC original microSD card, which has initial FPGA configuration and u-boot binary.

sudo mkdir /a
sudo mount /dev/sdb1 /a
sudo cp arch/arm/boot/zImage /a
sudo cp arch/arm/boot/dts/socfpga_cyclone5_de0_sockit.dtb /a/socfpga.dtb
sudo umount /a
sudo mkfs.ext3 /dev/sdb2
sudo mount /dev/sdb2 /mnt
cd $targetdir
sudo tar cf - . | (sudo tar xvf - -C /mnt)
cd ~/linux-4.4.6
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 modules_install INSTALL_MOD_PATH=/mnt

sudo chroot /mnt
passwd <set root password for this instance>

That's it.

See also: http://xillybus.com/tutorials/u-boot-image-altera-soc

English

Comments

Default FPGA configuration comes with DE0-Nano-SoC from Terasic blocks debugging a software access to LED region.  So that I've figured the way to generate the de0-nano-soc.rbf file for /dev/mmcblk0p1 partition (vFAT).

Walkthrough:

Open Quartus Prime Lite Edition, and then open "Convert Programing File" dialog from File menu.

Programming file type: ["Raw Binary File (.rbf)"]

File name: [de0_nano_soc.rbf] 

Clock "SOF Data" on the table at the bottom of this dialog, and then press "Add File..." button.  Address .sof file to be converted and select it.

Select .sof filename that was added, and press "Properties" button, and then check "compression".

If no "compression" is checked at last step, MSEL switch on the DE0-Nano-SoC board should be changed to: 1: ON-2:ON-3:ON-4:ON-5:ON

See: http://rocketboards.org/foswiki/view/Documentation/GSRD131ProgrammingFPGA

Download DE0_Nano_SoC_Linux_Console_3.3.zip from Terrasic web site, and inflate it.  Rename DE0_Nano_SoC_Linux_Console.img to de0_nano_soc_debian8.img.

And then, follow the procedure;

sudo mount -o rw,loop,offset=$((2121728*512)) de0_nano_soc-debian8.img /a
sudo losetup -f -o $((14336*512)) de0_nano_soc-debian8.img
sudo losetup -a

/dev/loop0: [2049]:3186115 (/home/toshi/src/de0-nano-soc/de0_nano_soc-debian8.img), offset 1086324736
/dev/loop1: [2049]:3186115 (/home/toshi/src/de0-nano-soc/de0_nano_soc-debian8.img), offset 7340032

 

sudo mkfs.ext3 /dev/loop1
sudo mount -o rw,loop,offset=$((14336*512)) de0_nano_soc-debian8.img /mnt

cd arm-linux-gnueabihf-rootfs
sudo tar cf - . | sudo tar xvf - -C /mnt

cd ../linux-4.4.7
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 modules_install INSTALL_MOD_PATH=/mnt
sudo cp arch/arm/boot/dts/socfpga_cyclone5_de0_sockit.dtb /a/socfpga.dtb
sudo cp arch/arm/boot/zImage /a
sudo /path/to/soc_system.rbf /a/de0_nano_soc.rbf

When I create a new partition by mkfs.ext4 that partition failed on mount.  Require following commands for disable huge_file feature.

tune2fs -O ^huge_file /dev/mmcblk0p4
fsck /dev/mmcblk0p4

sudo losetup --show -f -P de0.img 
/dev/loop0
ls /dev/loop0*

/dev/loop0  /dev/loop0p1  /dev/loop0p2  /dev/loop0p3

 

Created de0_nano_soc sd image file by above procedure is being fit to 2GB size with 1.2GB Linux root partition.  If you flush the image onto larger size of SD Card, you can enlarge root file system by following procedure;

1. Boot up de0_nano_soc with newly created SD Card.

2. Expand root filesystem: -- The procedure blow might be completely destroy your data.  Do it at your own risk --

sudo fdisk /dev/mmcblk0
... snip fdisk start message...
Device         Boot   Start     End Sectors  Size Id Type
/dev/mmcblk0p1        14336 1062911 1048576  512M  b W95 FAT32
/dev/mmcblk0p2      1062912 3799447 2736536  1.3G 83 Linux [Start sector# should not be changed]
/dev/mmcblk0p3         2048    4095    2048    1M a2 unknown

Partition table entries are not in disk order.

Command (m for help): d
Partition number (1-3, default 3): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2,4, default 2): 2
First sector (4096-7821311, default 4096): 1062912 [CAUTION: This value should be the same with oritinal Start sector# above]
Last sector, +sectors or +size{K,M,G,T,P} (1062912-7821311, default 7821311): 

Created a new partition 2 of type 'Linux' and of size 3.2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

Reboot Linux, then

sudo resize2fs /dev/mmcblk0p2

Reboot again, and make sure file system was enlarged.

Good luck.

User login