Search form

Zedboard - Modifying Your Ram Disk Image

So one thing that you will notice about your Zedboard, is that every time you reboot your Zedboard any changes you make don't stick. This is because the / directory is being loaded into Memory, and not to a hard disk or the SD-Card. This isn't a bad thing, as it allows for every fast boot times. But as you move along with your projects you may want to modify your Ram Disk Image to include different things such as your custom program code.

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

No matter what! The SD-Card is FAT32 formatted so you don't have any excuse in the world to not have the contents backed up!

If you are running on a windows machine simply just insert the SD Card into the computer and Windows will automatically mount it for you. On most modern Linux machines, a similar functionality should exist, but if it does not then it is probably under /dev/mmcblk#p# where the first # is the SD Card slot number, and the second # is the partition number.

Okay, now that you have your SD-Card backed up we can continue :D.

I will be working on Ubuntu 12.04 LTS x64 for this example.

Since my development system is in a VM, I don't have access to a SD-Card slot, so I am going to mount the SD-Card on my Zedboard and pull the image file off of it via FTP.

zynq> cd /

zynq> ls

bin etc licenses lost+found opt root sys usr

dev lib linuxrc mnt proc sbin tmp var

zynq> mkdir sdcard

zynq> mount /dev/mmcblk0p1 /sdcard

zynq> cd /sdcard

zynq> ls

BOOT.BIN backup ramdisk8M.image.gz zImage

README devicetree_ramdisk.dtb temp

Ok, I now have my SD-Card mounted. Since my root login points to / for the home directory on my FTP server I will be able to get to this folder. Now back on my Ubuntu box:

Note how I had to mount the folder as root. If you want to give access to yourself you will need to perform a chown <folder> <username> to give access.

Well that was easy! Alright, let's take our helloworld program and have it automatically run at the end of our startup script. First we need to copy our helloworld program to the ramdisk image. Let's do that. My helloworld program was in /home/zynqgeek/arm_devel/helloworld and was called simply helloworld.

Ok, so we now have our helloworld application within our ram disk image. Now we need to find our startup script in the /etc/init.d folder. The file is called rcS. Let's look at it's contents.

zynqgeek@beth:~/arm-devel/ramdisk/ram_image_mount/root$ cd ..

zynqgeek@beth:~/arm-devel/ramdisk/ram_image_mount$ cd etc

zynqgeek@beth:~/arm-devel/ramdisk/ram_image_mount/etc$ cd init.d/

zynqgeek@beth:~/arm-devel/ramdisk/ram_image_mount/etc/init.d$ ls

rcK rcS rcS.orig

zynqgeek@beth:~/arm-devel/ramdisk/ram_image_mount/etc/init.d$ cat rcS

#!/bin/sh

echo "Starting rcS..."

echo "++ Mounting filesystem"

mount -t proc none /proc

mount -t sysfs none /sys

mount -t tmpfs none /tmp

echo "++ Setting up mdev"

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev -s

mkdir -p /dev/pts

mkdir -p /dev/i2c

mount -t devpts devpts /dev/pts

echo "++ Configure static IP 192.168.1.10"

ifconfig eth0 down

ifconfig eth0 192.168.1.10 up

echo "++ Starting telnet daemon"

telnetd -l /bin/sh

echo "++ Starting http daemon"

httpd -h /var/www

echo "++ Starting ftp daemon"

tcpsvd 0:21 ftpd ftpd -w /&

echo "++ Starting dropbear (ssh) daemon"

dropbear

echo "++ Starting OLED Display"

load_oled

echo "++ Exporting LEDs & SWs"

for i in 0 1 2 3 4 5 6 7;

do

sw=$(($i+69));

led=$(($i+61));

echo $sw > /sys/class/gpio/export;

echo $led > /sys/class/gpio/export;

echo out > /sys/class/gpio/gpio$led/direction;

done;

export PATH=$PATH:/usr/local/bin

echo "rcS Complete"

zynqgeek@beth:~/arm-devel/ramdisk/ram_image_mount/etc/init.d$

Not too bad. We can see that it sets up some mounts, sets up our eth0 ethernet connection, and then loads various networking services such as our webserver and ssh server. Finally it performs some Digilent/Zedboard specific functions to fiddle with the OLED display, LED's and Switches found on the board.

We can place our application to execute right before the last line so it is executed within the script. I placed the following lines into my script file:

cd /root

./helloworld

cd /

This will move into the /root directory, execute our helloworld program, and then return the directory back to / for the first zynq> prompt.

Finally, now that we have our file added and our script updated in our image, we need to un-mount it, and re-compress it.

And finally, after you have backed-up your SD-Card contents, you can ftp back into your Zedboard and replace the ramdisk image file. First, go onto your Zedboard and list the size of the ramdisk8M.image.gz file:

zynq> cd sdcard/

zynq> lss

-sh: lss: not found

zynq> ls

BOOT.BIN backup ramdisk8M.image.gz zImage

README devicetree_ramdisk.dtb temp

zynq> ls -al

total 10433

drwxr-xr-x 4 root 0 32768 Jan 1 00:00 .

drwxr-xr-x 18 12319 300 1024 Jan 1 19:33 ..

-rwxr-xr-x 1 root 0 4317256 Jul 13 2012 BOOT.BIN

-rwxr-xr-x 1 root 0 2779 Jul 13 2012 README

drwxr-xr-x 2 root 0 32768 Aug 8 2012 backup

-rwxr-xr-x 1 root 0 5817 Jul 13 2012 devicetree_ramdisk.dtb

-rwxr-xr-x 1 root 0 3694108 Jul 13 2012 ramdisk8M.image.gz

drwxr-xr-x 3 root 0 32768 Jan 1 1980 temp

-rwxr-xr-x 1 root 0 2479640 Jul 13 2012 zImage

We can see that it is 3694108 Bytes. Now, on your development box ftp in and overwrite this file with our new image.

Thanks Zynqgeek and Joachim, this all worked well. For starters my tweaked Zedboard filesystem includes /root/*mountimage, a new /root/logo.bin OLED image, and a DHCP setup (/usr/share/udhcpc/default.script, /etc/resolv.conf, and "udhcpc -i eth0" in /etc/init.d/rcS).

Here is my simpler method:
0) Install 7zip for packing and unpacking gzip (gz) files.
1) Install ext2fsd for Windows. This lets Windows read and write to ext2/ext3 volumes.
2) Install OSFMount and use it to mount the the unpacked raw ".image" file.
3) Open the drive and edit files using Windows Explorer.
4) When done, recompress (gzip) the file and put it back on the SD card.

heyyy
first thanks a lot for this tutorial.and i tried this one a modified ramdisk8M.image.gz and and add zynqgeek.txt file in root but after rebooting linux in root directory is empty
can anyone tell me when i was wrong

This is a useful information about RAM disk management. I have observed some programs related to display on oxbridgeessays which were given an important information. But some knowledge is required to understand the program.