15f4c96b7SSong Gao:orphan: 25f4c96b7SSong Gao 35f4c96b7SSong Gao========================================== 45f4c96b7SSong Gaoloongson3 virt generic platform (``virt``) 55f4c96b7SSong Gao========================================== 65f4c96b7SSong Gao 75f4c96b7SSong GaoThe ``virt`` machine use gpex host bridge, and there are some 85f4c96b7SSong Gaoemulated devices on virt board, such as loongson7a RTC device, 95f4c96b7SSong GaoIOAPIC device, ACPI device and so on. 105f4c96b7SSong Gao 115f4c96b7SSong GaoSupported devices 125f4c96b7SSong Gao----------------- 135f4c96b7SSong Gao 145f4c96b7SSong GaoThe ``virt`` machine supports: 155f4c96b7SSong Gao- Gpex host bridge 165f4c96b7SSong Gao- Ls7a RTC device 175f4c96b7SSong Gao- Ls7a IOAPIC device 185f4c96b7SSong Gao- ACPI GED device 195f4c96b7SSong Gao- Fw_cfg device 205f4c96b7SSong Gao- PCI/PCIe devices 215f4c96b7SSong Gao- Memory device 225f4c96b7SSong Gao- CPU device. Type: la464. 235f4c96b7SSong Gao 245f4c96b7SSong GaoCPU and machine Type 255f4c96b7SSong Gao-------------------- 265f4c96b7SSong Gao 275f4c96b7SSong GaoThe ``qemu-system-loongarch64`` provides emulation for virt 285f4c96b7SSong Gaomachine. You can specify the machine type ``virt`` and 295f4c96b7SSong Gaocpu type ``la464``. 305f4c96b7SSong Gao 315f4c96b7SSong GaoBoot options 325f4c96b7SSong Gao------------ 335f4c96b7SSong Gao 345f4c96b7SSong GaoWe can boot the LoongArch virt machine by specifying the uefi bios, 355f4c96b7SSong Gaoinitrd, and linux kernel. And those source codes and binary files 365f4c96b7SSong Gaocan be accessed by following steps. 375f4c96b7SSong Gao 385f4c96b7SSong Gao(1) Build qemu-system-loongarch64: 395f4c96b7SSong Gao 405f4c96b7SSong Gao.. code-block:: bash 415f4c96b7SSong Gao 421dfd42c4SPhilippe Mathieu-Daudé ./configure --disable-rdma --prefix=/usr \ 435f4c96b7SSong Gao --target-list="loongarch64-softmmu" \ 445f4c96b7SSong Gao --disable-libiscsi --disable-libnfs --disable-libpmem \ 455f4c96b7SSong Gao --disable-glusterfs --enable-libusb --enable-usb-redir \ 465f4c96b7SSong Gao --disable-opengl --disable-xen --enable-spice \ 475f4c96b7SSong Gao --enable-debug --disable-capstone --disable-kvm \ 485f4c96b7SSong Gao --enable-profiler 495f4c96b7SSong Gao make -j8 505f4c96b7SSong Gao 515f4c96b7SSong Gao(2) Set cross tools: 525f4c96b7SSong Gao 535f4c96b7SSong Gao.. code-block:: bash 545f4c96b7SSong Gao 555f4c96b7SSong Gao wget https://github.com/loongson/build-tools/releases/download/2022.09.06/loongarch64-clfs-6.3-cross-tools-gcc-glibc.tar.xz 565f4c96b7SSong Gao 575f4c96b7SSong Gao tar -vxf loongarch64-clfs-6.3-cross-tools-gcc-glibc.tar.xz -C /opt 585f4c96b7SSong Gao 595f4c96b7SSong Gao export PATH=/opt/cross-tools/bin:$PATH 605f4c96b7SSong Gao export LD_LIBRARY_PATH=/opt/cross-tools/lib:$LD_LIBRARY_PATH 615f4c96b7SSong Gao export LD_LIBRARY_PATH=/opt/cross-tools/loongarch64-unknown-linux-gnu/lib/:$LD_LIBRARY_PATH 625f4c96b7SSong Gao 635f4c96b7SSong GaoNote: You need get the latest cross-tools at https://github.com/loongson/build-tools 645f4c96b7SSong Gao 655f4c96b7SSong Gao(3) Build BIOS: 665f4c96b7SSong Gao 67*b883fb93SXianglai Li See: https://github.com/tianocore/edk2/tree/master/OvmfPkg/LoongArchVirt#readme 685f4c96b7SSong Gao 695f4c96b7SSong GaoNote: To build the release version of the bios, set --buildtarget=RELEASE, 705f4c96b7SSong Gao the bios file path: Build/LoongArchQemu/RELEASE_GCC5/FV/QEMU_EFI.fd 715f4c96b7SSong Gao 725f4c96b7SSong Gao(4) Build kernel: 735f4c96b7SSong Gao 745f4c96b7SSong Gao.. code-block:: bash 755f4c96b7SSong Gao 765f4c96b7SSong Gao git clone https://github.com/loongson/linux.git 775f4c96b7SSong Gao 785f4c96b7SSong Gao cd linux 795f4c96b7SSong Gao 805f4c96b7SSong Gao git checkout loongarch-next 815f4c96b7SSong Gao 825f4c96b7SSong Gao make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- loongson3_defconfig 835f4c96b7SSong Gao 845f4c96b7SSong Gao make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- -j32 855f4c96b7SSong Gao 865f4c96b7SSong GaoNote: The branch of linux source code is loongarch-next. 875f4c96b7SSong Gao the kernel file: arch/loongarch/boot/vmlinuz.efi 885f4c96b7SSong Gao 895f4c96b7SSong Gao(5) Get initrd: 905f4c96b7SSong Gao 915f4c96b7SSong Gao You can use busybox tool and the linux modules to make a initrd file. Or you can access the 925f4c96b7SSong Gao binary files: https://github.com/yangxiaojuan-loongson/qemu-binary 935f4c96b7SSong Gao 945f4c96b7SSong Gao.. code-block:: bash 955f4c96b7SSong Gao 965f4c96b7SSong Gao git clone https://github.com/yangxiaojuan-loongson/qemu-binary 975f4c96b7SSong Gao 985f4c96b7SSong GaoNote: the initrd file is ramdisk 995f4c96b7SSong Gao 1005f4c96b7SSong Gao(6) Booting LoongArch: 1015f4c96b7SSong Gao 1025f4c96b7SSong Gao.. code-block:: bash 1035f4c96b7SSong Gao 1045f4c96b7SSong Gao $ ./build/qemu-system-loongarch64 -machine virt -m 4G -cpu la464 \ 1055f4c96b7SSong Gao -smp 1 -bios QEMU_EFI.fd -kernel vmlinuz.efi -initrd ramdisk \ 1065f4c96b7SSong Gao -serial stdio -monitor telnet:localhost:4495,server,nowait \ 1075f4c96b7SSong Gao -append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" \ 1085f4c96b7SSong Gao --nographic 109