1,下载systemc-2.3.1
下载网址:
cpp
$ wget https://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.1.tgz

2,编译安装 systemc-2.3.1
bash
tar zxf systemc-2.3.1.tgz
cd systemc-2.3.1/
export CXX=g++
mkdir build
cd build/
mkdir /home/hipper/ex_systemc_qemu/toolchain/SystemC # who i am -> hipper
export CXX=g++
../configure --prefix=/home/hipper/ex_systemc_qemu/toolchain/SystemC
make -j
make install
ls /home/hipper/ex_systemc_qemu/toolchain/SystemC

3,下载 demo
3.1 下载
打开:
bash
https://caslab.ee.ncku.edu.tw/dokuwiki/course:ca:106

wget 之:
bash
$ wget https://caslab.ee.ncku.edu.tw/dokuwiki/_media/course:ca:106a:ca_lab_attachedfiles.zip
3.2 解压编译
$ unzip course\:ca\:106a\:ca_lab_attachedfiles.zip
$ cd CA_LAB_AttachedFiles/
$ unzip LAB4.zip
$ cd LAB4/
$ ls

$ cd SystemC_Module/
$ vim makefile
修改: CXX 和 SYSTEMC_DIR 的值;
bash
CXX :=g++ -std=c++11
SYSTEMC_DIR :=/home/hipper/ex_systemc_qemu/toolchain/SystemC
$ make -j
$ ls

3.3 运行demo
$ export LD_LIBRARY_PATH=/home/hipper/ex_systemc_qemu/toolchain/SystemC/lib-linux64
$ ./qsysbridge

4,源码安装 qemu-arm
一堆普通用户命令:
git clone https://github.com/qemu/qemu.git
cd qemu/
git checkout v9.0.0
mkdir build_v9_arm/
cd ../build_v9_arm/
../configure --target-list="arm-softmmu,arm-linux-user" --prefix=/home/hipper/ex_systemc_qemu/qemu-bin-v9-arm
make -j
make install
$ ls /home/hipper/ex_systemc_qemu/qemu-bin-v9-arm

其中,qemu-arm 由配置选项 arm-linux-user 指定;
而 qemu-system-arm 由qemu编译前配置选项 arm-softmmu 指定。
5,在qemu中安装Linux
5.1 获得x86上的cross arm-gcc
5.1.1 安装
bash
$ sudo apt-get install gcc-arm-linux-gnueabi
#check
$ dpkg -l gcc-arm-linux-gnueabi
5.1.2 测试 arm-gcc 和 qemu-arm
实例代码
hello.c
cpp
#include <stdio.h>
int main()
{
printf("Hello world!!!!!\n");
return 0;
}
编译:
cpp
$ arm-linux-gnueabi-gcc hello.c -o hello
设置:
error1:
qemu-arm: Could not open '/lib/ld-linux.so.3': No such file or directory
$ sudo find /usr/ -name ld-linux.so.3
/usr/arm-linux-gnueabihf/lib/ld-linux.so.3
/usr/arm-linux-gnueabi/lib/ld-linux.so.3
error2:

$ sudo find /usr/ -name libc.so.6
/usr/arm-linux-gnueabihf/lib/libc.so.6
/usr/arm-linux-gnueabi/lib/libc.so.6
/usr/lib/i386-linux-gnu/libc.so.6
/usr/lib/x86_64-linux-gnu/libc.so.6
bash
$ sudo cp /usr/arm-linux-gnueabi/lib/ld-linux.so.3 /lib/
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/arm-linux-gnueabi/lib
这个 /lib/ld-linux.so.3 测试结束后可以删掉
运行:
bash
$ ../qemu-bin-v9-arm/bin/qemu-arm -L /usr/lib/gcc-cross/arm-linux-gnueabi/11/ -L /usr/arm-linux-gnueabi/lib/ ./hello
效果:

5.2 下载编译 Linux kernel
bash
$ wget https://github.com/torvalds/linux/archive/refs/tags/v5.10.tar.gz
$ tar zxf v5.10.tar.gz
$ cd linux-5.10/
./linux-5.10$ cp ../../CA_LAB_AttachedFiles/LAB3/kernel/config-4.14.85-realview-arm1136 ./.config
/linux-5.10$ make ARCH=arm menuconfig
<Exit>
./linux-5.10$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
//## or seprated steps:
./linux-5.10$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j zImage
./linux-5.10$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm dtbs
使用了一个非常简单的arm arch 的config 文件:
./linux-5.10$ cp ../../CA_LAB_AttachedFiles/LAB3/kernel/config-4.14.85-realview-arm1136 ./.config
编译结果:

device tree of arm-realview-eb.dtb

5.3 下载编译 busybox
使用 wget 下载,配置方式可以宽松一点,直接 make menuconfig ARCH=arm,然后使用交叉编译器编译
bash
$ wget https://busybox.net/downloads/busybox-1.35.0.tar.bz2
$ cd ./busybox-1.35.0/
$ make ARCH=arm menuconfig
<Exit>
<Yes>
$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
编译结果:

bash
$ make install CROSS_COMPILE=arm-linux-gnueabi-
$ ls _install/

5.4 Building Initrd ramdisk
5.4.1 准备文件
bash
cd _install/
cp ../../../CA_LAB_AttachedFiles/LAB3/busybox/etc.tar.gz ./
tar zxf etc.tar.gz
ls etc

