搭建 Loongarch-Linux 模拟环境

搭建 LA-Linux 模拟环境

尝试使用 qemu 模拟 loongarch 环境来运行社区版本的 linux 操作系统,结合开源提供的代码和文档做这个实验。应该需要准备

wangjianfeng@dev:~/virtual/loongarch-linux$ tree -L 1
.
├── boot-qemu.sh
├── pc-bios
├── QEMU_EFI.fd
├── qemu-system-loongarch64
├── ramdisk
└── vmlinux.efi

1 directory, 5 files

1 交叉编译器

cd /opt/tools/cross-tools/
wget https://github.com/loongson/build-tools/releases/download/2022.08.11/loongarch64-clfs-5.1-cross-tools-gcc-glibc.tar.xz
tar xvf loongarch64-clfs-5.1-cross-tools-gcc-glibc.tar.xz

# echo "export PATH=/opt/tools/cross-tools/bin:$PATH" >> ~/.bashrc
# source ~/.bashrc

2 bios 固件

2.1 下载

git clone https://github.com/loongson/edk2-LoongarchVirt.git
git checkout --track origin/LoongArch

cd edk2-LoongarchVirt

git submodule update --init

2.2 编译

#! /bin/bash

CC_PREFIX=/opt/tools/cross-tools/

export PATH=${CC_PREFIX}/bin:$PATH
export WORKSPACE=`pwd`
export PACKAGES_PATH=$WORKSPACE/edk2-LoongarchVirt
export GCC5_LOONGARCH64_PREFIX=loongarch64-unknown-linux-gnu-

source edk2-LoongarchVirt/edksetup.sh
make -C edk2-LoongarchVirt/BaseTools

build --buildtarget=DEBUG --tagname=GCC5 --arch=LOONGARCH64  --platform=OvmfPkg/LoongArchQemu/Loongson.dsc
build --buildtarget=RELEASE --tagname=GCC5 --arch=LOONGARCH64  --platform=OvmfPkg/LoongArchQemu/Loongson.dsc

编译前源码中默认放置了 QEMU_EFI.fd_debug 和 QEMU_EFI.fd_release。编译后得到文件 “QEMU_EFI.fd”。

3 linux 内核

3.1 下载

git clone git@github.com:loongson/linux.git
git checkout --track origin/loongarch-next

3.2 编译

#! /bin/bash

CC_PREFIX=/opt/tools/cross-tools/

export PATH="$PATH:${CC_PREFIX}/bin:PATH"
export LD_LIBRARY_PATH="${CC_PREFIX}/lib:$LD_LIBRARY_PATH"

make ARCH=loongarch clean
make ARCH=loongarch defconfig
#make ARCH=loongarch menuconfig
make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- -j8

#make modules_install ARCH=loongarch CROSS_COMPILE=loongarch64-linux-gnu- INSTALL_MOD_PATH=./modules

#cp vmlinux vmlinux-public
#tar zcf modules.tar.gz  modules vmlinu* System.map

得到 efi 文件 “vmlinux.efi”

4 qemu 程序

4.1 下载

git@github.com:loongson/qemu.git

4.2 编译

./configure --disable-rdma --disable-pvrdma \
            --target-list="loongarch64-softmmu" \
            --disable-libiscsi --disable-libnfs --disable-libpmem \
            --disable-glusterfs --enable-libusb --enable-usb-redir \
            --disable-opengl --disable-xen --enable-spice \
            --enable-debug --disable-capstone --disable-kvm \
            --enable-profiler

make

# make install

得到 efi 文件 “qemu-system-loongarch64” 和 pc-bios 文件包

5 initrd 文件

N/A

6 运行脚本

6.1 准备

#!/bin/bash
./qemu-system-loongarch64  -L ./pc-bios \
	-m 4G -smp 1 --cpu la464 --machine virt \
	-bios ./QEMU_EFI.fd \
	-kernel ./vmlinux.efi \
	-serial stdio \
	-monitor telnet:localhost:4495,server,nowait \
	-initrd ./ramdisk \
	-append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" --nographic

6.2 运行

wangjianfeng@dev:~/virtual/loongarch-linux$ ./boot-qemu.sh
....
....
[    3.409556] This architecture does not have kernel memory protection.
[    3.409939] Run /sbin/init as init process
/ # poweroff

7 参考资料

  • https://github.com/loongson/qemu/blob/master/docs/system/loongarch/loongson3.rst#loongson3-virt-generic-platform-virt

  • https://github.com/yangxiaojuan-loongson/qemu-binary

  • https://github.com/loongson/build-tools

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hinzer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值