Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ Source code catalog description:

### Configure Toolchain

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.
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.

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

```
python get_toolchain.py riscv64
```

In the userapps directory, run smart-env.bat to configure the toolchain path, and the currently supported parameter is arm | riscv64
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

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

### Make QEMU SD Card

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.
#### FAT
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.

#### EXT4
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

![img](figures/build_sd1.png)

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

### zlib1.dll missing prompted while scons

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/
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/
10 changes: 7 additions & 3 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ git clone https://github.com/RT-Thread/userapps.git

### 配置工具链

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

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

```
python get_toolchain.py riscv64
```

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

```
smart-env.bat riscv64
Expand Down Expand Up @@ -68,13 +68,17 @@ smart-env.bat riscv64

### 制作QEMU SD卡

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

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

1.

![img](figures/build_sd1.png)

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

### 运行QEMU

Expand Down
149 changes: 149 additions & 0 deletions prebuilt/qemu-virt64-aarch64-ext4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# 基于 EXT4 文件系统的 RT-Smart 用户态应用开发

> 本文档环境为 `ubuntu 20.04`

## 环境准备

### 仓库

`RT-Smart` 软件开源在 `https://github.com/RT-Thread/rt-thread.git` 本 `bsp` 的源码在 `https://github.com/RT-Thread/rt-thread/tree/master/bsp/qemu-virt64-aarch64`

请 `clone` 此仓库以进行开发:

```shell
git clone https://github.com/RT-Thread/rt-thread.git
```

### pkgs

pkgs 是 RT-Smart 的包管理软件,

```shell
mkdir -pv ~/.env/tools/
git clone https://gitee.com/RT-Thread-Mirror/env.git ~/.env/tools/scripts
export PATH=~/.env/tools/scripts:$PATH:$RTT_EXEC_PATH
```

### 添加 EXT4 软件包

EXT4 是作为 RT-Smart 的一个软件包,因此我们需要使用 pkgs 去管理下载 EXT4 软件包

首先进入 `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`

执行 `pkgs --update` 以下载软件包(需确保已将 `pkgs` 添加置环境变量)

### 修改 SD 卡挂载方式

将 `bsp` 的 `sd` 卡的挂载文件系统代码(`bsp/qemu-virt64-aarch64/applications/mnt.c`)修改为 ext 文件系统

```c
int mnt_init(void)
{
if (rt_device_find("virtio-blk0"))
{
/* mount virtio-blk as root directory */
if (dfs_mount("virtio-blk0", "/", "ext", 0, RT_NULL) == 0)
{
rt_kprintf("file system initialization done!\n");
}
}

return 0;
}
INIT_ENV_EXPORT(mnt_init);
```

### 工具链

首先进入到 `tools` 文件夹,下载工具链:

```shell
python3 get_toolchain.py aarch64
```

## 内核编译

先在 `userapps` 目录下执行以下命令将编译器信息添加到环境变量

```shell
source smart-env.sh aarch64
```

随后进入 `bsp` 目录进行编译

```shell
scons -j8
```

将编译生成的产物复制到 `userapps` 目录下的 `prebuilt/qemu-virt64-aarch64-ext4/rtthread.bin` 处

## 用户态编译

先在 `userapps` 目录下执行以下命令将编译器信息添加到环境变量

```shell
source smart-env.sh aarch64
```

随后直接在此目录执行编译命令即可编译事先准备好的用户态示例

```shell
scons -j8 --verbose
```

产物存放在 `root/bin` 目录下

## sd 卡打包

在 `userapps` 目录执行以下命令将 `root` 目录打包成一个 `500M` 大小的镜像包并放入 `prebuilt/qemu-virt64-aarch64-ext4/rootfs.img`

```
tools/make_ext4fs/make_ext4fs -l 500M prebuilt/qemu-virt64-aarch64-ext4/rootfs.img root
```

## 运行 qemu

在 `userapps` 目录下的 `prebuilt/qemu-virt64-aarch64-ext4` 目录执行 `qemu.sh` 以运行 qemu

随后可以执行 `bin/hello.elf` 看是否正确输出`hello world!`字样

```log
# ./qemu.sh
[I/libcpu.aarch64.cpu] Using MPID 0x0 as cpu 0
[I/libcpu.aarch64.cpu] Using MPID 0x1 as cpu 1
[I/libcpu.aarch64.cpu] Using MPID 0x2 as cpu 2
[I/libcpu.aarch64.cpu] Using MPID 0x3 as cpu 3

\ | /
- RT - Thread Smart Operating System
/ | \ 5.0.0 build Mar 24 2023 15:02:31
2006 - 2022 Copyright by RT-Thread team
lwIP-2.0.3 initialized!
[I/sal.skt] Socket Abstraction Layer initialize success.
file system initialization done!
[I/libcpu.aarch64.cpu] Secondary CPU 1 booted
[I/libcpu.aarch64.cpu] Secondary CPU 2 booted
[I/libcpu.aarch64.cpu] Secondary CPU 3 booted
msh />hello rt-thread

msh />ls
Directory /:
. <DIR>
.. <DIR>
lost+found <DIR>
bin <DIR>
msh />b
msh />bin/
.
..
hello.elf
ping.elf
pong.elf
umailbox.elf
vi.elf
webclient.elf
webserver.elf
msh />bin/he
msh />bin/hello.elf
msh />hello world!
```
7 changes: 7 additions & 0 deletions prebuilt/qemu-virt64-aarch64-ext4/qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if [ ! -f "rootfs.img" ]; then
dd if=/dev/zero of=rootfs.img bs=1024 count=65536
fi
qemu-system-aarch64 -M virt,gic-version=2 -cpu cortex-a53 -m 128M -smp 4 -kernel rtthread.bin -nographic \
-drive if=none,file=rootfs.img,format=raw,id=blk0 -device virtio-blk-device,drive=blk0,bus=virtio-mmio-bus.0 \
-netdev user,id=net0 -device virtio-net-device,netdev=net0,bus=virtio-mmio-bus.1 \
-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
Binary file added prebuilt/qemu-virt64-aarch64-ext4/rtthread.bin
Binary file not shown.
Binary file added sdk/rt-thread/lib/aarch64/cortex-a/librtthread.a
Binary file not shown.
Binary file added sdk/rt-thread/lib/aarch64/cortex-a/librtthread.so
Binary file not shown.
2 changes: 1 addition & 1 deletion smart-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ supported_arch="arm aarch64 riscv64"

def_arch="unknown"

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

# find arch in arch list
if [ -z $1 ]
Expand Down
Binary file added tools/make_ext4fs/make_ext4fs
Binary file not shown.