Run Linaro Ubuntu Desktop on ZED AP SoC Board – Step-By-Step Guide

ZED board is currently shipped with Linux kernel with a RAM disk file systems.
However, it is fairly simple to get a desktop version of Linaro Ubuntu running on it.
In this blog, I will give you step-by-step instructions with pictures to get Linaro Ubuntu running on your ZED board with the kernel image in the SD card.

Things You Need

A. A Linux Machine

You need a Linux machine to format disks, copy files, etc. You cannot do these under Windows because Windows does not support EXT filesystem, and cannot understand special files (e.g. device files, link files, etc.) which only exists for Unix-like systems. Any Linux distributions, such as Fedora, CentOS, RHEL, Ubuntu, ArchLinux, etc.) can satisfy our needs.

B. Linaro Ubuntu File System Image

You can view Linaro Ubuntu as a Ubuntu distribution specifically for ARM-based processors. You can obtained the file system image from linaro 12.09. The file system is about 500ish MB. The current built is called: linaro-precise-ubuntu-desktop-20120923-436.tar.gz

C. SD Card Image (containing Kernel, BOOT.BIN, etc.)

Before we move on to modify the SD card, it is recommended to store the files on the SD card to some place. However, you can also obtain those files from Digilent Website: Out-of-Box SD Card Image .

Idea for Running Desktop

To run desktop linux, you just need to swap the file system from RAMDISK to linaro file system image. The ramdisk gets loaded up into the SDRAM by bootloader, and the memory address is passed to kernel via boot args (defined in device tree file: devicetree_ramdisk.dtb). However, the file system of Ubuntu is above 500MB. So, we cannot load it as the way we deal with RAMDISK (which is usually around 4~8 MB). As a result, we are going to make a second partition on SD card (3GB), make a root filesystem on it, and point it as the root filesystem in dtb file.

Step-by-Step Instructions

A. Repartition the SD Card

1. Plug in your SD Card to your Linux machine. Some distribution will automatically mount the partition on SD Card. So, you need to umount the automounted partitions first, before we repartition the disk.

On my computer, when I insert the SD card, the device node created for the SD card on my machine is /dev/sdd:

[tinghui.wang@DIGILENT_LINUX ~]$ df 
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
470166952 316061992 130221800 71% /
tmpfs 3988440 976 3987464 1% /dev/shm
/dev/sda1 495844 65557 404687 14% /boot
/dev/sdd1 3862528 10268 3852260 1% /media/ZED_BOOT

Umount the pre-mounted SD Card Partition:

[tinghui.wang@DIGILENT_LINUX ~]$ sudo umount /media/ZED_BOOT/
[tinghui.wang@DIGILENT_LINUX ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
470166952 316062016 130221776 71% /
tmpfs 3988440 976 3987464 1% /dev/shm
/dev/sda1 495844 65557 404687 14% /boot
[tinghui.wang@DIGILENT_LINUX ~]$

2. Now we will delete the original 4G FAT Partition and create two partitions: first one is 1GB FAT for booting files, and second one is 3GB EXT4 for root file system. The partition utility we will use is fdisk.

Open the SD card device using fdisk, and use command p to print current partition table on SD card.

[tinghui.wang@DIGILENT_LINUX ~]$ sudo fdisk /dev/sdd
[sudo] password for tinghui.wang:

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdd: 3965 MB, 3965190144 bytes
228 heads, 2 sectors/track, 16983 cylinders
Units = cylinders of 456 * 512 = 233472 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00047708

Device Boot Start End Blocks Id System
/dev/sdd1 1 16978 3870720 b W95 FAT32

Type command d to delete the partition. As there is only one partition on SD card, it will be deleted automatically.

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdd: 3965 MB, 3965190144 bytes
228 heads, 2 sectors/track, 16983 cylinders
Units = cylinders of 456 * 512 = 233472 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00047708

Device Boot Start End Blocks Id System

Now it’s time for us to create new partitions. We will create
a. A primary partition, Partition Number 1, Start from first Cylinder, Size of 1GB;
b. A primary partition, Partition Number 2, Start from next available Cylinder, Take rest of the available space on SD Card.
Command n stands for “New Partitions”.

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-16983, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-16983, default 16983): +1G

Command (m for help): p

Disk /dev/sdd: 3965 MB, 3965190144 bytes
228 heads, 2 sectors/track, 16983 cylinders
Units = cylinders of 456 * 512 = 233472 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00047708

