xref: /openbmc/qemu/docs/system/loongarch/virt.rst (revision 5f4c96b7)
1*5f4c96b7SSong Gao:orphan:
2*5f4c96b7SSong Gao
3*5f4c96b7SSong Gao==========================================
4*5f4c96b7SSong Gaoloongson3 virt generic platform (``virt``)
5*5f4c96b7SSong Gao==========================================
6*5f4c96b7SSong Gao
7*5f4c96b7SSong GaoThe ``virt`` machine use gpex host bridge, and there are some
8*5f4c96b7SSong Gaoemulated devices on virt board, such as loongson7a RTC device,
9*5f4c96b7SSong GaoIOAPIC device, ACPI device and so on.
10*5f4c96b7SSong Gao
11*5f4c96b7SSong GaoSupported devices
12*5f4c96b7SSong Gao-----------------
13*5f4c96b7SSong Gao
14*5f4c96b7SSong GaoThe ``virt`` machine supports:
15*5f4c96b7SSong Gao- Gpex host bridge
16*5f4c96b7SSong Gao- Ls7a RTC device
17*5f4c96b7SSong Gao- Ls7a IOAPIC device
18*5f4c96b7SSong Gao- ACPI GED device
19*5f4c96b7SSong Gao- Fw_cfg device
20*5f4c96b7SSong Gao- PCI/PCIe devices
21*5f4c96b7SSong Gao- Memory device
22*5f4c96b7SSong Gao- CPU device. Type: la464.
23*5f4c96b7SSong Gao
24*5f4c96b7SSong GaoCPU and machine Type
25*5f4c96b7SSong Gao--------------------
26*5f4c96b7SSong Gao
27*5f4c96b7SSong GaoThe ``qemu-system-loongarch64`` provides emulation for virt
28*5f4c96b7SSong Gaomachine. You can specify the machine type ``virt`` and
29*5f4c96b7SSong Gaocpu type ``la464``.
30*5f4c96b7SSong Gao
31*5f4c96b7SSong GaoBoot options
32*5f4c96b7SSong Gao------------
33*5f4c96b7SSong Gao
34*5f4c96b7SSong GaoWe can boot the LoongArch virt machine by specifying the uefi bios,
35*5f4c96b7SSong Gaoinitrd, and linux kernel. And those source codes and binary files
36*5f4c96b7SSong Gaocan be accessed by following steps.
37*5f4c96b7SSong Gao
38*5f4c96b7SSong Gao(1) Build qemu-system-loongarch64:
39*5f4c96b7SSong Gao
40*5f4c96b7SSong Gao.. code-block:: bash
41*5f4c96b7SSong Gao
42*5f4c96b7SSong Gao  ./configure --disable-rdma --disable-pvrdma --prefix=/usr \
43*5f4c96b7SSong Gao              --target-list="loongarch64-softmmu" \
44*5f4c96b7SSong Gao              --disable-libiscsi --disable-libnfs --disable-libpmem \
45*5f4c96b7SSong Gao              --disable-glusterfs --enable-libusb --enable-usb-redir \
46*5f4c96b7SSong Gao              --disable-opengl --disable-xen --enable-spice \
47*5f4c96b7SSong Gao              --enable-debug --disable-capstone --disable-kvm \
48*5f4c96b7SSong Gao              --enable-profiler
49*5f4c96b7SSong Gao  make -j8
50*5f4c96b7SSong Gao
51*5f4c96b7SSong Gao(2) Set cross tools:
52*5f4c96b7SSong Gao
53*5f4c96b7SSong Gao.. code-block:: bash
54*5f4c96b7SSong Gao
55*5f4c96b7SSong Gao  wget https://github.com/loongson/build-tools/releases/download/2022.09.06/loongarch64-clfs-6.3-cross-tools-gcc-glibc.tar.xz
56*5f4c96b7SSong Gao
57*5f4c96b7SSong Gao  tar -vxf loongarch64-clfs-6.3-cross-tools-gcc-glibc.tar.xz  -C /opt
58*5f4c96b7SSong Gao
59*5f4c96b7SSong Gao  export PATH=/opt/cross-tools/bin:$PATH
60*5f4c96b7SSong Gao  export LD_LIBRARY_PATH=/opt/cross-tools/lib:$LD_LIBRARY_PATH
61*5f4c96b7SSong Gao  export LD_LIBRARY_PATH=/opt/cross-tools/loongarch64-unknown-linux-gnu/lib/:$LD_LIBRARY_PATH
62*5f4c96b7SSong Gao
63*5f4c96b7SSong GaoNote: You need get the latest cross-tools at https://github.com/loongson/build-tools
64*5f4c96b7SSong Gao
65*5f4c96b7SSong Gao(3) Build BIOS:
66*5f4c96b7SSong Gao
67*5f4c96b7SSong Gao    See: https://github.com/tianocore/edk2-platforms/tree/master/Platform/Loongson/LoongArchQemuPkg#readme
68*5f4c96b7SSong Gao
69*5f4c96b7SSong GaoNote: To build the release version of the bios,  set --buildtarget=RELEASE,
70*5f4c96b7SSong Gao      the bios file path:  Build/LoongArchQemu/RELEASE_GCC5/FV/QEMU_EFI.fd
71*5f4c96b7SSong Gao
72*5f4c96b7SSong Gao(4) Build kernel:
73*5f4c96b7SSong Gao
74*5f4c96b7SSong Gao.. code-block:: bash
75*5f4c96b7SSong Gao
76*5f4c96b7SSong Gao  git clone https://github.com/loongson/linux.git
77*5f4c96b7SSong Gao
78*5f4c96b7SSong Gao  cd linux
79*5f4c96b7SSong Gao
80*5f4c96b7SSong Gao  git checkout loongarch-next
81*5f4c96b7SSong Gao
82*5f4c96b7SSong Gao  make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- loongson3_defconfig
83*5f4c96b7SSong Gao
84*5f4c96b7SSong Gao  make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- -j32
85*5f4c96b7SSong Gao
86*5f4c96b7SSong GaoNote: The branch of linux source code is loongarch-next.
87*5f4c96b7SSong Gao      the kernel file: arch/loongarch/boot/vmlinuz.efi
88*5f4c96b7SSong Gao
89*5f4c96b7SSong Gao(5) Get initrd:
90*5f4c96b7SSong Gao
91*5f4c96b7SSong Gao  You can use busybox tool and the linux modules to make a initrd file. Or you can access the
92*5f4c96b7SSong Gao  binary files: https://github.com/yangxiaojuan-loongson/qemu-binary
93*5f4c96b7SSong Gao
94*5f4c96b7SSong Gao.. code-block:: bash
95*5f4c96b7SSong Gao
96*5f4c96b7SSong Gao  git clone https://github.com/yangxiaojuan-loongson/qemu-binary
97*5f4c96b7SSong Gao
98*5f4c96b7SSong GaoNote: the initrd file is ramdisk
99*5f4c96b7SSong Gao
100*5f4c96b7SSong Gao(6) Booting LoongArch:
101*5f4c96b7SSong Gao
102*5f4c96b7SSong Gao.. code-block:: bash
103*5f4c96b7SSong Gao
104*5f4c96b7SSong Gao  $ ./build/qemu-system-loongarch64 -machine virt -m 4G -cpu la464 \
105*5f4c96b7SSong Gao      -smp 1 -bios QEMU_EFI.fd -kernel vmlinuz.efi -initrd ramdisk \
106*5f4c96b7SSong Gao      -serial stdio   -monitor telnet:localhost:4495,server,nowait \
107*5f4c96b7SSong Gao      -append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" \
108*5f4c96b7SSong Gao      --nographic
109