xref: /openbmc/u-boot/doc/README.qemu-mips (revision 3ed75b6f7415332f4f6c57b1d84ca720b803aed4)
1*3ed75b6fSDaniel SchwierzeckBy Vlad Lungu vlad.lungu@windriver.com 2007-Oct-01
2*3ed75b6fSDaniel Schwierzeck----------------------------------------
3*3ed75b6fSDaniel SchwierzeckQemu is a full system emulator. See
4*3ed75b6fSDaniel Schwierzeck
5*3ed75b6fSDaniel Schwierzeckhttp://www.nongnu.org/qemu/
6*3ed75b6fSDaniel Schwierzeck
7*3ed75b6fSDaniel SchwierzeckLimitations & comments
8*3ed75b6fSDaniel Schwierzeck----------------------
9*3ed75b6fSDaniel SchwierzeckSupports the "-M mips" configuration of qemu: serial,NE2000,IDE.
10*3ed75b6fSDaniel SchwierzeckSupports little and big endian as well as 32 bit and 64 bit.
11*3ed75b6fSDaniel SchwierzeckDerived from au1x00 with a lot of things cut out.
12*3ed75b6fSDaniel Schwierzeck
13*3ed75b6fSDaniel SchwierzeckSupports emulated flash (patch Jean-Christophe PLAGNIOL-VILLARD) with
14*3ed75b6fSDaniel Schwierzeckrecent qemu versions. When using emulated flash, launch with
15*3ed75b6fSDaniel Schwierzeck-pflash <filename> and erase mips_bios.bin.
16*3ed75b6fSDaniel Schwierzeck
17*3ed75b6fSDaniel Schwierzeck
18*3ed75b6fSDaniel Schwierzeck
19*3ed75b6fSDaniel SchwierzeckNotes for the Qemu MIPS port
20*3ed75b6fSDaniel Schwierzeck----------------------------
21*3ed75b6fSDaniel Schwierzeck
22*3ed75b6fSDaniel SchwierzeckI) Example usage:
23*3ed75b6fSDaniel Schwierzeck
24*3ed75b6fSDaniel SchwierzeckUsing u-boot.bin as ROM (replaces Qemu monitor):
25*3ed75b6fSDaniel Schwierzeck
26*3ed75b6fSDaniel Schwierzeck32 bit, big endian:
27*3ed75b6fSDaniel Schwierzeck# make qemu_mips
28*3ed75b6fSDaniel Schwierzeck# qemu-system-mips -M mips -bios u-boot.bin -nographic
29*3ed75b6fSDaniel Schwierzeck
30*3ed75b6fSDaniel Schwierzeck32 bit, little endian:
31*3ed75b6fSDaniel Schwierzeck# make qemu_mipsel
32*3ed75b6fSDaniel Schwierzeck# qemu-system-mipsel -M mips -bios u-boot.bin -nographic
33*3ed75b6fSDaniel Schwierzeck
34*3ed75b6fSDaniel Schwierzeck64 bit, big endian:
35*3ed75b6fSDaniel Schwierzeck# make qemu_mips64
36*3ed75b6fSDaniel Schwierzeck# qemu-system-mips64 -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic
37*3ed75b6fSDaniel Schwierzeck
38*3ed75b6fSDaniel Schwierzeck64 bit, little endian:
39*3ed75b6fSDaniel Schwierzeck# make qemu_mips64el
40*3ed75b6fSDaniel Schwierzeck# qemu-system-mips64el -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic
41*3ed75b6fSDaniel Schwierzeck
42*3ed75b6fSDaniel Schwierzeckor using u-boot.bin from emulated flash:
43*3ed75b6fSDaniel Schwierzeck
44*3ed75b6fSDaniel Schwierzeckif you use a qemu version after commit 4224
45*3ed75b6fSDaniel Schwierzeck
46*3ed75b6fSDaniel Schwierzeckcreate image:
47*3ed75b6fSDaniel Schwierzeck# dd of=flash bs=1k count=4k if=/dev/zero
48*3ed75b6fSDaniel Schwierzeck# dd of=flash bs=1k conv=notrunc if=u-boot.bin
49*3ed75b6fSDaniel Schwierzeckstart it (see above):
50*3ed75b6fSDaniel Schwierzeck# qemu-system-mips[64][el] [-cpu MIPS64R2-generic] -M mips -pflash flash -nographic
51*3ed75b6fSDaniel Schwierzeck
52*3ed75b6fSDaniel Schwierzeck2) Download kernel + initrd
53*3ed75b6fSDaniel Schwierzeck
54*3ed75b6fSDaniel SchwierzeckOn ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/
55*3ed75b6fSDaniel Schwierzeckyou can downland
56*3ed75b6fSDaniel Schwierzeck
57*3ed75b6fSDaniel Schwierzeck#config to build the kernel
58*3ed75b6fSDaniel Schwierzeckqemu_mips_defconfig
59*3ed75b6fSDaniel Schwierzeck#patch to fix mips interrupt init on 2.6.24.y kernel
60*3ed75b6fSDaniel Schwierzeckqemu_mips_kernel.patch
61*3ed75b6fSDaniel Schwierzeckinitrd.gz
62*3ed75b6fSDaniel Schwierzeckvmlinux
63*3ed75b6fSDaniel Schwierzeckvmlinux.bin
64*3ed75b6fSDaniel SchwierzeckSystem.map
65*3ed75b6fSDaniel Schwierzeck
66*3ed75b6fSDaniel Schwierzeck4) Generate uImage
67*3ed75b6fSDaniel Schwierzeck
68*3ed75b6fSDaniel Schwierzeck# 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
69*3ed75b6fSDaniel Schwierzeck
70*3ed75b6fSDaniel Schwierzeck5) Copy uImage to Flash
71*3ed75b6fSDaniel Schwierzeck# dd if=uImage bs=1k conv=notrunc seek=224 of=flash
72*3ed75b6fSDaniel Schwierzeck
73*3ed75b6fSDaniel Schwierzeck6) Generate Ide Disk
74*3ed75b6fSDaniel Schwierzeck
75*3ed75b6fSDaniel Schwierzeck# dd of=ide bs=1k cout=100k if=/dev/zero
76*3ed75b6fSDaniel Schwierzeck
77*3ed75b6fSDaniel Schwierzeck# sfdisk -C 261 -d ide
78*3ed75b6fSDaniel Schwierzeck# partition table of ide
79*3ed75b6fSDaniel Schwierzeckunit: sectors
80*3ed75b6fSDaniel Schwierzeck
81*3ed75b6fSDaniel Schwierzeck     ide1 : start=       63, size=    32067, Id=83
82*3ed75b6fSDaniel Schwierzeck     ide2 : start=    32130, size=    32130, Id=83
83*3ed75b6fSDaniel Schwierzeck     ide3 : start=    64260, size=  4128705, Id=83
84*3ed75b6fSDaniel Schwierzeck     ide4 : start=        0, size=        0, Id= 0
85*3ed75b6fSDaniel Schwierzeck
86*3ed75b6fSDaniel Schwierzeck7) Copy to ide
87*3ed75b6fSDaniel Schwierzeck
88*3ed75b6fSDaniel Schwierzeck# dd if=uImage bs=512 conv=notrunc seek=63 of=ide
89*3ed75b6fSDaniel Schwierzeck
90*3ed75b6fSDaniel Schwierzeck8) Generate ext2 on part 2 on Copy uImage and initrd.gz
91*3ed75b6fSDaniel Schwierzeck
92*3ed75b6fSDaniel Schwierzeck# Attached as loop device ide offset = 32130 * 512
93*3ed75b6fSDaniel Schwierzeck# losetup -o 16450560 -f ide
94*3ed75b6fSDaniel Schwierzeck# Format as ext2 ( arg2 : nb blocks)
95*3ed75b6fSDaniel Schwierzeck# mke2fs /dev/loop0 16065
96*3ed75b6fSDaniel Schwierzeck# losetup -d /dev/loop0
97*3ed75b6fSDaniel Schwierzeck# Mount and copy uImage and initrd.gz to it
98*3ed75b6fSDaniel Schwierzeck# mount -o loop,offset=16450560 -t ext2 ide /mnt
99*3ed75b6fSDaniel Schwierzeck# mkdir /mnt/boot
100*3ed75b6fSDaniel Schwierzeck# cp {initrd.gz,uImage} /mnt/boot/
101*3ed75b6fSDaniel Schwierzeck# Umount it
102*3ed75b6fSDaniel Schwierzeck# umount /mnt
103*3ed75b6fSDaniel Schwierzeck
104*3ed75b6fSDaniel Schwierzeck9) Set Environment
105*3ed75b6fSDaniel Schwierzeck
106*3ed75b6fSDaniel Schwierzecksetenv rd_start 0x80800000
107*3ed75b6fSDaniel Schwierzecksetenv rd_size 2663940
108*3ed75b6fSDaniel Schwierzecksetenv kernel BFC38000
109*3ed75b6fSDaniel Schwierzecksetenv oad_addr 80500000
110*3ed75b6fSDaniel Schwierzecksetenv load_addr2 80F00000
111*3ed75b6fSDaniel Schwierzecksetenv kernel_flash BFC38000
112*3ed75b6fSDaniel Schwierzecksetenv load_addr_hello 80200000
113*3ed75b6fSDaniel Schwierzecksetenv bootargs 'root=/dev/ram0 init=/bin/sh'
114*3ed75b6fSDaniel Schwierzecksetenv load_rd_ext2 'ide res; ext2load ide 0:2 ${rd_start} /boot/initrd.gz'
115*3ed75b6fSDaniel Schwierzecksetenv load_rd_tftp 'tftp ${rd_start} /initrd.gz'
116*3ed75b6fSDaniel Schwierzecksetenv load_kernel_hda 'ide res; diskboot ${load_addr} 0:2'
117*3ed75b6fSDaniel Schwierzecksetenv load_kernel_ext2 'ide res; ext2load ide 0:2 ${load_addr} /boot/uImage'
118*3ed75b6fSDaniel Schwierzecksetenv load_kernel_tftp 'tftp ${load_addr} /qemu_mips/uImage'
119*3ed75b6fSDaniel Schwierzecksetenv boot_ext2_ext2 'run load_rd_ext2; run load_kernel_ext2; run addmisc; bootm ${load_addr}'
120*3ed75b6fSDaniel Schwierzecksetenv boot_ext2_flash 'run load_rd_ext2; run addmisc; bootm ${kernel_flash}'
121*3ed75b6fSDaniel Schwierzecksetenv boot_ext2_hda 'run load_rd_ext2; run load_kernel_hda; run addmisc; bootm ${load_addr}'
122*3ed75b6fSDaniel Schwierzecksetenv boot_ext2_tftp 'run load_rd_ext2; run load_kernel_tftp; run addmisc; bootm ${load_addr}'
123*3ed75b6fSDaniel Schwierzecksetenv boot_tftp_hda 'run load_rd_tftp; run load_kernel_hda; run addmisc; bootm ${load_addr}'
124*3ed75b6fSDaniel Schwierzecksetenv boot_tftp_ext2 'run load_rd_tftp; run load_kernel_ext2; run addmisc; bootm ${load_addr}'
125*3ed75b6fSDaniel Schwierzecksetenv boot_tftp_flash 'run load_rd_tftp; run addmisc; bootm ${kernel_flash}'
126*3ed75b6fSDaniel Schwierzecksetenv boot_tftp_tftp 'run load_rd_tftp; run load_kernel_tftp; run addmisc; bootm ${load_addr}'
127*3ed75b6fSDaniel Schwierzecksetenv load_hello_tftp 'tftp ${load_addr_hello} /examples/hello_world.bin'
128*3ed75b6fSDaniel Schwierzecksetenv go_tftp 'run load_hello_tftp; go ${load_addr_hello}'
129*3ed75b6fSDaniel Schwierzecksetenv addmisc 'setenv bootargs ${bootargs} console=ttyS0,${baudrate} rd_start=${rd_start} rd_size=${rd_size} ethaddr=${ethaddr}'
130*3ed75b6fSDaniel Schwierzecksetenv bootcmd 'run boot_tftp_flash'
131*3ed75b6fSDaniel Schwierzeck
132*3ed75b6fSDaniel Schwierzeck10) Now you can boot from flash, ide, ide+ext2 and tfp
133*3ed75b6fSDaniel Schwierzeck
134*3ed75b6fSDaniel Schwierzeck# qemu-system-mips -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide
135*3ed75b6fSDaniel Schwierzeck
136*3ed75b6fSDaniel SchwierzeckII) How to debug U-Boot
137*3ed75b6fSDaniel Schwierzeck
138*3ed75b6fSDaniel SchwierzeckIn order to debug U-Boot you need to start qemu with gdb server support (-s)
139*3ed75b6fSDaniel Schwierzeckand waiting the connection to start the CPU (-S)
140*3ed75b6fSDaniel Schwierzeck
141*3ed75b6fSDaniel Schwierzeck# qemu-system-mips -S -s -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide
142*3ed75b6fSDaniel Schwierzeck
143*3ed75b6fSDaniel Schwierzeckin an other console you start gdb
144*3ed75b6fSDaniel Schwierzeck
145*3ed75b6fSDaniel Schwierzeck1) Debugging of U-Boot Before Relocation
146*3ed75b6fSDaniel Schwierzeck
147*3ed75b6fSDaniel SchwierzeckBefore relocation, the addresses in the ELF file can be used without any problems
148*3ed75b6fSDaniel Schwierzeckby connecting to the gdb server localhost:1234
149*3ed75b6fSDaniel Schwierzeck
150*3ed75b6fSDaniel Schwierzeck# mipsel-unknown-linux-gnu-gdb u-boot
151*3ed75b6fSDaniel SchwierzeckGNU gdb 6.6
152*3ed75b6fSDaniel SchwierzeckCopyright (C) 2006 Free Software Foundation, Inc.
153*3ed75b6fSDaniel SchwierzeckGDB is free software, covered by the GNU General Public License, and you are
154*3ed75b6fSDaniel Schwierzeckwelcome to change it and/or distribute copies of it under certain conditions.
155*3ed75b6fSDaniel SchwierzeckType "show copying" to see the conditions.
156*3ed75b6fSDaniel SchwierzeckThere is absolutely no warranty for GDB.  Type "show warranty" for details.
157*3ed75b6fSDaniel SchwierzeckThis GDB was configured as "--host=i486-linux-gnu --target=mipsel-unknown-linux-gnu"...
158*3ed75b6fSDaniel Schwierzeck(gdb)  target remote localhost:1234
159*3ed75b6fSDaniel SchwierzeckRemote debugging using localhost:1234
160*3ed75b6fSDaniel Schwierzeck_start () at start.S:64
161*3ed75b6fSDaniel Schwierzeck64		RVECENT(reset,0)	/* U-boot entry point */
162*3ed75b6fSDaniel SchwierzeckCurrent language:  auto; currently asm
163*3ed75b6fSDaniel Schwierzeck(gdb)  b board.c:289
164*3ed75b6fSDaniel SchwierzeckBreakpoint 1 at 0xbfc00cc8: file board.c, line 289.
165*3ed75b6fSDaniel Schwierzeck(gdb) c
166*3ed75b6fSDaniel SchwierzeckContinuing.
167*3ed75b6fSDaniel Schwierzeck
168*3ed75b6fSDaniel SchwierzeckBreakpoint 1, board_init_f (bootflag=<value optimized out>) at board.c:290
169*3ed75b6fSDaniel Schwierzeck290		relocate_code (addr_sp, id, addr);
170*3ed75b6fSDaniel SchwierzeckCurrent language:  auto; currently c
171*3ed75b6fSDaniel Schwierzeck(gdb) p/x addr
172*3ed75b6fSDaniel Schwierzeck$1 = 0x87fa0000
173*3ed75b6fSDaniel Schwierzeck
174*3ed75b6fSDaniel Schwierzeck2) Debugging of U-Boot After Relocation
175*3ed75b6fSDaniel Schwierzeck
176*3ed75b6fSDaniel SchwierzeckFor debugging U-Boot after relocation we need to know the address to which
177*3ed75b6fSDaniel SchwierzeckU-Boot relocates itself to 0x87fa0000 by default.
178*3ed75b6fSDaniel SchwierzeckAnd replace the symbol table to this offset.
179*3ed75b6fSDaniel Schwierzeck
180*3ed75b6fSDaniel Schwierzeck(gdb) symbol-file
181*3ed75b6fSDaniel SchwierzeckDiscard symbol table from `/private/u-boot-arm/u-boot'? (y or n) y
182*3ed75b6fSDaniel SchwierzeckError in re-setting breakpoint 1:
183*3ed75b6fSDaniel SchwierzeckNo symbol table is loaded.  Use the "file" command.
184*3ed75b6fSDaniel SchwierzeckNo symbol file now.
185*3ed75b6fSDaniel Schwierzeck(gdb) add-symbol-file u-boot 0x87fa0000
186*3ed75b6fSDaniel Schwierzeckadd symbol table from file "u-boot" at
187*3ed75b6fSDaniel Schwierzeck	.text_addr = 0x87fa0000
188*3ed75b6fSDaniel Schwierzeck(y or n) y
189*3ed75b6fSDaniel SchwierzeckReading symbols from /private/u-boot-arm/u-boot...done.
190*3ed75b6fSDaniel SchwierzeckBreakpoint 1 at 0x87fa0cc8: file board.c, line 289.
191*3ed75b6fSDaniel Schwierzeck(gdb) c
192*3ed75b6fSDaniel SchwierzeckContinuing.
193*3ed75b6fSDaniel Schwierzeck
194*3ed75b6fSDaniel SchwierzeckProgram received signal SIGINT, Interrupt.
195*3ed75b6fSDaniel Schwierzeck0xffffffff87fa0de4 in udelay (usec=<value optimized out>) at time.c:78
196*3ed75b6fSDaniel Schwierzeck78		while ((tmo - read_c0_count()) < 0x7fffffff)
197