buildroot编译一个基于riscv架构的linux系统

1、https://toolchains.bootlin.com. 下載工具鏈,並配置PATH,注意此処使用root權限配置
2、内核編譯:
make ARCH=riscv CROSS_COMPILE=riscv64-linux- defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux- -j $(nproc)

3、opensbi編譯
git clone https://github.com/riscv-software-src/opensbi.git
export CROSS_COMPILE=riscv64-linux-
make PLATFORM=generic

4、rootfs(也可以在buildroot中选择内核编译)
https://buildroot.org/download.html

make defconfig
make menuconfig
配置目標架構為riscv
配置image文件格式為ext2/3/4

//編譯會聯網
make -j$(nproc)

生成文件在output/images下,rootfs.ext2

這裏也可以下載busybox:
git clone https://git.busybox.net/busybox
cd busybox
CROSS_COMPILE=riscv{{bits}}-unknown-linux-gnu- make defconfig
CROSS_COMPILE=riscv{{bits}}-unknown-linux-gnu- make -j $(nproc)

5、運行
sudo qemu-system-riscv64 -nographic -machine virt
-kernel linux/arch/riscv/boot/Image -append “root=/dev/vda ro console=ttyS0”
-drive file=busybox,format=raw,id=hd0
-device virtio-blk-device,drive=hd0

相關鏈接:
https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html#:~:text=Build%20Linux%20for%20the%20RISC-V%20target.%20First%2C%20checkout,riscv%20CROSS_COMPILE%3D%20riscv64-unknown-linux-gnu-%20defconfig%20Then%20compile%20the%20kernel%3A

你可能感兴趣的:(linux,linux)