blob: d35925126a548cfb83fe2ee6304a0f5e58d016e2 [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
Heinrich Schuchardtfad68352020-01-01 08:34:03 +01002832 bit, big endian
Bin Meng475d4bd2019-07-18 00:34:17 -070029
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010030.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -070031
Heinrich Schuchardt75e0fac2020-07-27 18:46:09 +020032 make qemu_mips_defconfig
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010033 qemu-system-mips -M mips -bios u-boot.bin -nographic
Bin Meng475d4bd2019-07-18 00:34:17 -070034
Heinrich Schuchardtfad68352020-01-01 08:34:03 +01003532 bit, little endian
Bin Meng475d4bd2019-07-18 00:34:17 -070036
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010037.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -070038
Heinrich Schuchardt75e0fac2020-07-27 18:46:09 +020039 make qemu_mipsel_defconfig
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010040 qemu-system-mipsel -M mips -bios u-boot.bin -nographic
Bin Meng475d4bd2019-07-18 00:34:17 -070041
Heinrich Schuchardtfad68352020-01-01 08:34:03 +01004264 bit, big endian
Bin Meng475d4bd2019-07-18 00:34:17 -070043
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010044.. code-block:: bash
45
Heinrich Schuchardt75e0fac2020-07-27 18:46:09 +020046 make qemu_mips64_defconfig
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010047 qemu-system-mips64 -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic
48
4964 bit, little endian
50
51.. code-block:: bash
52
Heinrich Schuchardt75e0fac2020-07-27 18:46:09 +020053 make qemu_mips64el_defconfig
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010054 qemu-system-mips64el -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic
Bin Meng475d4bd2019-07-18 00:34:17 -070055
56or using u-boot.bin from emulated flash:
57
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010058if you use a QEMU version after commit 4224
Bin Meng475d4bd2019-07-18 00:34:17 -070059
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010060.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -070061
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010062 # create image:
63 dd of=flash bs=1k count=4k if=/dev/zero
64 dd of=flash bs=1k conv=notrunc if=u-boot.bin
65 # start it (see above):
66 qemu-system-mips[64][el] [-cpu MIPS64R2-generic] -M mips -pflash flash -nographic
Bin Meng475d4bd2019-07-18 00:34:17 -070067
68Download kernel + initrd
69^^^^^^^^^^^^^^^^^^^^^^^^
70
71On ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/
72you can downland::
73
74 #config to build the kernel
75 qemu_mips_defconfig
76 #patch to fix mips interrupt init on 2.6.24.y kernel
77 qemu_mips_kernel.patch
78 initrd.gz
79 vmlinux
80 vmlinux.bin
81 System.map
82
83Generate uImage
84^^^^^^^^^^^^^^^
85
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010086.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -070087
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010088 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
Bin Meng475d4bd2019-07-18 00:34:17 -070089
90Copy uImage to Flash
91^^^^^^^^^^^^^^^^^^^^
92
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010093.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -070094
Heinrich Schuchardtfad68352020-01-01 08:34:03 +010095 dd if=uImage bs=1k conv=notrunc seek=224 of=flash
Bin Meng475d4bd2019-07-18 00:34:17 -070096
97Generate Ide Disk
98^^^^^^^^^^^^^^^^^
99
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100100.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -0700101
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100102 dd of=ide bs=1k count=100k if=/dev/zero
Bin Meng475d4bd2019-07-18 00:34:17 -0700103
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100104 # Create partion table
105 sudo sfdisk ide << EOF
106 label: dos
107 label-id: 0x6fe3a999
108 device: image
Bin Meng475d4bd2019-07-18 00:34:17 -0700109 unit: sectors
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100110 image1 : start= 63, size= 32067, Id=83
111 image2 : start= 32130, size= 32130, Id=83
112 image3 : start= 64260, size= 4128705, Id=83
113 EOF
Bin Meng475d4bd2019-07-18 00:34:17 -0700114
115Copy to ide
116^^^^^^^^^^^
117
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100118.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -0700119
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100120 dd if=uImage bs=512 conv=notrunc seek=63 of=ide
Bin Meng475d4bd2019-07-18 00:34:17 -0700121
122Generate ext2 on part 2 on Copy uImage and initrd.gz
123^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100125.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -0700126
127 # Attached as loop device ide offset = 32130 * 512
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100128 sudo losetup -o 16450560 /dev/loop0 ide
Bin Meng475d4bd2019-07-18 00:34:17 -0700129 # Format as ext2 ( arg2 : nb blocks)
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100130 sudo mkfs.ext2 /dev/loop0 16065
131 sudo losetup -d /dev/loop0
Bin Meng475d4bd2019-07-18 00:34:17 -0700132 # Mount and copy uImage and initrd.gz to it
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100133 sudo mount -o loop,offset=16450560 -t ext2 ide /mnt
134 sudo mkdir /mnt/boot
135 cp {initrd.gz,uImage} /mnt/boot/
Bin Meng475d4bd2019-07-18 00:34:17 -0700136 # Umount it
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100137 sudo umount /mnt
Bin Meng475d4bd2019-07-18 00:34:17 -0700138
139Set Environment
140^^^^^^^^^^^^^^^
141
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100142.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -0700143
144 setenv rd_start 0x80800000
145 setenv rd_size 2663940
146 setenv kernel BFC38000
147 setenv oad_addr 80500000
148 setenv load_addr2 80F00000
149 setenv kernel_flash BFC38000
150 setenv load_addr_hello 80200000
151 setenv bootargs 'root=/dev/ram0 init=/bin/sh'
152 setenv load_rd_ext2 'ide res; ext2load ide 0:2 ${rd_start} /boot/initrd.gz'
153 setenv load_rd_tftp 'tftp ${rd_start} /initrd.gz'
154 setenv load_kernel_hda 'ide res; diskboot ${load_addr} 0:2'
155 setenv load_kernel_ext2 'ide res; ext2load ide 0:2 ${load_addr} /boot/uImage'
156 setenv load_kernel_tftp 'tftp ${load_addr} /qemu_mips/uImage'
157 setenv boot_ext2_ext2 'run load_rd_ext2; run load_kernel_ext2; run addmisc; bootm ${load_addr}'
158 setenv boot_ext2_flash 'run load_rd_ext2; run addmisc; bootm ${kernel_flash}'
159 setenv boot_ext2_hda 'run load_rd_ext2; run load_kernel_hda; run addmisc; bootm ${load_addr}'
160 setenv boot_ext2_tftp 'run load_rd_ext2; run load_kernel_tftp; run addmisc; bootm ${load_addr}'
161 setenv boot_tftp_hda 'run load_rd_tftp; run load_kernel_hda; run addmisc; bootm ${load_addr}'
162 setenv boot_tftp_ext2 'run load_rd_tftp; run load_kernel_ext2; run addmisc; bootm ${load_addr}'
163 setenv boot_tftp_flash 'run load_rd_tftp; run addmisc; bootm ${kernel_flash}'
164 setenv boot_tftp_tftp 'run load_rd_tftp; run load_kernel_tftp; run addmisc; bootm ${load_addr}'
165 setenv load_hello_tftp 'tftp ${load_addr_hello} /examples/hello_world.bin'
166 setenv go_tftp 'run load_hello_tftp; go ${load_addr_hello}'
167 setenv addmisc 'setenv bootargs ${bootargs} console=ttyS0,${baudrate} rd_start=${rd_start} rd_size=${rd_size} ethaddr=${ethaddr}'
168 setenv bootcmd 'run boot_tftp_flash'
169
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100170Now you can boot from flash, ide, ide+ext2 and tfp
Bin Meng475d4bd2019-07-18 00:34:17 -0700171
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100172.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -0700173
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100174 qemu-system-mips -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide
175
Bin Meng475d4bd2019-07-18 00:34:17 -0700176
177How to debug U-Boot
178-------------------
179
180In order to debug U-Boot you need to start qemu with gdb server support (-s)
181and waiting the connection to start the CPU (-S)
182
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100183.. code-block:: bash
Bin Meng475d4bd2019-07-18 00:34:17 -0700184
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100185 qemu-system-mips -S -s -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide
Bin Meng475d4bd2019-07-18 00:34:17 -0700186
187in an other console you start gdb
188
189Debugging of U-Boot Before Relocation
190^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191
192Before relocation, the addresses in the ELF file can be used without any problems
193by connecting to the gdb server localhost:1234
194
195.. code-block:: none
196
Heinrich Schuchardtfad68352020-01-01 08:34:03 +0100197 $ mipsel-unknown-linux-gnu-gdb u-boot
Bin Meng475d4bd2019-07-18 00:34:17 -0700198 GNU gdb 6.6
199 Copyright (C) 2006 Free Software Foundation, Inc.
200 GDB is free software, covered by the GNU General Public License, and you are
201 welcome to change it and/or distribute copies of it under certain conditions.
202 Type "show copying" to see the conditions.
203 There is absolutely no warranty for GDB. Type "show warranty" for details.
204 This GDB was configured as "--host=i486-linux-gnu --target=mipsel-unknown-linux-gnu"...
205 (gdb) target remote localhost:1234
206 Remote debugging using localhost:1234
207 _start () at start.S:64
208 64 RVECENT(reset,0) /* U-Boot entry point */
209 Current language: auto; currently asm
210 (gdb) b board.c:289
211 Breakpoint 1 at 0xbfc00cc8: file board.c, line 289.
212 (gdb) c
213 Continuing.
214
215 Breakpoint 1, board_init_f (bootflag=<value optimized out>) at board.c:290
216 290 relocate_code (addr_sp, id, addr);
217 Current language: auto; currently c
218 (gdb) p/x addr
219 $1 = 0x87fa0000
220
221Debugging of U-Boot After Relocation
222^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
223
224For debugging U-Boot after relocation we need to know the address to which
225U-Boot relocates itself to 0x87fa0000 by default.
226And replace the symbol table to this offset.
227
228.. code-block:: none
229
230 (gdb) symbol-file
231 Discard symbol table from `/private/u-boot-arm/u-boot'? (y or n) y
232 Error in re-setting breakpoint 1:
233 No symbol table is loaded. Use the "file" command.
234 No symbol file now.
235 (gdb) add-symbol-file u-boot 0x87fa0000
236 add symbol table from file "u-boot" at
237 .text_addr = 0x87fa0000
238 (y or n) y
239 Reading symbols from /private/u-boot-arm/u-boot...done.
240 Breakpoint 1 at 0x87fa0cc8: file board.c, line 289.
241 (gdb) c
242 Continuing.
243
244 Program received signal SIGINT, Interrupt.
245 0xffffffff87fa0de4 in udelay (usec=<value optimized out>) at time.c:78
246 78 while ((tmo - read_c0_count()) < 0x7fffffff)