Skip to content

Commit b5f7fbb

Browse files
committed
📃 docs(prebuilt/qemu-virt64-aarch64-ext4/README.md): add README.md
1 parent 08b90c6 commit b5f7fbb

1 file changed

Lines changed: 149 additions & 0 deletions

File tree

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+
```

0 commit comments

Comments
 (0)