Skip to content

Commit b03b7cc

Browse files
authored
Merge pull request #19 from xqyjlj/qemu-virt64-aarch64-ext4-dev
qemu-virt64-aarch64 ext4 支持
2 parents 0578f82 + b5f7fbb commit b03b7cc

9 files changed

Lines changed: 172 additions & 8 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ Source code catalog description:
3131

3232
### Configure Toolchain
3333

34-
Running get_toolchain.py script in the userapps\tools directory, the corresponding toolchain will be downloaded and expanded to the userapps\tools\gun_gcc directory. The toolchain can be named arm | riscv64.
34+
Running get_toolchain.py script in the userapps\tools directory, the corresponding toolchain will be downloaded and expanded to the userapps\tools\gun_gcc directory. The toolchain can be named arm | aarch64 | riscv64.
3535

3636
In this article, we're taking the RISC-V platform as an example and entering the following command:
3737

3838
```
3939
python get_toolchain.py riscv64
4040
```
4141

42-
In the userapps directory, run smart-env.bat to configure the toolchain path, and the currently supported parameter is arm | riscv64
42+
In the userapps directory, run smart-env.bat | smart-env.sh to configure the toolchain path, and the currently supported parameter is arm | aarch64 | riscv64
4343

4444
```
4545
smart-env.bat riscv64
@@ -68,7 +68,11 @@ The QEMU version inside the Env is running an earlier version, it needs an updat
6868

6969
### Make QEMU SD Card
7070

71-
In the tools\fatdisk directory there is a tool fatdisk .exe that packages FAT format files, which we can use to package the files we want to store in the QEMU SD card into sd.bin files.
71+
#### FAT
72+
In the tools\fatdisk directory there is a tool fatdisk.exe that packages FAT format files, which we can use to package the files we want to store in the QEMU SD card into sd.bin files.
73+
74+
#### EXT4
75+
In the tools\make_ext4fs directory, there is a tool make_ext4fs for packaging EXT4 format files (linux (ubuntu) only), use the command `./make_ext4fs -l 8G rootfs.img /home/xqyjl/git/github/RT-Thread/userapps /root` to create an ext4 image
7276

7377
![img](figures/build_sd1.png)
7478

@@ -134,4 +138,4 @@ Check that if the toolchain path is correctly set, or follow this article to get
134138

135139
### zlib1.dll missing prompted while scons
136140

137-
Re-download [zlib1.dll Files](https://www.dlldownloader.com/zlib1-dll/) and place them in the C:\Windows\System32 and C:\Windows\SysWOW64 folders. https://www.githubstatus.com/
141+
Re-download [zlib1.dll Files](https://www.dlldownloader.com/zlib1-dll/) and place them in the C:\Windows\System32 and C:\Windows\SysWOW64 folders. https://www.githubstatus.com/

README_ZH.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ git clone https://github.com/RT-Thread/userapps.git
3131

3232
### 配置工具链
3333

34-
在userapps\tools目录下运行get_toolchain.py的脚本,会下载对应的工具链并展开到userapps\tools\gun_gcc目录。后面的工具链名称可以是 arm | riscv64。
34+
在userapps\tools目录下运行get_toolchain.py的脚本,会下载对应的工具链并展开到userapps\tools\gun_gcc目录。后面的工具链名称可以是 arm | aarch64 | riscv64。
3535

3636
本文以RISC-V平台为例,输入下面的命令:
3737

3838
```
3939
python get_toolchain.py riscv64
4040
```
4141

42-
在userapps目录下,运行smart-env.bat配置工具链路径,目前支持的参数可以是 arm | riscv64
42+
在userapps目录下,运行 smart-env.bat | smart-env.sh 配置工具链路径,目前支持的参数可以是 arm | aarch64 | riscv64
4343

4444
```
4545
smart-env.bat riscv64
@@ -68,13 +68,17 @@ smart-env.bat riscv64
6868

6969
### 制作QEMU SD卡
7070

