Can you write up a brief tutorial on how to get your ARM code running in QEMU to see how it runs without having to have hardware?
This is a flow I hadn't thought of, but I do agree it is definitely a useful topic to write about.
First, if you are on Windows, you will want to get your self setup with VirtualBox to bring up a 64 bit Linux environment.
Next, get QEMU downloaded and up and running.
You also need to get your ARM development environment up and running. The alternative to this is to download and install the Xilinx tools, and then do your ARM code development in the Xilinx SDK tool.
Ok, now we are to the point where, regardless of you being on Windows or Linux, you are good to go for configuration.
So let's write a simple hello world c program, cross compile it for ARM, push it to the qemu machine, and then run it.
First, let's write our hello world program. I usually use vi to edit files, however here I will just use the cat command so I can show you what the file contents are:
zynqgeek@beth:~$ cd
zynqgeek@beth:~$ mkdir arm-devel
zynqgeek@beth:~$ cd arm-devel/
zynqgeek@beth:~/arm-devel$ touch helloworld.c
zynqgeek@beth:~/arm-devel$ cat > helloworld.c
#include
int main()
{
printf("Hello World!\n");
return 0;
}
^C
Where the ^C is hitting ctrl-c on your keyboard.
Ok, now that I have my file, we need to compile it (note if this doesn't work go back and follow the instructions for setting up your development environment).
zynqgeek@beth:~$ arm-linux-gnueabi-gcc -o helloworld helloworld.c
Ok, now that we have our file, we need to get it to our qemu virtual machine. To do this, we are going to do need two command terminals open, so pop open another xterm or open another ssh session.
In terminal window 0, we are going to be running qemu - this simple will just be executing a single bash script. In terminal window 1 we will be ftp'ing our file to the qemu VM.
In terminal 0:
*navigate to where you have downloaded and uncompressed the zynq_linux.tar.gz archive*
root@sue:~# cd zynq_linux/
root@sue:~/zynq_linux# ./start_qemu.sh
...
Starting rcS...
++ Mounting filesystem
++ Setting up mdev
eth0: link up (1000/FULL)
++ Starting telnet daemon
++ Starting http daemon
++ Starting ftp daemon
++ Starting dropbear (ssh) daemon
rcS Complete
zynq>
So let's make sure that we now have our ftp server up and running on our qemu vm. We will list the processes that are running:
zynq> ps | grep "ftpd"
600 root 0:00 tcpsvd 0:21 ftpd ftpd -w /
620 root 0:00 grep ftpd
zynq>
We see two items, the first is our ftp server - woot! The second is the command of us looking for the ftp server.
Note: If do not see the server running, you can execute this command:
zynq> tcpsvd 0:21 ftpd ftpd -w /&
Cool! Now all we need to do is go to our terminal 1 and make a connection to our qemu VM ftp server and upload our helloworld program.
If you take a look in the start_qemu script, you will see that there are a number of port forwarding assignments, specifically port 21 (the tcp/ip port that ftp uses) is forwarded to port 10021 locally. So we will make our connection on that.
In terminal 1:
zynqgeek@beth:~/arm-devel# ls
helloworld helloworld.c
zynqgeek@beth:~/arm-devel# ftp localhost 10021
Connected to localhost.
220 Operation successful
Name (localhost:tim): root
230 Operation successful
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put helloworld
local: helloworld remote: helloworld
200 Operation successful
150 Ok to send data
226 Operation successful
7797 bytes sent in 0.00 secs (104304.9 kB/s)
ftp> quit
Now, jump back to terminal 0 (our qemu VM):
zynq> cd /
zynq> ls
README lib opt sys
bin licenses proc tmp
dev linuxrc ps update_qspi.sh
etc lost+found root usr
helloworld mnt sbin var
zynq> chmod +x helloworld
zynq> ./helloworld
Hello World!
zynq>
COOL!
One quick note: Don't forget the chmod +x command - the file won't have execution privileges when being created by ftpd, you need to add those.
Conclusion
So there you have it, this is a nice way to test our your arm code without needing hardware in the loop. Enjoy!
Note: Since the output of SDK is an .elf file, I am still working on the best way to get your code over from SDK to qemu. I do believe there is a how-to on this from Xilinx, but I can't find it right now - I will check again in the morning.