FAQ Hero Banner

The Question and the Answer

Modify your boot image on your ZedBoard
Modify your boot image on your ZedBoard
Modify your boot image on your ZedBoard
Question:

How do I change my boot image on my Zedboard?

Answer:

I had a few comments come in about suggestions on how to change your boot image on your ZedBoard - as not everyone has a Linux machine to use.

Thanks to one of my readers 'J' for putting together a small reference and sending it to me.  Thanks J!

First, let's get our ZedBoard up and running.  I am assuming that you have your default SD-Card image on the FAT32 formated SD-Card that came with your Zedboard.  Stop everything and ...

FIRST!!! BACK UP YOUR SD-CARD CONTENTS!!!!

Ok, now that you have done this, we can continue.

Boot your ZedBoard to the prompt.  Type the mount command and see what is currently mounted on the system:

zynq> mount
none on /proc type proc (0)
none on /sys type sysfs (0)
none on /tmp type tmpfs (0)
devpts on /dev/pts type devpts (0)
zynq>

We can see that the SD-Card is not yet mounted (it is at /dev/mmcblk0 in my case).

So let's create a folder to mount our SD-Card to:

zynq> cd /
zynq> mkdir sdcard
zynq> ls
bin         lib         lost+found  proc        sdcard      usr
dev         licenses    mnt         root        sys         var
etc         linuxrc     opt         sbin        tmp
zynq>

Great!  Now we have a place to mount the SD-Card to.  Use the mount command to mount the SD-Card.

zynq> mount /dev/mmcblk0p1 /sdcard
zynq> cd sdcard/
zynq> ls
BOOT.BIN                devicetree_ramdisk.dtb  zImage
README                  ramdisk8M.image.gz
zynq>

Now that we have the SD-Card mounted, we can uncompress our ramdisk image, mount it, change it, re-compress it, and then unmount our SD-Card.  Not too bad right?

First, we'll move our ramdisk image to our tmp directory, unzip it, and then mount it so we can change it:

zynq> cp /sdcard/ramdisk8M.image.gz /tmp/
zynq> gunzip /tmp/ramdisk8M.image.gz
zynq> mount -o loop /tmp/ramdisk8M.image /mnt/
[  605.300000] EXT4-fs (loop0): couldn't mount as ext3 due to feature incompatibilities
[  605.350000] EXT4-fs (loop0): mounting ext2 file system using the ext4 subsystem
[  605.350000] EXT4-fs (loop0): warning: mounting unchecked fs, running e2fsck is recommended
[  605.360000] EXT4-fs (loop0): mounted filesystem without journal. Opts: (null)
zynq> cd /mnt
zynq> ls
bin         lib         lost+found  proc        sys         var
dev         licenses    mnt         root        tmp
etc         linuxrc     opt         sbin        usr
zynq>

We can see that we have our ram disk image mounted, and we can not edit it.  Here I will simply just create a file in the /root directory called zynqgeek.txt with some text in it to prove that we have changed the contents of the ram disk image.

zynq> cd /mnt/root/
zynq> ls
logo.bin
zynq> touch zynqgeek.txt
zynq> cat > zynqgeek.txt
The ZynqGeek Blog Rocks!
^C
zynq> ls -al
total 4
drwxr-xr-x    2 12319    300           1024 Jan  1 00:11 .
drwxr-xr-x   17 12319    300           1024 Jul 12  2012 ..
-rw-r--r--    1 root     0              512 Jul 12  2012 logo.bin
-rw-r--r--    1 root     0               25 Jan  1 00:11 zynqgeek.txt
zynq> cat zynqgeek.txt
The ZynqGeek Blog Rocks!
zynq>

We can see that the file has been created, it has a size of 25 Bytes, and it has the text "The ZynqGeek Blog Rocks!" :D.

Ok, now that we have mad our modifications we need to unmount the image, re-compress it, then unmount our SD-Card.  Then we can reboot the board and see our modified ramdisk image after boot.

zynq> umount -l /mnt
zynq> gzip -9 /tmp/ramdisk8M.image
zynq> mv /tmp/ramdisk8M.image.gz /sdcard/
zynq> umount -l /sdcard/
zynq> mount
none on /proc type proc (0)
none on /sys type sysfs (0)
none on /tmp type tmpfs (0)
devpts on /dev/pts type devpts (0)
zynq>

Note that the gzip command may take a few seconds (took 14 for me).  Now reboot your board, and take a look in the /root directory ...

zynq> cd /root
zynq> ls
logo.bin      zynqgeek.txt
zynq> cat zynqgeek.txt
The ZynqGeek Blog Rocks!
zynq>

Cool!

So with the suggestions by J, I put together a nice little script and placed it up on GitHub.  This script will mount your SD-Card to /sdcard, and your ram disk image to /ramdisk, as well as unmount them.  There are two scripts:

mount_sd_and_ramdisk
umount_sd_and_ramdisk

The first will try and create the /sdcard and /ramdisk folders - if they are already there they will just display an error.

Download the scripts here:

https://github.com/zynqgeek/sdcard_ramdisk_mount_util.git

I'll post a link where the scripts will be hosted outside of github so you can pull them down with wget as soon as I get them up to a page.

I have copied the mount, and unmount scripts onto the root of the SD-Card.  Here is how to copy them into your /usr/bin directory in your ramdisk image and run them.

zynq> mount /dev/mmcblk0 /sdcard
zynq> cp /sdcard/ramdisk8M.image.gz /tmp
zynq> gunzip /tmp/ramdisk8M.image.gz
zynq> mount /tmp/ramdisk8M.image /mnt
zynq> cp /sdcard/mount_sd_and_ramdisk /mnt/usr/bin/
zynq> cp /sdcard/umount_sd_and_ramdisk /mnt/usr/bin/
zynq> umount -l /mnt/
zynq> gzip -9 /tmp/ramdisk8M.image
zynq> mv /tmp/ramdisk8M.image.gz /sdcard/
zynq> umount /sdcard/

 -- reboot board --

zynq> mount
none on /proc type proc (0)
none on /sys type sysfs (0)
none on /tmp type tmpfs (0)
devpts on /dev/pts type devpts (0)
zynq> mount_sd_and_ramdisk
Creating Directories, mounting SD-Card, and Ram Disk Image
[  675.600000] EXT4-fs (loop0): couldn't mount as ext3 due to feature incompatibilities
[  675.650000] EXT4-fs (loop0): mounting ext2 file system using the ext4 subsystem
[  675.650000] EXT4-fs (loop0): warning: mounting unchecked fs, running e2fsck is recommended
[  675.660000] EXT4-fs (loop0): mounted filesystem without journal. Opts: (null)
none on /proc type proc (0)
none on /sys type sysfs (0)
none on /tmp type tmpfs (0)
devpts on /dev/pts type devpts (0)
/dev/mmcblk0p1 on /sdcard type vfat (0)
/dev/loop0 on /ramdisk type ext2 (loop)
zynq> umount_sd_and_ramdisk
Unmounting Ram Disk ...
... Done
Compressing Ram Disk Image ... this make take a few seconds ...
... done.
Making Copy of Existing Ram Disk Image ...
... Done
Overwriting Existing Compressed Image on SD-Card ...
... Done
Unmounting SD-Card ...
... Done
zynq>

Modify your boot image on your ZedBoard