71+
#### FAT
7172
在 tools\fatdisk 目录下有一个打包 FAT 格式文件的工具 fatdisk.exe,我们可以利用这个工具将我们要存储到QEMU SD卡里的文件打包成 sd.bin 文件。
7273

74+
#### EXT4
75+
在 tools\make_ext4fs 目录下有一个打包 EXT4 格式文件的工具 make_ext4fs(仅限linux(ubuntu)),使用命令 `./make_ext4fs -l 8G rootfs.img /home/xqyjl/git/github/RT-Thread/userapps/root` 即可制作ext4镜像
76+
7377
1.
7478

7579
![img](figures/build_sd1.png)
7680

77-
2. 将新生成的 sd.bin 放入userapps\prebuilt\qemu-virt64-riscv目录。
81+
2. 将新生成的 sd.bin(如果是ext4,则是 rootfs.img) 放入userapps\prebuilt\qemu-virt64-riscv目录。
7882

7983
### 运行QEMU
8084

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# 基于 EXT4 文件系统的 RT-Smart 用户态应用开发
2+
3+
> 本文档环境为 `ubuntu 20.04`
4+
5+
## 环境准备
6+
7+
### 仓库
8+
9+
`RT-Smart` 软件开源在 `https://github.com/RT-Thread/rt-thread.git``bsp` 的源码在 `https://github.com/RT-Thread/rt-thread/tree/master/bsp/qemu-virt64-aarch64`
10+
11+
`clone` 此仓库以进行开发:
12+
13+
```shell
14+
git clone https://github.com/RT-Thread/rt-thread.git
15+
```
16+
17+
### pkgs
18+
19+
pkgs 是 RT-Smart 的包管理软件,
20+
21+
```shell
22+
mkdir -pv ~/.env/tools/
23+
git clone https://gitee.com/RT-Thread-Mirror/env.git ~/.env/tools/scripts
24+
export PATH=~/.env/tools/scripts:$PATH:$RTT_EXEC_PATH
25+
```
26+
27+
### 添加 EXT4 软件包
28+
29+
EXT4 是作为 RT-Smart 的一个软件包,因此我们需要使用 pkgs 去管理下载 EXT4 软件包
30+
31+
首先进入 `bsp` 目录,也就是从 github 克隆的那个仓库,进入 `bsp/qemu-virt64-aarch64` 目录执行 `scons --menuconfig`。将 `> RT-Thread online packages > system packages > lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers.` 目录的选项激活,然后退出 `menuconfig`
32+
33+
执行 `pkgs --update` 以下载软件包(需确保已将 `pkgs` 添加置环境变量)
34+
35+
### 修改 SD 卡挂载方式
36+
37+
`bsp``sd` 卡的挂载文件系统代码(`bsp/qemu-virt64-aarch64/applications/mnt.c`)修改为 ext 文件系统
38+
39+
```c
40+
int mnt_init(void)
41+
{
42+
if (rt_device_find("virtio-blk0"))
43+
{
44+
/* mount virtio-blk as root directory */
45+
if (dfs_mount("virtio-blk0", "/", "ext", 0, RT_NULL) == 0)
46+
{
47+
rt_kprintf("file system initialization done!\n");
48+
}
49+
}
50+
51+
return 0;
52+
}
53+
INIT_ENV_EXPORT(mnt_init);
54+
```
55+
56+
### 工具链
57+
58+
首先进入到 `tools` 文件夹,下载工具链:
59+
60+
```shell
61+
python3 get_toolchain.py aarch64
62+
```
63+
64+
## 内核编译
65+
66+
先在 `userapps` 目录下执行以下命令将编译器信息添加到环境变量
67+
68+
```shell
69+
source smart-env.sh aarch64
70+
```
71+
72+
随后进入 `bsp` 目录进行编译
73+
74+
```shell
75+
scons -j8
76+
```
77+
78+
将编译生成的产物复制到 `userapps` 目录下的 `prebuilt/qemu-virt64-aarch64-ext4/rtthread.bin`
79+
80+
## 用户态编译
81+
82+
先在 `userapps` 目录下执行以下命令将编译器信息添加到环境变量
83+
84+
```shell
85+
source smart-env.sh aarch64
86+
```
87+
88+
随后直接在此目录执行编译命令即可编译事先准备好的用户态示例
89+
90+
```shell
91+
scons -j8 --verbose
92+
```
93+
94+
产物存放在 `root/bin` 目录下
95+
96+
## sd 卡打包
97+
98+
`userapps` 目录执行以下命令将 `root` 目录打包成一个 `500M` 大小的镜像包并放入 `prebuilt/qemu-virt64-aarch64-ext4/rootfs.img`
99+
100+
```
101+
tools/make_ext4fs/make_ext4fs -l 500M prebuilt/qemu-virt64-aarch64-ext4/rootfs.img root
102+
```
103+
104+
## 运行 qemu
105+
106+
`userapps` 目录下的 `prebuilt/qemu-virt64-aarch64-ext4` 目录执行 `qemu.sh` 以运行 qemu
107+
108+
随后可以执行 `bin/hello.elf` 看是否正确输出`hello world!`字样
109+
110+
```log
111+
# ./qemu.sh
112+
[I/libcpu.aarch64.cpu] Using MPID 0x0 as cpu 0
113+
[I/libcpu.aarch64.cpu] Using MPID 0x1 as cpu 1
114+
[I/libcpu.aarch64.cpu] Using MPID 0x2 as cpu 2
115+
[I/libcpu.aarch64.cpu] Using MPID 0x3 as cpu 3
116+
117+
\ | /
118+
- RT - Thread Smart Operating System
119+
/ | \ 5.0.0 build Mar 24 2023 15:02:31
120+
2006 - 2022 Copyright by RT-Thread team
121+
lwIP-2.0.3 initialized!
122+
[I/sal.skt] Socket Abstraction Layer initialize success.
123+
file system initialization done!
124+
[I/libcpu.aarch64.cpu] Secondary CPU 1 booted
125+
[I/libcpu.aarch64.cpu] Secondary CPU 2 booted
126+
[I/libcpu.aarch64.cpu] Secondary CPU 3 booted
127+
msh />hello rt-thread
128+
129+
msh />ls
130+
Directory /:
131+
. <DIR>
132+
.. <DIR>
133+
lost+found <DIR>
134+
bin <DIR>
135+
msh />b
136+
msh />bin/
137+
.
138+
..
139+
hello.elf
140+
ping.elf
141+
pong.elf
142+
umailbox.elf
143+
vi.elf
144+
webclient.elf
145+
webserver.elf
146+
msh />bin/he
147+
msh />bin/hello.elf
148+
msh />hello world!
149+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if [ ! -f "rootfs.img" ]; then
2+
dd if=/dev/zero of=rootfs.img bs=1024 count=65536
3+
fi
4+
qemu-system-aarch64 -M virt,gic-version=2 -cpu cortex-a53 -m 128M -smp 4 -kernel rtthread.bin -nographic \
5+
-drive if=none,file=rootfs.img,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \
6+
-netdev user,id=net0 -device virtio-net-device,netdev=net0,bus=virtio-mmio-bus.1 \
7+
-device virtio-serial-device -chardev socket,host=127.0.0.1,port=4321,server=on,wait=off,telnet=on,id=console0 -device virtserialport,chardev=console0
890 KB
Binary file not shown.
182 KB
Binary file not shown.
91.7 KB
Binary file not shown.

smart-env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ supported_arch="arm aarch64 riscv64"
1111

1212
def_arch="unknown"
1313

14-
SHELL_FOLDER=$(cd $(dirname $0); pwd)
14+
SHELL_FOLDER=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
1515

1616
# find arch in arch list
1717
if [ -z $1 ]

tools/make_ext4fs/make_ext4fs

1.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)