Device Boot Start End Blocks Id System
/dev/sdd1 1 4600 1048799 83 Linux

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (4601-16983, default 4601):
Using default value 4601
Last cylinder, +cylinders or +size{K,M,G} (4601-16983, default 16983):
Using default value 16983

Command (m for help): p

Disk /dev/sdd: 3965 MB, 3965190144 bytes
228 heads, 2 sectors/track, 16983 cylinders
Units = cylinders of 456 * 512 = 233472 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00047708

Device Boot Start End Blocks Id System
/dev/sdd1 1 4600 1048799 83 Linux
/dev/sdd2 4601 16983 2823324 83 Linux

So far, we have finished creating two new partitions. We write our changes back to SD card using command w and fdisk will quit automatically after disk is sychronized.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[tinghui.wang@DIGILENT_LINUX ~]$
B. Creating File Systems

Next Step is to create file systems. We need to format the first partition to FAT with label “ZED_BOOT”, and Second one EXT4 with label “ROOT_FS”. The utility we use for formatting partitions is makefs.

[tinghui.wang@DIGILENT_LINUX ~]$ sudo mkfs -t vfat -n ZED_BOOT /dev/sdd1
mkfs.vfat 3.0.9 (31 Jan 2010)
[tinghui.wang@DIGILENT_LINUX ~]$ sudo mkfs -t ext4 -L ROOT_FS /dev/sdd2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=ROOT_FS
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
176704 inodes, 705831 blocks
35291 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=725614592
22 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[tinghui.wang@DIGILENT_LINUX ~]$

Now, unplug the SD Card from your computer and plug it in again. In most Linux distributions, both partitions will be mounted to /media/ZED_BOOT and /media/ROOT_FS automatically. If not, you need to create two folders manually and mount them manually.

C. Creating Linaro Ubuntu Root Filesystem

Personally, I would like to create a folder named linaro under /tmp and copy the zipped linaro image there.

[tinghui.wang@DIGILENT_LINUX ~]$ mkdir -p /tmp/linaro
[tinghui.wang@DIGILENT_LINUX ~]$ sudo cp /home/tinghui.wang/Downloads/linaro-precise-ubuntu-desktop-20120923-436.tar.gz /tmp/linaro/
[tinghui.wang@DIGILENT_LINUX ~]$ cd /tmp/linaro/
[tinghui.wang@DIGILENT_LINUX linaro]$ ls
32mlinaro-precise-ubuntu-desktop-20120923-436.tar.gz
[tinghui.wang@DIGILENT_LINUX linaro]$

Unpack the disk image using tar. (Part of the log is omitted for brevity).

[tinghui.wang@DIGILENT_LINUX linaro]$ tar zxvf linaro-precise-ubuntu-desktop-20120923-436.tar.gz
binary/
binary/md5sum.txt
binary/boot/
binary/boot/filesystem.dir/
binary/boot/filesystem.dir/.disk/
binary/boot/filesystem.dir/.disk/casper-uuid
binary/boot/filesystem.dir/var/
...
binary/boot/filesystem.dir/srv/
binary/boot/filesystem.dir/opt/
binary/boot/filesystem.dir/media/
binary/boot/filesystem.dir/tmp/
[tinghui.wang@DIGILENT_LINUX linaro]$ ls
binary linaro-precise-ubuntu-desktop-20120923-436.tar.gz

After unpacking the disk image, the root filesystem lies at /tmp/linaro/binary/boot/filesystem.dir. So the next step to do is to copy the root filesystem into the second partition of our SD Card, mounted already to /media/ROOT_FS. A lot of files in the root filesystem are special files with special attributes, I would recommend to use rsync to do the copy, which keeps the attibutes for every file. It takes a while to copy the file to SD card, basically depended on your SD card speed. (Part of the log is omitted for brevity).

