qemu-x86.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. .. sectionauthor:: Bin Meng <bmeng.cn@gmail.com>
  3. QEMU x86
  4. ========
  5. Build instructions for bare mode
  6. --------------------------------
  7. To build u-boot.rom for QEMU x86 targets, just simply run::
  8. $ make qemu-x86_defconfig (for 32-bit)
  9. $ make qemu-x86_64_defconfig (for 64-bit)
  10. $ make all
  11. Note this default configuration will build a U-Boot for the QEMU x86 i440FX
  12. board. To build a U-Boot against QEMU x86 Q35 board, you can change the build
  13. configuration during the 'make menuconfig' process like below::
  14. Device Tree Control --->
  15. ...
  16. (qemu-x86_q35) Default Device Tree for DT control
  17. Test with QEMU for bare mode
  18. ----------------------------
  19. QEMU is a fancy emulator that can enable us to test U-Boot without access to
  20. a real x86 board. Please make sure your QEMU version is 2.3.0 or above test
  21. U-Boot. To launch QEMU with u-boot.rom, call QEMU as follows::
  22. $ qemu-system-i386 -nographic -bios path/to/u-boot.rom
  23. This will instantiate an emulated x86 board with i440FX and PIIX chipset. QEMU
  24. also supports emulating an x86 board with Q35 and ICH9 based chipset, which is
  25. also supported by U-Boot. To instantiate such a machine, call QEMU with::
  26. $ qemu-system-i386 -nographic -bios path/to/u-boot.rom -M q35
  27. Note by default QEMU instantiated boards only have 128 MiB system memory. But
  28. it is enough to have U-Boot boot and function correctly. You can increase the
  29. system memory by pass '-m' parameter to QEMU if you want more memory::
  30. $ qemu-system-i386 -nographic -bios path/to/u-boot.rom -m 1024
  31. This creates a board with 1 GiB system memory. Currently U-Boot for QEMU only
  32. supports 3 GiB maximum system memory and reserves the last 1 GiB address space
  33. for PCI device memory-mapped I/O and other stuff, so the maximum value of '-m'
  34. would be 3072.
  35. QEMU emulates a graphic card which U-Boot supports. Removing '-nographic' will
  36. show QEMU's VGA console window. Note this will disable QEMU's serial output.
  37. If you want to check both consoles, use '-serial stdio'.
  38. Multicore is also supported by QEMU via '-smp n' where n is the number of cores
  39. to instantiate. Note, the maximum supported CPU number in QEMU is 255.
  40. U-Boot uses 'distro_bootcmd' by default when booting on x86 QEMU. This tries to
  41. load a boot script, kernel, and ramdisk from several different interfaces. For
  42. the default boot order, see 'qemu-x86.h'. For more information, see
  43. 'README.distro'. Most Linux distros can be booted by writing a uboot script.
  44. For example, Debian (stretch) can be booted by creating a script file named
  45. 'boot.txt' with the contents::
  46. setenv bootargs root=/dev/sda1 ro
  47. load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} /vmlinuz
  48. load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /initrd.img
  49. zboot ${kernel_addr_r} - ${ramdisk_addr_r} ${filesize}
  50. Then compile and install it with::
  51. $ apt install u-boot-tools && \
  52. mkimage -T script -C none -n "Boot script" -d boot.txt /boot/boot.scr
  53. The fw_cfg interface in QEMU also provides information about kernel data,
  54. initrd, command-line arguments and more. U-Boot supports directly accessing
  55. these informtion from fw_cfg interface, which saves the time of loading them
  56. from hard disk or network again, through emulated devices. To use it , simply
  57. providing them in QEMU command line::
  58. $ qemu-system-i386 -nographic -bios path/to/u-boot.rom -m 1024 \
  59. -kernel /path/to/bzImage -append 'root=/dev/ram console=ttyS0' \
  60. -initrd /path/to/initrd -smp 8
  61. Note: -initrd and -smp are both optional
  62. Then start QEMU, in U-Boot command line use the following U-Boot command to
  63. setup kernel::
  64. => qfw
  65. qfw - QEMU firmware interface
  66. Usage:
  67. qfw <command>
  68. - list : print firmware(s) currently loaded
  69. - cpus : print online cpu number
  70. - load <kernel addr> <initrd addr> : load kernel and initrd (if any) and setup for zboot
  71. => qfw load
  72. loading kernel to address 01000000 size 5d9d30 initrd 04000000 size 1b1ab50
  73. Here the kernel (bzImage) is loaded to 01000000 and initrd is to 04000000. Then,
  74. 'zboot' can be used to boot the kernel::
  75. => zboot 01000000 - 04000000 1b1ab50
  76. To run 64-bit U-Boot, qemu-system-x86_64 should be used instead, e.g.::
  77. $ qemu-system-x86_64 -nographic -bios path/to/u-boot.rom
  78. A specific CPU can be specified via the '-cpu' parameter but please make
  79. sure the specified CPU supports 64-bit like '-cpu core2duo'. Conversely
  80. '-cpu pentium' won't work for obvious reasons that the processor only
  81. supports 32-bit.
  82. Note 64-bit support is very preliminary at this point. Lots of features
  83. are missing in the 64-bit world. One notable feature is the VGA console
  84. support which is currently missing, so that you must specify '-nographic'
  85. to get 64-bit U-Boot up and running.