qemu-mips.rst 7.3 KB

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