1*4882a593SmuzhiyunBy Vlad Lungu vlad.lungu@windriver.com 2007-Oct-01 2*4882a593Smuzhiyun---------------------------------------- 3*4882a593SmuzhiyunQemu is a full system emulator. See 4*4882a593Smuzhiyun 5*4882a593Smuzhiyunhttp://www.nongnu.org/qemu/ 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunLimitations & comments 8*4882a593Smuzhiyun---------------------- 9*4882a593SmuzhiyunSupports the "-M mips" configuration of qemu: serial,NE2000,IDE. 10*4882a593SmuzhiyunSupports little and big endian as well as 32 bit and 64 bit. 11*4882a593SmuzhiyunDerived from au1x00 with a lot of things cut out. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunSupports emulated flash (patch Jean-Christophe PLAGNIOL-VILLARD) with 14*4882a593Smuzhiyunrecent qemu versions. When using emulated flash, launch with 15*4882a593Smuzhiyun-pflash <filename> and erase mips_bios.bin. 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunNotes for the Qemu MIPS port 19*4882a593Smuzhiyun---------------------------- 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunI) Example usage: 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunUsing u-boot.bin as ROM (replaces Qemu monitor): 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun32 bit, big endian: 26*4882a593Smuzhiyun# make qemu_mips 27*4882a593Smuzhiyun# qemu-system-mips -M mips -bios u-boot.bin -nographic 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun32 bit, little endian: 30*4882a593Smuzhiyun# make qemu_mipsel 31*4882a593Smuzhiyun# qemu-system-mipsel -M mips -bios u-boot.bin -nographic 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun64 bit, big endian: 34*4882a593Smuzhiyun# make qemu_mips64 35*4882a593Smuzhiyun# qemu-system-mips64 -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun64 bit, little endian: 38*4882a593Smuzhiyun# make qemu_mips64el 39*4882a593Smuzhiyun# qemu-system-mips64el -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic 40*4882a593Smuzhiyun 41*4882a593Smuzhiyunor using u-boot.bin from emulated flash: 42*4882a593Smuzhiyun 43*4882a593Smuzhiyunif you use a qemu version after commit 4224 44*4882a593Smuzhiyun 45*4882a593Smuzhiyuncreate image: 46*4882a593Smuzhiyun# dd of=flash bs=1k count=4k if=/dev/zero 47*4882a593Smuzhiyun# dd of=flash bs=1k conv=notrunc if=u-boot.bin 48*4882a593Smuzhiyunstart it (see above): 49*4882a593Smuzhiyun# qemu-system-mips[64][el] [-cpu MIPS64R2-generic] -M mips -pflash flash -nographic 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun2) Download kernel + initrd 52*4882a593Smuzhiyun 53*4882a593SmuzhiyunOn ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/ 54*4882a593Smuzhiyunyou can downland 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun#config to build the kernel 57*4882a593Smuzhiyunqemu_mips_defconfig 58*4882a593Smuzhiyun#patch to fix mips interrupt init on 2.6.24.y kernel 59*4882a593Smuzhiyunqemu_mips_kernel.patch 60*4882a593Smuzhiyuninitrd.gz 61*4882a593Smuzhiyunvmlinux 62*4882a593Smuzhiyunvmlinux.bin 63*4882a593SmuzhiyunSystem.map 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun4) Generate uImage 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun# tools/mkimage -A mips -O linux -T kernel -C gzip -a 0x80010000 -e 0x80245650 -n "Linux 2.6.24.y" -d vmlinux.bin.gz uImage 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun5) Copy uImage to Flash 70*4882a593Smuzhiyun# dd if=uImage bs=1k conv=notrunc seek=224 of=flash 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun6) Generate Ide Disk 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun# dd of=ide bs=1k cout=100k if=/dev/zero 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun# sfdisk -C 261 -d ide 77*4882a593Smuzhiyun# partition table of ide 78*4882a593Smuzhiyununit: sectors 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun ide1 : start= 63, size= 32067, Id=83 81*4882a593Smuzhiyun ide2 : start= 32130, size= 32130, Id=83 82*4882a593Smuzhiyun ide3 : start= 64260, size= 4128705, Id=83 83*4882a593Smuzhiyun ide4 : start= 0, size= 0, Id= 0 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun7) Copy to ide 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun# dd if=uImage bs=512 conv=notrunc seek=63 of=ide 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun8) Generate ext2 on part 2 on Copy uImage and initrd.gz 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun# Attached as loop device ide offset = 32130 * 512 92*4882a593Smuzhiyun# losetup -o 16450560 -f ide 93*4882a593Smuzhiyun# Format as ext2 ( arg2 : nb blocks) 94*4882a593Smuzhiyun# mke2fs /dev/loop0 16065 95*4882a593Smuzhiyun# losetup -d /dev/loop0 96*4882a593Smuzhiyun# Mount and copy uImage and initrd.gz to it 97*4882a593Smuzhiyun# mount -o loop,offset=16450560 -t ext2 ide /mnt 98*4882a593Smuzhiyun# mkdir /mnt/boot 99*4882a593Smuzhiyun# cp {initrd.gz,uImage} /mnt/boot/ 100*4882a593Smuzhiyun# Umount it 101*4882a593Smuzhiyun# umount /mnt 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun9) Set Environment 104*4882a593Smuzhiyun 105*4882a593Smuzhiyunsetenv rd_start 0x80800000 106*4882a593Smuzhiyunsetenv rd_size 2663940 107*4882a593Smuzhiyunsetenv kernel BFC38000 108*4882a593Smuzhiyunsetenv oad_addr 80500000 109*4882a593Smuzhiyunsetenv load_addr2 80F00000 110*4882a593Smuzhiyunsetenv kernel_flash BFC38000 111*4882a593Smuzhiyunsetenv load_addr_hello 80200000 112*4882a593Smuzhiyunsetenv bootargs 'root=/dev/ram0 init=/bin/sh' 113*4882a593Smuzhiyunsetenv load_rd_ext2 'ide res; ext2load ide 0:2 ${rd_start} /boot/initrd.gz' 114*4882a593Smuzhiyunsetenv load_rd_tftp 'tftp ${rd_start} /initrd.gz' 115*4882a593Smuzhiyunsetenv load_kernel_hda 'ide res; diskboot ${load_addr} 0:2' 116*4882a593Smuzhiyunsetenv load_kernel_ext2 'ide res; ext2load ide 0:2 ${load_addr} /boot/uImage' 117*4882a593Smuzhiyunsetenv load_kernel_tftp 'tftp ${load_addr} /qemu_mips/uImage' 118*4882a593Smuzhiyunsetenv boot_ext2_ext2 'run load_rd_ext2; run load_kernel_ext2; run addmisc; bootm ${load_addr}' 119*4882a593Smuzhiyunsetenv boot_ext2_flash 'run load_rd_ext2; run addmisc; bootm ${kernel_flash}' 120*4882a593Smuzhiyunsetenv boot_ext2_hda 'run load_rd_ext2; run load_kernel_hda; run addmisc; bootm ${load_addr}' 121*4882a593Smuzhiyunsetenv boot_ext2_tftp 'run load_rd_ext2; run load_kernel_tftp; run addmisc; bootm ${load_addr}' 122*4882a593Smuzhiyunsetenv boot_tftp_hda 'run load_rd_tftp; run load_kernel_hda; run addmisc; bootm ${load_addr}' 123*4882a593Smuzhiyunsetenv boot_tftp_ext2 'run load_rd_tftp; run load_kernel_ext2; run addmisc; bootm ${load_addr}' 124*4882a593Smuzhiyunsetenv boot_tftp_flash 'run load_rd_tftp; run addmisc; bootm ${kernel_flash}' 125*4882a593Smuzhiyunsetenv boot_tftp_tftp 'run load_rd_tftp; run load_kernel_tftp; run addmisc; bootm ${load_addr}' 126*4882a593Smuzhiyunsetenv load_hello_tftp 'tftp ${load_addr_hello} /examples/hello_world.bin' 127*4882a593Smuzhiyunsetenv go_tftp 'run load_hello_tftp; go ${load_addr_hello}' 128*4882a593Smuzhiyunsetenv addmisc 'setenv bootargs ${bootargs} console=ttyS0,${baudrate} rd_start=${rd_start} rd_size=${rd_size} ethaddr=${ethaddr}' 129*4882a593Smuzhiyunsetenv bootcmd 'run boot_tftp_flash' 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun10) Now you can boot from flash, ide, ide+ext2 and tfp 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun# qemu-system-mips -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunII) How to debug U-Boot 136*4882a593Smuzhiyun 137*4882a593SmuzhiyunIn order to debug U-Boot you need to start qemu with gdb server support (-s) 138*4882a593Smuzhiyunand waiting the connection to start the CPU (-S) 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun# qemu-system-mips -S -s -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide 141*4882a593Smuzhiyun 142*4882a593Smuzhiyunin an other console you start gdb 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun1) Debugging of U-Boot Before Relocation 145*4882a593Smuzhiyun 146*4882a593SmuzhiyunBefore relocation, the addresses in the ELF file can be used without any problems 147*4882a593Smuzhiyunby connecting to the gdb server localhost:1234 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun# mipsel-unknown-linux-gnu-gdb u-boot 150*4882a593SmuzhiyunGNU gdb 6.6 151*4882a593SmuzhiyunCopyright (C) 2006 Free Software Foundation, Inc. 152*4882a593SmuzhiyunGDB is free software, covered by the GNU General Public License, and you are 153*4882a593Smuzhiyunwelcome to change it and/or distribute copies of it under certain conditions. 154*4882a593SmuzhiyunType "show copying" to see the conditions. 155*4882a593SmuzhiyunThere is absolutely no warranty for GDB. Type "show warranty" for details. 156*4882a593SmuzhiyunThis GDB was configured as "--host=i486-linux-gnu --target=mipsel-unknown-linux-gnu"... 157*4882a593Smuzhiyun(gdb) target remote localhost:1234 158*4882a593SmuzhiyunRemote debugging using localhost:1234 159*4882a593Smuzhiyun_start () at start.S:64 160*4882a593Smuzhiyun64 RVECENT(reset,0) /* U-Boot entry point */ 161*4882a593SmuzhiyunCurrent language: auto; currently asm 162*4882a593Smuzhiyun(gdb) b board.c:289 163*4882a593SmuzhiyunBreakpoint 1 at 0xbfc00cc8: file board.c, line 289. 164*4882a593Smuzhiyun(gdb) c 165*4882a593SmuzhiyunContinuing. 166*4882a593Smuzhiyun 167*4882a593SmuzhiyunBreakpoint 1, board_init_f (bootflag=<value optimized out>) at board.c:290 168*4882a593Smuzhiyun290 relocate_code (addr_sp, id, addr); 169*4882a593SmuzhiyunCurrent language: auto; currently c 170*4882a593Smuzhiyun(gdb) p/x addr 171*4882a593Smuzhiyun$1 = 0x87fa0000 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun2) Debugging of U-Boot After Relocation 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunFor debugging U-Boot after relocation we need to know the address to which 176*4882a593SmuzhiyunU-Boot relocates itself to 0x87fa0000 by default. 177*4882a593SmuzhiyunAnd replace the symbol table to this offset. 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun(gdb) symbol-file 180*4882a593SmuzhiyunDiscard symbol table from `/private/u-boot-arm/u-boot'? (y or n) y 181*4882a593SmuzhiyunError in re-setting breakpoint 1: 182*4882a593SmuzhiyunNo symbol table is loaded. Use the "file" command. 183*4882a593SmuzhiyunNo symbol file now. 184*4882a593Smuzhiyun(gdb) add-symbol-file u-boot 0x87fa0000 185*4882a593Smuzhiyunadd symbol table from file "u-boot" at 186*4882a593Smuzhiyun .text_addr = 0x87fa0000 187*4882a593Smuzhiyun(y or n) y 188*4882a593SmuzhiyunReading symbols from /private/u-boot-arm/u-boot...done. 189*4882a593SmuzhiyunBreakpoint 1 at 0x87fa0cc8: file board.c, line 289. 190*4882a593Smuzhiyun(gdb) c 191*4882a593SmuzhiyunContinuing. 192*4882a593Smuzhiyun 193*4882a593SmuzhiyunProgram received signal SIGINT, Interrupt. 194*4882a593Smuzhiyun0xffffffff87fa0de4 in udelay (usec=<value optimized out>) at time.c:78 195*4882a593Smuzhiyun78 while ((tmo - read_c0_count()) < 0x7fffffff) 196