Original article written by Bacon Xu. Translation to English and revision by Saeed Ehteshamifar.

(contact us, bacon's email: baconxu@gmail.com;  SAeeD's mail: salpha.2004@gmail.com)

This is a step-by-step guide to compile QEMU for Mini2440 under Fedora 14, configure network options of QEMU and use TFTP to transfer files to QEMU.

This tutorial was written for i686 (That is, ordinary PCs) computers and have some prerequisites:
0. All commands are executed as root user and must be so.
1. Git which is obtainable by this command:
$ yum install git
1. QEMU for Mini2440. You can clone it from the official repository:
$ git clone git://repo.or.cz/qemu/mini2440.git QEMU
3. U-Boot built for Mini2440. (The binary form is available in this post's files. please download .)
After getting the source code for QEMU, open file "net.c" and change it as follows:
static int launch_script(const char *setup_script, const char *ifname, int fd)
{
    int pid, status;
    char *args[4]; /* bacon modified */
    char **parg;
    
    /* try to launch network script */
    pid = fork();
    if (pid >= 0) {
        if (pid == 0) {
        char path[20];/* bacon add */
        int open_max = sysconf (_SC_OPEN_MAX), i;
        for (i = 0; i < open_max; i++)
            if (i != STDIN_FILENO &&
            i != STDOUT_FILENO &&
            i != STDERR_FILENO &&
            i != fd)
            close(i);
    
        parg = args;
        strcpy(path, "/bin/bash");/*bacon add*/
    
        *parg++ = (char *)path; /*bacon add*/
        *parg++ = (char *)setup_script;
        *parg++ = (char *)ifname;
        *parg++ = NULL;
    
        status = execv(path, args);/*bacon add*/
        fprintf(stderr, "error:%d %d %d %s %s/n", status, errno, ENOEXEC, setup_script, ifname);/*bacon add for debug.*/
        _exit(1);
        }
        while (waitpid(pid, &status, 0) != pid);
        if (!WIFEXITED(status) ||
        WEXITSTATUS(status) != 0) {
        fprintf(stderr, "%s: could not launch network script/n",
            setup_script);
        return -1;
        }
    }
    return 0;
}
This change is to avoid a bug in networking of QEMU. After that, build QEMU:
$ cd QEMU
$ ./configure -target-list=arm-softmmu
$ make
(Obviously gcc is necessary!)
Then create two empty files:
/etc/QEMU-ifup
/etc/QEMU-ifdown
Now, you need a package named "uml-utilities" which is available in the official repository:
$ yum install uml_utilities.i686
After installing this package, create a TAP module and configure it with the address known to U-Boot as the 'serverip':
$ tunctl -u root
$ ifconfig tap0 192.168.1.8/24 up
Note that 192.168.1.8 is the 'serverip' known to U-Boot. You can see what address is known as 'serverip' to U-Boot by "printenv" command in U-Boot command line.
In order to make sure your TAP device was successfully installed, check the output of command 'ifconfig' in your Fedora's shell. You must see something like:
...
tap0      Link encap:Ethernet  HWaddr e2:0d:44:51:db:0f  
          inet addr:192.168.1.8  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::e00d:44ff:fe51:db0f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:16 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
...
Place the u-boot.bin, attached to this post in your QEMU folder. (
Now you can run QEMU:
$ cd QEMU
$ ./mini2440/mini2440_start.sh
Note: In mini2440_start.sh, make sure that your command to run QEMU-system-arm has following commented options:
    -net nic,vlan=0 : This line and the line below are required for correct functionality of QEMU's network card.
    -net tap,vlan=0,ifname=tap0 : Note that ifname=tap0. That is the TAP device we've just created. The numbers for TAP devices should be the same.
To make sure everything is fine, ping 'serverip' that is 192.168.1.8 in this case, from U-Boot's command line:
Mini2440# ping 192.168.1.8
dm9000 i/o: 0x20000300, id: 0x90000a46
MAC: 0a:1b:2c:3d:4e:5f
host 192.168.1.8 is alive
Now you are only one step beyond: You need a TFTP server.
Install it by following command:
$ yum install tftp-server.i686
After tftp-server was installed, edit this file: /etc/xinetd.d/tftp (This file stores configuration of TFTP server in it.)
service tftp
{
    disable    = no # This line was changed from yes to no in order to enable TFTP server.
    ...
    server_args        = -s /home/saeed/tftp # This is the directory where I must place the files I want to transfer using TFTP. Change it accordingly.
    ...
}
You may restart your computer now for changes to make effect.
After the system was restarted, you must create the TAP device again:
$ tunctl -u root
$ ifconfig tap0 192.168.1.8/24 up
And run QEMU:
$ cd QEMU
$ ./mini2440/mini2440_start.sh
Ping serverip again to make sure everything is right:
Mini2440# ping 192.168.1.8
dm9000 i/o: 0x20000300, id: 0x90000a46
MAC: 0a:1b:2c:3d:4e:5f
host 192.168.1.8 is alive
Now you can use TFTP to transfer files to Mini2440, running on QEMU:
Mini2440# tftp 0x32000000 my-file
Note that my-file should be placed in /home/saeed/tftp, that is the directory we setted as server_arg in /etc/xinetd.d/tftp earlier.
Again, note that Mini2440 SRAM space is mapped to 0x30000000 to 0x34000000 and you must enter an address in between in order to use TFTP. (Exclude bounds, that is 0x30000000 and 0x34000000.)
If everything is alright, you may see:
Mini2440# tftp 0x32000000 my-file
dm9000 i/o: 0x20000300, id: 0x90000a46
MAC: 0a:1b:2c:3d:4e:5f
TFTP from server 192.168.1.8; our IP address is 192.168.1.6
Filename 'my-file'.
Load address: 0x32000000
Loading: #########
done
Now your file has been placed in Mini2440's SRAM, at address 0x32000000.
That's it! You've successfully built QEMU, configured its NIC, and transferred your file to QEMU using TFTP. Congratulations!