将 命令
$ ../qemu-bin-v9-arm/bin/qemu-arm -L /usr/lib/gcc-cross/arm-linux-gnueabi/11/ -L /usr/arm-linux-gnueabi/lib/ ./hello
中通过 -L 暴露给qemu-arm 的 .so 文件,别忘记 ld-linux.so.3,全部拷贝到 _install/lib/ 中:
bash
$ mkdir lib
$ cp -r /usr/lib/gcc-cross/arm-linux-gnueabi/11/* ./
$ cp -r /usr/arm-linux-gnueabi/lib/* ./
$ cp /usr/arm-linux-gnueabi/lib/ld-linux.so.3 ./
5.4.2 制作 initrd.gz
bash
$ cd ./_install/
$ find . | cpio --create --format=newc > ../initrd
$ gzip -f ../initrd
$ ls ../initrd.gz -all -h

5.5 QEMU 中启动 Linux
必须的文件:
qemu-system-arm, zImage, initrd.gz arm-realview-eb.dtb
bash
//# qemu-system-arm:
./qemu-bin-v9-arm/bin/qemu-system-arm
//# zImage:
./uboot_kernel/linux-5.10/arch/arm/boot/zImage
//# Initrd.gz:
./uboot_kernel/busybox-1.35.0/initrd.gz
//# Device tree:
./uboot_kernel/linux-5.10/arch/arm/boot/dts/arm-realview-eb.dtb
启动Linux:
bash
../qemu-bin-v9-arm/bin/qemu-system-arm \
-M realview-eb \
-m 128M \
-cpu arm1136 \
-kernel ../uboot_kernel/linux-5.10/arch/arm/boot/zImage \
-initrd ../uboot_kernel/busybox-1.35.0/initrd.gz \
-nographic -serial mon:stdio \
-dtb ../uboot_kernel/linux-5.10/arch/arm/boot/dts/arm-realview-eb.dtb
保持内存数量为 -m 128M \
文件系统问题,导致出错:

Errors:

再看看。。。
构建qemu和vexpress 板子的仿真环境:
#!/usr/bin/bash
mkdir workspace2
cd workspace2
WORK_DIR=${PWD}
git clone https://github.com/qemu/qemu.git
cd qemu/
git checkout v9.0.0
mkdir ./build_arm/
cd ./build_arm/
../configure --target-list="arm-softmmu,arm-linux-user" --prefix=${WORK_DIR}/qemu-bin-arm/
make -j
make install
cd ../../
sudo ls
sudo apt-get install gcc-arm-linux-gnueabi
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.10.tar.gz
tar zxf linux-5.10.tar.gz
cd linux-5.10/
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
cd ../
wget https://ftp.denx.de/pub/u-boot/u-boot-2020.10.tar.bz2
tar xf u-boot-2020.10.tar.bz2
cd u-boot-2020.10/
make vexpress_ca9x4_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- all
cd ../
wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
tar xf busybox-1.36.0.tar.bz2
cd busybox-1.36.0/
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make install CROSS_COMPILE=arm-linux-gnueabi-
cd ../
mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
sudo cp busybox-1.36.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
mkfs.ext3 a9rootfs.ext3
sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/* tmpfs/ && sudo umount tmpfs
${WORK_DIR}/qemu-bin-arm/bin/qemu-system-arm -M vexpress-a9 -m 512M \
-kernel ./linux-5.10/arch/arm/boot/zImage \
-dtb ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3
vexpress 平台结构:
从 这份文档中《ARM® CoreTile Express A9×4 Cortex®-A9 MPCore (V2P-CA9) Technical Reference Manual》发现如下内存布局:


添加硬件:
添加 LKM:
添加 app:
重建系统
在qemu中添加硬件,在linux中添加LKM,在用户态添加app后,重新编译整个系统:
update_buildup.sh
#!/usr/bin/bash
#mkdir workspace2
cd workspace2
WORK_DIR=${PWD}
#git clone https://github.com/qemu/qemu.git
cd qemu/
#git checkout v9.0.0
#mkdir build_arm/
cd ../build_arm/
#../configure --target-list="arm-softmmu,arm-linux-user" --prefix=${WORK_DIR}/qemu-bin-arm/
make -j
make install
cd ../
sudo ls
#sudo apt-get install gcc-arm-linux-gnueabi
#wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.10.tar.gz
#tar zxf linux-5.10.tar.gz
cd linux-5.10/
#make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
cd ../
#wget https://ftp.denx.de/pub/u-boot/u-boot-2020.10.tar.bz2
#tar xf u-boot-2020.10.tar.bz2
#cd u-boot-2020.10/
#make vexpress_ca9x4_defconfig
#make CROSS_COMPILE=arm-linux-gnueabi- all
#cd ../
#wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
#tar xf busybox-1.36.0.tar.bz2
#cd busybox-1.36.0/
#make defconfig
#make CROSS_COMPILE=arm-linux-gnueabi-
#make install CROSS_COMPILE=arm-linux-gnueabi-
#cd ../
#mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
#sudo cp busybox-1.36.0/_install/* -r rootfs/
#sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
#sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
rm a9rootfs.ext3
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
mkfs.ext3 a9rootfs.ext3
sudo mkdir -p tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/* tmpfs/ && sudo umount tmpfs
${WORK_DIR}/qemu-bin-arm/bin/qemu-system-arm -M vexpress-a9 -m 512M \
-kernel ./linux-5.10/arch/arm/boot/zImage \
-dtb ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3