xref: /qemu/docs/system/loongarch/virt.rst (revision 5eb0849562c9b6988b620493dbea6421e31bfc33)
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:
15*1267e1ddSBibo Mao
16*1267e1ddSBibo Mao* Gpex host bridge
17*1267e1ddSBibo Mao* Ls7a RTC device
18*1267e1ddSBibo Mao* Ls7a IOAPIC device
19*1267e1ddSBibo Mao* ACPI GED device
20*1267e1ddSBibo Mao* Fw_cfg device
21*1267e1ddSBibo Mao* PCI/PCIe devices
22*1267e1ddSBibo Mao* Memory device
23*1267e1ddSBibo Mao* CPU device. Type: la464.
245f4c96b7SSong Gao
255f4c96b7SSong GaoCPU and machine Type
265f4c96b7SSong Gao--------------------
275f4c96b7SSong Gao
285f4c96b7SSong GaoThe ``qemu-system-loongarch64`` provides emulation for virt
295f4c96b7SSong Gaomachine. You can specify the machine type ``virt`` and
305f4c96b7SSong Gaocpu type ``la464``.
315f4c96b7SSong Gao
325f4c96b7SSong GaoBoot options
335f4c96b7SSong Gao------------
345f4c96b7SSong Gao
355f4c96b7SSong GaoWe can boot the LoongArch virt machine by specifying the uefi bios,
365f4c96b7SSong Gaoinitrd, and linux kernel. And those source codes and binary files
375f4c96b7SSong Gaocan be accessed by following steps.
385f4c96b7SSong Gao
395f4c96b7SSong Gao(1) Build qemu-system-loongarch64:
405f4c96b7SSong Gao
415f4c96b7SSong Gao.. code-block:: bash
425f4c96b7SSong Gao
43*1267e1ddSBibo Mao  ./configure --target-list="loongarch64-softmmu"
445f4c96b7SSong Gao  make -j8
455f4c96b7SSong Gao
465f4c96b7SSong Gao(2) Set cross tools:
475f4c96b7SSong Gao
485f4c96b7SSong Gao.. code-block:: bash
495f4c96b7SSong Gao
505f4c96b7SSong Gao  wget https://github.com/loongson/build-tools/releases/download/2022.09.06/loongarch64-clfs-6.3-cross-tools-gcc-glibc.tar.xz
515f4c96b7SSong Gao  tar -vxf loongarch64-clfs-6.3-cross-tools-gcc-glibc.tar.xz  -C /opt
525f4c96b7SSong Gao  export PATH=/opt/cross-tools/bin:$PATH
535f4c96b7SSong Gao  export LD_LIBRARY_PATH=/opt/cross-tools/lib:$LD_LIBRARY_PATH
545f4c96b7SSong Gao  export LD_LIBRARY_PATH=/opt/cross-tools/loongarch64-unknown-linux-gnu/lib/:$LD_LIBRARY_PATH
555f4c96b7SSong Gao
565f4c96b7SSong GaoNote: You need get the latest cross-tools at https://github.com/loongson/build-tools
575f4c96b7SSong Gao
585f4c96b7SSong Gao(3) Build BIOS:
595f4c96b7SSong Gao
60b883fb93SXianglai Li    See: https://github.com/tianocore/edk2/tree/master/OvmfPkg/LoongArchVirt#readme
615f4c96b7SSong Gao
625f4c96b7SSong GaoNote: To build the release version of the bios,  set --buildtarget=RELEASE,
635f4c96b7SSong Gao      the bios file path:  Build/LoongArchQemu/RELEASE_GCC5/FV/QEMU_EFI.fd
645f4c96b7SSong Gao
655f4c96b7SSong Gao(4) Build kernel:
665f4c96b7SSong Gao
675f4c96b7SSong Gao.. code-block:: bash
685f4c96b7SSong Gao
695f4c96b7SSong Gao  git clone https://github.com/loongson/linux.git
705f4c96b7SSong Gao  cd linux
715f4c96b7SSong Gao  git checkout loongarch-next
725f4c96b7SSong Gao  make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- loongson3_defconfig
735f4c96b7SSong Gao  make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- -j32
745f4c96b7SSong Gao
755f4c96b7SSong GaoNote: The branch of linux source code is loongarch-next.
765f4c96b7SSong Gao      the kernel file: arch/loongarch/boot/vmlinuz.efi
775f4c96b7SSong Gao
785f4c96b7SSong Gao(5) Get initrd:
795f4c96b7SSong Gao
805f4c96b7SSong Gao  You can use busybox tool and the linux modules to make a initrd file. Or you can access the
815f4c96b7SSong Gao  binary files: https://github.com/yangxiaojuan-loongson/qemu-binary
825f4c96b7SSong Gao
835f4c96b7SSong Gao.. code-block:: bash
845f4c96b7SSong Gao
855f4c96b7SSong Gao  git clone https://github.com/yangxiaojuan-loongson/qemu-binary
865f4c96b7SSong Gao
875f4c96b7SSong GaoNote: the initrd file is ramdisk
885f4c96b7SSong Gao
895f4c96b7SSong Gao(6) Booting LoongArch:
905f4c96b7SSong Gao
915f4c96b7SSong Gao.. code-block:: bash
925f4c96b7SSong Gao
935f4c96b7SSong Gao  $ ./build/qemu-system-loongarch64 -machine virt -m 4G -cpu la464 \
945f4c96b7SSong Gao      -smp 1 -bios QEMU_EFI.fd -kernel vmlinuz.efi -initrd ramdisk \
955f4c96b7SSong Gao      -serial stdio   -monitor telnet:localhost:4495,server,nowait \
965f4c96b7SSong Gao      -append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" \
975f4c96b7SSong Gao      --nographic
98