1.. SPDX-License-Identifier: GPL-2.0+
2.. sectionauthor:: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3
4QEMU MIPS
5=========
6
7Qemu for MIPS is based on the MIPS Malta board. The built Malta U-Boot
8images can be used for Qemu and on physical hardware. The Malta board
9supports all combinations of Little and Big Endian as well as 32 bit
10and 64 bit.
11
12Limitations & comments
13----------------------
14The memory size for Qemu is hard-coded to 256 MiB. For Malta Little Endian
15targets an extra endianness swapped image named *u-boot-swap.bin* is
16generated and required for Qemu.
17
18Example usage
19-------------
20
21Build for 32 bit, big endian:
22
23.. code-block:: bash
24
25  make malta_defconfig
26  make
27  UBOOT_BIN=u-boot.bin
28  QEMU_BIN=qemu-system-mips
29  QEMU_CPU=24Kc
30
31Build for 32 bit, little endian:
32
33.. code-block:: bash
34
35  make maltael_defconfig
36  make
37  UBOOT_BIN=u-boot-swap.bin
38  QEMU_BIN=qemu-system-mipsel
39  QEMU_CPU=24Kc
40
41Build for 64 bit, big endian:
42
43.. code-block:: bash
44
45  make malta64_defconfig
46  make
47  UBOOT_BIN=u-boot.bin
48  QEMU_BIN=qemu-system-mips64
49  QEMU_CPU=MIPS64R2-generic
50
51Build for 64 bit, little endian:
52
53.. code-block:: bash
54
55  make malta64el_defconfig
56  make
57  UBOOT_BIN=u-boot-swap.bin
58  QEMU_BIN=qemu-system-mips64el
59  QEMU_CPU=MIPS64R2-generic
60
61Generate NOR flash image with U-Boot binary:
62
63.. code-block:: bash
64
65  dd if=/dev/zero bs=1M count=4 | tr '\000' '\377' > pflash.img
66  dd if=${UBOOT_BIN} of=pflash.img conv=notrunc
67
68Start Qemu:
69
70.. code-block:: bash
71
72  mkdir tftproot
73  ${QEMU_BIN} -nographic -cpu ${QEMU_CPU} -m 256 -drive if=pflash,file="$(pwd)/pflash.img",format=raw -netdev user,id=net0,tftp="$(pwd)/tftproot" -device pcnet,netdev=net0
74
75.. code-block:: bash
76
77  U-Boot 2021.04-00963-g60279a2b1d (Apr 21 2021 - 19:54:32 +0200)
78
79  Board: MIPS Malta CoreLV
80  DRAM:  256 MiB
81  Flash: 4 MiB
82  Loading Environment from Flash... *** Warning - bad CRC, using default environment
83
84  In:    serial@3f8
85  Out:   serial@3f8
86  Err:   serial@3f8
87  Net:   pcnet#0
88  IDE:   Bus 0: not available
89  maltael #
90
91How to debug U-Boot
92-------------------
93
94In order to debug U-Boot you need to start qemu with gdb server support (-s)
95and waiting the connection to start the CPU (-S). Start Qemu in the first console:
96
97.. code-block:: bash
98
99  mkdir tftproot
100  ${QEMU_BIN} -s -S -nographic -cpu ${QEMU_CPU} -m 256 -drive if=pflash,file="$(pwd)/pflash.img",format=raw -netdev user,id=net0,tftp="$(pwd)/tftproot" -device pcnet,netdev=net0
101
102In the second console start gdb:
103
104.. code-block:: bash
105
106  gdb-multiarch --eval-command "target remote :1234" u-boot
107
108.. code-block:: bash
109
110  GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
111  Copyright (C) 2020 Free Software Foundation, Inc.
112  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
113  This is free software: you are free to change and redistribute it.
114  There is NO WARRANTY, to the extent permitted by law.
115  Type "show copying" and "show warranty" for details.
116  This GDB was configured as "x86_64-linux-gnu".
117  Type "show configuration" for configuration details.
118  For bug reporting instructions, please see:
119  <http://www.gnu.org/software/gdb/bugs/>.
120  Find the GDB manual and other documentation resources online at:
121      <http://www.gnu.org/software/gdb/documentation/>.
122
123  For help, type "help".
124  Type "apropos word" to search for commands related to "word"...
125  Reading symbols from u-boot...
126  Remote debugging using :1234
127  0xbfc00000 in ?? ()
128  (gdb) c
129  Continuing.
130