blob: 529a908b55b2e4454a08c17fa2698e6159848602 [file] [log] [blame]
Bin Meng475d4bd2019-07-18 00:34:17 -07001.. SPDX-License-Identifier: GPL-2.0+
2.. sectionauthor:: Vlad Lungu <vlad.lungu@windriver.com>
3
4QEMU MIPS
5=========
6
7Qemu is a full system emulator. See http://www.nongnu.org/qemu/
8
9Limitations & comments
10----------------------
11Supports the "-M mips" configuration of qemu: serial,NE2000,IDE.
12Supports little and big endian as well as 32 bit and 64 bit.
13Derived from au1x00 with a lot of things cut out.
14
15Supports emulated flash (patch Jean-Christophe PLAGNIOL-VILLARD) with
16recent qemu versions. When using emulated flash, launch with
17-pflash <filename> and erase mips_bios.bin.
18
19
20Notes for the Qemu MIPS port
21----------------------------
22
23Example usage
24^^^^^^^^^^^^^
25
26Using u-boot.bin as ROM (replaces Qemu monitor):
27
2832 bit, big endian::
29
30 # make qemu_mips
31 # qemu-system-mips -M mips -bios u-boot.bin -nographic
32
3332 bit, little endian::
34
35 # make qemu_mipsel
36 # qemu-system-mipsel -M mips -bios u-boot.bin -nographic
37
3864 bit, big endian::
39
40 # make qemu_mips64
41 # qemu-system-mips64 -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic
42
4364 bit, little endian::
44
45 # make qemu_mips64el
46 # qemu-system-mips64el -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic
47
48or using u-boot.bin from emulated flash:
49
50if you use a qemu version after commit 4224
51
52.. code-block:: none
53
54 create image:
55 # dd of=flash bs=1k count=4k if=/dev/zero
56 # dd of=flash bs=1k conv=notrunc if=u-boot.bin
57 start it (see above):
58 # qemu-system-mips[64][el] [-cpu MIPS64R2-generic] -M mips -pflash flash -nographic
59
60Download kernel + initrd
61^^^^^^^^^^^^^^^^^^^^^^^^
62
63On ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/
64you can downland::
65
66 #config to build the kernel
67 qemu_mips_defconfig
68 #patch to fix mips interrupt init on 2.6.24.y kernel
69 qemu_mips_kernel.patch
70 initrd.gz
71 vmlinux
72 vmlinux.bin
73 System.map
74
75Generate uImage
76^^^^^^^^^^^^^^^
77
78.. code-block:: none
79
80 # 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
81
82Copy uImage to Flash
83^^^^^^^^^^^^^^^^^^^^
84
85.. code-block:: none
86
87 # dd if=uImage bs=1k conv=notrunc seek=224 of=flash
88
89Generate Ide Disk
90^^^^^^^^^^^^^^^^^
91
92.. code-block:: none
93
94 # dd of=ide bs=1k cout=100k if=/dev/zero
95
96 # sfdisk -C 261 -d ide
97 # partition table of ide
98 unit: sectors
99
100 ide1 : start= 63, size= 32067, Id=83
101 ide2 : start= 32130, size= 32130, Id=83
102 ide3 : start= 64260, size= 4128705, Id=83
103 ide4 : start= 0, size= 0, Id= 0
104
105Copy to ide
106^^^^^^^^^^^
107
108.. code-block:: none
109
110 # dd if=uImage bs=512 conv=notrunc seek=63 of=ide
111
112Generate ext2 on part 2 on Copy uImage and initrd.gz
113^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114
115.. code-block:: none
116
117 # Attached as loop device ide offset = 32130 * 512
118 # losetup -o 16450560 -f ide
119 # Format as ext2 ( arg2 : nb blocks)
120 # mke2fs /dev/loop0 16065
121 # losetup -d /dev/loop0
122 # Mount and copy uImage and initrd.gz to it
123 # mount -o loop,offset=16450560 -t ext2 ide /mnt
124 # mkdir /mnt/boot
125 # cp {initrd.gz,uImage} /mnt/boot/
126 # Umount it
127 # umount /mnt
128
129Set Environment
130^^^^^^^^^^^^^^^
131
132.. code-block:: none
133
134 setenv rd_start 0x80800000
135 setenv rd_size 2663940
136 setenv kernel BFC38000
137 setenv oad_addr 80500000
138 setenv load_addr2 80F00000
139 setenv kernel_flash BFC38000
140 setenv load_addr_hello 80200000
141 setenv bootargs 'root=/dev/ram0 init=/bin/sh'
142 setenv load_rd_ext2 'ide res; ext2load ide 0:2 ${rd_start} /boot/initrd.gz'
143 setenv load_rd_tftp 'tftp ${rd_start} /initrd.gz'
144 setenv load_kernel_hda 'ide res; diskboot ${load_addr} 0:2'
145 setenv load_kernel_ext2 'ide res; ext2load ide 0:2 ${load_addr} /boot/uImage'
146 setenv load_kernel_tftp 'tftp ${load_addr} /qemu_mips/uImage'
147 setenv boot_ext2_ext2 'run load_rd_ext2; run load_kernel_ext2; run addmisc; bootm ${load_addr}'
148 setenv boot_ext2_flash 'run load_rd_ext2; run addmisc; bootm ${kernel_flash}'
149 setenv boot_ext2_hda 'run load_rd_ext2; run load_kernel_hda; run addmisc; bootm ${load_addr}'
150 setenv boot_ext2_tftp 'run load_rd_ext2; run load_kernel_tftp; run addmisc; bootm ${load_addr}'
151 setenv boot_tftp_hda 'run load_rd_tftp; run load_kernel_hda; run addmisc; bootm ${load_addr}'
152 setenv boot_tftp_ext2 'run load_rd_tftp; run load_kernel_ext2; run addmisc; bootm ${load_addr}'
153 setenv boot_tftp_flash 'run load_rd_tftp; run addmisc; bootm ${kernel_flash}'
154 setenv boot_tftp_tftp 'run load_rd_tftp; run load_kernel_tftp; run addmisc; bootm ${load_addr}'
155 setenv load_hello_tftp 'tftp ${load_addr_hello} /examples/hello_world.bin'
156 setenv go_tftp 'run load_hello_tftp; go ${load_addr_hello}'
157 setenv addmisc 'setenv bootargs ${bootargs} console=ttyS0,${baudrate} rd_start=${rd_start} rd_size=${rd_size} ethaddr=${ethaddr}'
158 setenv bootcmd 'run boot_tftp_flash'
159
160Now you can boot from flash, ide, ide+ext2 and tfp::
161
162 # qemu-system-mips -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide
163
164
165How to debug U-Boot
166-------------------
167
168In order to debug U-Boot you need to start qemu with gdb server support (-s)
169and waiting the connection to start the CPU (-S)
170
171.. code-block:: none
172
173 # qemu-system-mips -S -s -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide
174
175in an other console you start gdb
176
177Debugging of U-Boot Before Relocation
178^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179
180Before relocation, the addresses in the ELF file can be used without any problems
181by connecting to the gdb server localhost:1234
182
183.. code-block:: none
184
185 # mipsel-unknown-linux-gnu-gdb u-boot
186 GNU gdb 6.6
187 Copyright (C) 2006 Free Software Foundation, Inc.
188 GDB is free software, covered by the GNU General Public License, and you are
189 welcome to change it and/or distribute copies of it under certain conditions.
190 Type "show copying" to see the conditions.
191 There is absolutely no warranty for GDB. Type "show warranty" for details.
192 This GDB was configured as "--host=i486-linux-gnu --target=mipsel-unknown-linux-gnu"...
193 (gdb) target remote localhost:1234
194 Remote debugging using localhost:1234
195 _start () at start.S:64
196 64 RVECENT(reset,0) /* U-Boot entry point */
197 Current language: auto; currently asm
198 (gdb) b board.c:289
199 Breakpoint 1 at 0xbfc00cc8: file board.c, line 289.
200 (gdb) c
201 Continuing.
202
203 Breakpoint 1, board_init_f (bootflag=<value optimized out>) at board.c:290
204 290 relocate_code (addr_sp, id, addr);
205 Current language: auto; currently c
206 (gdb) p/x addr
207 $1 = 0x87fa0000
208
209Debugging of U-Boot After Relocation
210^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
211
212For debugging U-Boot after relocation we need to know the address to which
213U-Boot relocates itself to 0x87fa0000 by default.
214And replace the symbol table to this offset.
215
216.. code-block:: none
217
218 (gdb) symbol-file
219 Discard symbol table from `/private/u-boot-arm/u-boot'? (y or n) y
220 Error in re-setting breakpoint 1:
221 No symbol table is loaded. Use the "file" command.
222 No symbol file now.
223 (gdb) add-symbol-file u-boot 0x87fa0000
224 add symbol table from file "u-boot" at
225 .text_addr = 0x87fa0000
226 (y or n) y
227 Reading symbols from /private/u-boot-arm/u-boot...done.
228 Breakpoint 1 at 0x87fa0cc8: file board.c, line 289.
229 (gdb) c
230 Continuing.
231
232 Program received signal SIGINT, Interrupt.
233 0xffffffff87fa0de4 in udelay (usec=<value optimized out>) at time.c:78
234 78 while ((tmo - read_c0_count()) < 0x7fffffff)