Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | .. sectionauthor:: Vlad Lungu <vlad.lungu@windriver.com> |
| 3 | |
| 4 | QEMU MIPS |
| 5 | ========= |
| 6 | |
| 7 | Qemu is a full system emulator. See http://www.nongnu.org/qemu/ |
| 8 | |
| 9 | Limitations & comments |
| 10 | ---------------------- |
| 11 | Supports the "-M mips" configuration of qemu: serial,NE2000,IDE. |
| 12 | Supports little and big endian as well as 32 bit and 64 bit. |
| 13 | Derived from au1x00 with a lot of things cut out. |
| 14 | |
| 15 | Supports emulated flash (patch Jean-Christophe PLAGNIOL-VILLARD) with |
| 16 | recent qemu versions. When using emulated flash, launch with |
| 17 | -pflash <filename> and erase mips_bios.bin. |
| 18 | |
| 19 | |
| 20 | Notes for the Qemu MIPS port |
| 21 | ---------------------------- |
| 22 | |
| 23 | Example usage |
| 24 | ^^^^^^^^^^^^^ |
| 25 | |
| 26 | Using u-boot.bin as ROM (replaces Qemu monitor): |
| 27 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 28 | 32 bit, big endian |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 29 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 30 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 31 | |
Heinrich Schuchardt | 75e0fac | 2020-07-27 18:46:09 +0200 | [diff] [blame] | 32 | make qemu_mips_defconfig |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 33 | qemu-system-mips -M mips -bios u-boot.bin -nographic |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 34 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 35 | 32 bit, little endian |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 36 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 37 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 38 | |
Heinrich Schuchardt | 75e0fac | 2020-07-27 18:46:09 +0200 | [diff] [blame] | 39 | make qemu_mipsel_defconfig |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 40 | qemu-system-mipsel -M mips -bios u-boot.bin -nographic |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 41 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 42 | 64 bit, big endian |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 43 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 44 | .. code-block:: bash |
| 45 | |
Heinrich Schuchardt | 75e0fac | 2020-07-27 18:46:09 +0200 | [diff] [blame] | 46 | make qemu_mips64_defconfig |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 47 | qemu-system-mips64 -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic |
| 48 | |
| 49 | 64 bit, little endian |
| 50 | |
| 51 | .. code-block:: bash |
| 52 | |
Heinrich Schuchardt | 75e0fac | 2020-07-27 18:46:09 +0200 | [diff] [blame] | 53 | make qemu_mips64el_defconfig |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 54 | qemu-system-mips64el -cpu MIPS64R2-generic -M mips -bios u-boot.bin -nographic |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 55 | |
| 56 | or using u-boot.bin from emulated flash: |
| 57 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 58 | if you use a QEMU version after commit 4224 |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 59 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 60 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 61 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 62 | # 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 Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 67 | |
| 68 | Download kernel + initrd |
| 69 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 70 | |
| 71 | On ftp://ftp.denx.de/pub/contrib/Jean-Christophe_Plagniol-Villard/qemu_mips/ |
| 72 | you 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 | |
| 83 | Generate uImage |
| 84 | ^^^^^^^^^^^^^^^ |
| 85 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 86 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 87 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 88 | 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 Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 89 | |
| 90 | Copy uImage to Flash |
| 91 | ^^^^^^^^^^^^^^^^^^^^ |
| 92 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 93 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 94 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 95 | dd if=uImage bs=1k conv=notrunc seek=224 of=flash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 96 | |
| 97 | Generate Ide Disk |
| 98 | ^^^^^^^^^^^^^^^^^ |
| 99 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 100 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 101 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 102 | dd of=ide bs=1k count=100k if=/dev/zero |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 103 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 104 | # Create partion table |
| 105 | sudo sfdisk ide << EOF |
| 106 | label: dos |
| 107 | label-id: 0x6fe3a999 |
| 108 | device: image |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 109 | unit: sectors |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 110 | 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 Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 114 | |
| 115 | Copy to ide |
| 116 | ^^^^^^^^^^^ |
| 117 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 118 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 119 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 120 | dd if=uImage bs=512 conv=notrunc seek=63 of=ide |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 121 | |
| 122 | Generate ext2 on part 2 on Copy uImage and initrd.gz |
| 123 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 124 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 125 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 126 | |
| 127 | # Attached as loop device ide offset = 32130 * 512 |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 128 | sudo losetup -o 16450560 /dev/loop0 ide |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 129 | # Format as ext2 ( arg2 : nb blocks) |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 130 | sudo mkfs.ext2 /dev/loop0 16065 |
| 131 | sudo losetup -d /dev/loop0 |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 132 | # Mount and copy uImage and initrd.gz to it |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 133 | sudo mount -o loop,offset=16450560 -t ext2 ide /mnt |
| 134 | sudo mkdir /mnt/boot |
| 135 | cp {initrd.gz,uImage} /mnt/boot/ |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 136 | # Umount it |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 137 | sudo umount /mnt |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 138 | |
| 139 | Set Environment |
| 140 | ^^^^^^^^^^^^^^^ |
| 141 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 142 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 143 | |
| 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 Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 170 | Now you can boot from flash, ide, ide+ext2 and tfp |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 171 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 172 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 173 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 174 | qemu-system-mips -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide |
| 175 | |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 176 | |
| 177 | How to debug U-Boot |
| 178 | ------------------- |
| 179 | |
| 180 | In order to debug U-Boot you need to start qemu with gdb server support (-s) |
| 181 | and waiting the connection to start the CPU (-S) |
| 182 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 183 | .. code-block:: bash |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 184 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 185 | qemu-system-mips -S -s -M mips -pflash flash -monitor null -nographic -net nic -net user -tftp `pwd` -hda ide |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 186 | |
| 187 | in an other console you start gdb |
| 188 | |
| 189 | Debugging of U-Boot Before Relocation |
| 190 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 191 | |
| 192 | Before relocation, the addresses in the ELF file can be used without any problems |
| 193 | by connecting to the gdb server localhost:1234 |
| 194 | |
| 195 | .. code-block:: none |
| 196 | |
Heinrich Schuchardt | fad6835 | 2020-01-01 08:34:03 +0100 | [diff] [blame] | 197 | $ mipsel-unknown-linux-gnu-gdb u-boot |
Bin Meng | 475d4bd | 2019-07-18 00:34:17 -0700 | [diff] [blame] | 198 | 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 | |
| 221 | Debugging of U-Boot After Relocation |
| 222 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 223 | |
| 224 | For debugging U-Boot after relocation we need to know the address to which |
| 225 | U-Boot relocates itself to 0x87fa0000 by default. |
| 226 | And 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) |