[tinghui.wang@DIGILENT_LINUX binary]$ cd binary/boot/filesystem.dir/
[tinghui.wang@DIGILENT_LINUX filesystem.dir]$ pwd
/tmp/linaro/binary/boot/filesystem.dir
[tinghui.wang@DIGILENT_LINUX filesystem.dir]$ sudo rsync -a --progress ./ /media/ROOT_FS/
sending incremental file list
./
.disk/
.disk/casper-uuid
37 100% 0.00kB/s 0:00:00 (xfer#1, to-check=1039/1061)
bin/
bin/auto-root-login
36 100% 0.78kB/s 0:00:00 (xfer#2, to-check=1152/1175)
bin/bash
605140 100% 12.02MB/s 0:00:00 (xfer#4, to-check=1150/1175)
bin/bunzip2
22112 100% 449.87kB/s 0:00:00 (xfer#5, to-check=1149/1175)
...
var/spool/cups/
var/spool/cups/tmp/
var/spool/plymouth/
var/spool/rsyslog/
var/tmp/

sent 1331510996 bytes received 1327420 bytes 3738677.18 bytes/sec
total size is 1325555569 speedup is 0.99
[tinghui.wang@DIGILENT_LINUX filesystem.dir]$

To make sure all the files have been sychronized to SD card, we need to unmount the /media/ROOT_FS before we unplug the SD card. It may take several minutes to get everything synchronized onto SD Card.

[tinghui.wang@DIGILENT_LINUX filesystem.dir]$ sudo umount /media/ROOT_FS/
D. Getting images files back to FAT partition

We are almost done. To boot up the whole system, we need to get the original SD card files back to FAT partition. As mentioned before, we can get them from the Out-of-Box Design available on Digilent Website.

[tinghui.wang@DIGILENT_LINUX ~]$ cp ~/Downloads/ZedBoard_OOB_Design/sd_image/* /media/ZED_BOOT/ -rfv
`/home/tinghui.wang/Downloads/ZedBoard_OOB_Design/sd_image/BOOT.BIN' -> `/media/ZED_BOOT/BOOT.BIN'
`/home/tinghui.wang/Downloads/ZedBoard_OOB_Design/sd_image/devicetree_ramdisk.dtb' -> `/media/ZED_BOOT/devicetree_ramdisk.dtb'
`/home/tinghui.wang/Downloads/ZedBoard_OOB_Design/sd_image/ramdisk8M.image.gz' -> `/media/ZED_BOOT/ramdisk8M.image.gz'
`/home/tinghui.wang/Downloads/ZedBoard_OOB_Design/sd_image/README' -> `/media/ZED_BOOT/README'
`/home/tinghui.wang/Downloads/ZedBoard_OOB_Design/sd_image/zImage' -> `/media/ZED_BOOT/zImage'
[tinghui.wang@DIGILENT_LINUX ~]$

You need to change the bootargs defined in the DTB to let the kernel use the second partition of SD card as root file system. To make your life easier, I precompiled a dtb file for you available at: devicetree_linaro.dtb

[tinghui.wang@DIGILENT_LINUX ~]$ cp ~/Downloads/* /media/ZED_BOOT/devicetree_linaro.dtb -rfv
[tinghui.wang@DIGILENT_LINUX ~]$
E. Boot up Your Desktop Ubuntu

Insert your SD Card into your ZED Board, connect a monitor to the ZED Board with an HDMI cable, connect the UART port to your computer, open a hyper-terminal for it (115200, 8 bit, 1 stop bit, no parity, no flow control) and boot it up. However, automatically, the boot loader (U-Boot) will still look for ramdisk by default. So, you need to stop the autoboot by pressing a key during the 3-second count down, and type command run sdboot_linaro to boot Linaro Ubuntu Desktop up.

U-Boot 2012.04.01-00297-gc319bf9-dirty (Sep 13 2012 - 09:30:49)

DRAM: 512 MiB
WARNING: Caches not enabled
MMC: SDHCI: 0
Using default environment

In: serial
Out: serial
Err: serial
Net: zynq_gem
Hit any key to stop autoboot: 0
zed-boot> run sdboot_linaro
Advertisements

14 thoughts on “Run Linaro Ubuntu Desktop on ZED AP SoC Board – Step-By-Step Guide

  1. Steven,

    1. When I create file system by executing sudo mkfs -t ext4 -L ROOT_FS /dev/sdp2, I get mkfs.ext4: No such file or directory. What is wrong?

    2. In the SD repartioning, should SD partition 2 be primary or extended?

    2. What OS are you using?

    Thanks

    • Hi, Karl,

      1. it seems you do not have ext4 support installed on your system. You can use ext3 instead. It does not matter.

      2. Make second partition “Primary”

      3. I am using CentOS 5.6 x64. But it should work on most distributions.

      Regards,
      Steve

  2. Hi Steve. Very nice recipe, thanks. I followed a very similar one you posted elsewhere and it worked fine.
    I have a couple of questions. In this article you mention the “boot sdboot_linaro” but I don’t see where that is specified. I’m guessing it is a boot parameter string inside the U-BOOT environment variables somewhere?
    In the version of this that I got to work, I left the ramdisk8M on the boot partition, it gets read too, but then the linaro filesystem (as pointed to by the .dtb file) gets used. I am wondering if I can delete the ramdisk8M and use something like ‘setenv’ in the u-boot menu to create a sdboot_linaro command and then set bootcmd to be sdboot_linaro so it boots automatically? What would the sdboot_linar string be?
    Thanks

    • Well, the environment variable of U-Boot are created at compilation time.
      I have sent you the tutorial, and you may follow that to see what’s the difference between ramdisk version and linaro version.
      In the pre-built image on the SD card, sdboot_linaro will read a different dts file, which sets the root file system to be the second partition on SD card,
      while sdboot set the root file system to the memory location where ramdisk8M is copied to.

  3. Thank you Steven, great tutorial!

    could you share the devicetree_linaro.dts you used to generate your devicetree_linaro.dtb so to understand how to modify the boot args in order to have linaro working on a sd partition?

    • Hi, Roberto,

      In the DTS file arch/arm/boot/dts/digilent-zed.dts
      48 chosen {
      49 /* bootargs = “console=ttyPS0,115200 root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1”; */
      50 bootargs = “console=ttyPS0,115200 root=/dev/ram rw initrd=0x800000,8M init=/init earlyprintk rootwait devtmpfs.mount=1”;
      51 linux,stdout-path = “/axi@0/serial@e0001000”;
      52 };

      line 49 is for RAMDISK
      and line 50 to 51 is for Linaro File System.

      You may refer to the Linux Tutorial available at http://www.digilentinc.com/ZedBoard/
      And the kernel repository: https://github.com/Digilent/linux-digilent

  4. Hi Steven,
    I think 49 is for Linaro and 50 is for Ramdisk;
    anyway I cannot bootstrap;
    when I launch “run sdboot_linaro” the systems executes mmcinfo and then:

    reading uImage

    2458168 bytes read
    reading devicetree_linaro.dtb

    9652 bytes read
    ## Starting application at 0x00008000 …

    and then it stops; it never proceeds further this point

    I suppose the problem could be in the u-boot, where the zynq_zed.h shows:

    “sdboot_linaro=echo Copying Linux from SD to RAM…;” \
    “mmcinfo;” \
    “fatload mmc 0 0x8000 uImage;” \
    “fatload mmc 0 0x1000000 devicetree_linaro.dtb;” \
    “go 0x8000” \
    “sdboot=echo version 1.0.1: loading 64M ramdisk size 0x4000000 Copying Linux from SD to RAM…;” \
    “mmcinfo;” \
    “fatload mmc 0 0x3000000 uImage;” \
    “fatload mmc 0 0x2A00000 devicetree.dtb;” \
    “fatload mmc 0 0x4000000 uramdisk64M.image.gz;” \
    “bootm 0x3000000 0x4000000 0x2A00000”

    or could be in the SDCARD, that when I format it, the first partition starts from cylinder 2048 instead of 1

    could you please check your zynq_zed.h?
    Thank you very much,

    Roberto

    • the problem is in my kernel, I’m working with linux-3.6-digilent;
      I recompiled the kernel generating the uImage and the zImage:
      with uImage I can boot the fs in the ram, but when I boot Linaro with zImage I obtain:

      ##Starting application at 0x00008000 …
      Uncompressing Linux… done, booting the kernel.
      Error: unrecognized/unsupported machine ID (r1=0x1fb6ded4).
      Available machine support:
      ID (hex) NAME
      00000d32 Xilinx Zynq Platform
      00000d32 Xilinx Zynq Platform
      Please check your kernel config and/or bootloader.

      any idea how to fix this?

  5. Pingback: Yet Another Guide to Running Linaro Ubuntu Desktop on the Xilinx Zynq ZedBoard | FPGA CPU News

  6. Hi Steven,

    thank you for your well-written tutorial.

    I just wanted to inform you that the link to your devicetree_linaro.dtb is broken.

    Regards,
    Rainer

  7. Hello everyone,

    I can’t download the devicetree_linaro.dtb file
    the link seems to be broken!

    Can anyone who already downloaded the file send me a working link?

    Thanks …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s