[bsp][allwinner] 增加 D1s QEMU 启动脚本 (#11903)

为 D1s BSP 提供匹配虚拟机参数的 QEMU 启动入口。
This commit is contained in:
Chen Moushun authored and GitHub committed 2026-11-05 11:16:29 +08:00
1 parent 4d1e4e58f0
commit d42ffde1b5
4 files changed
+145

No files matched your search

+30
View File
@@ -2,3 +2,33 @@
* [基于柿饼M7运行 RT-Smart](./README-M7.md)
* [基于麻雀MQ运行 RT-Smart](./README-MQ.md)
* [在 QEMU 中运行(Run on QEMU)](#在-qemu-中运行run-on-qemu)
## 在 QEMU 中运行(Run on QEMU)
没有板子时,可以用 [d1s-qemu](https://github.com/cms19859230182-lang/d1s-qemu)
提供的 QEMU `d1s` 机型启动本 BSP 编出的 `rtthread.bin`:
```sh
# 1. 编译 d1s-qemu(见该仓库 README)
git clone https://github.com/cms19859230182-lang/d1s-qemu
cd d1s-qemu && scripts/fetch-qemu.sh && scripts/apply-patches.sh && scripts/build.sh
# 2. 在本目录编译 RT-Thread(工具链见 README-M7.md;也可用环境变量指定,例如
# RTT_EXEC_PATH=/path/to/toolchain/bin RTT_CC_PREFIX=riscv64-linux-musleabi-)
scons
# 3. 启动(UART0 接到终端)
D1S_QEMU_DIR=/path/to/d1s-qemu ./qemu-d1s.sh
```
当前状态:默认配置下能打印 RT-Thread Smart 启动信息,完成 SD/MMC(SMHC0/SMHC1,
`run.sh` 自动挂空白镜像)初始化并进入 `msh />`;空白镜像没有文件系统,根文件系统挂载失败属正常现象。
更完整的步骤与常见失败见 [target-qemu/](./target-qemu/)(`run-qemu.sh` + README)。
Without a board, `rtthread.bin` from this BSP can be started on the `d1s`
machine of d1s-qemu with `D1S_QEMU_DIR=/path/to/d1s-qemu ./qemu-d1s.sh`.
The RT-Thread Smart banner is printed, SD/MMC (SMHC0/SMHC1, blank images
attached by run.sh) is probed and the boot reaches `msh />`. Mounting the root
file system fails on the blank images, which is expected.
See [target-qemu/](./target-qemu/) for the fuller guide (`run-qemu.sh` + README).
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
# Kept for compatibility; see target-qemu/run-qemu.sh
exec "$(cd "$(dirname "$0")" && pwd)/target-qemu/run-qemu.sh" "$@"
+68
View File
@@ -0,0 +1,68 @@
# D1s on QEMU (for humans and AI agents)
This directory boots the `bsp/allwinner/d1s` image on the d1s QEMU machine
(<https://github.com/cms19859230182-lang/d1s-qemu>). It's written as a short
step-by-step guide that an AI coding agent can follow without guessing.
## 1. Prepare the QEMU environment
```sh
git clone https://github.com/cms19859230182-lang/d1s-qemu
cd d1s-qemu
# follow its README to build; the result must provide an executable ./run.sh
export D1S_QEMU_DIR=$PWD
```
Check: `test -x "$D1S_QEMU_DIR/run.sh" && echo ok`.
## 2. Build the BSP
```sh
cd rt-thread/bsp/allwinner/d1s
export RTT_EXEC_PATH=/path/to/riscv64-unknown-elf/bin # RISC-V toolchain
scons -j$(nproc)
```
Check: `rtthread.bin` exists in `bsp/allwinner/d1s/`. `sbi.bin` and
`u-boot.dtb` are already in the BSP directory, and `run.sh` uses them.
## 3. Run
Interactive:
```sh
./target-qemu/run-qemu.sh
```
Non-interactive smoke test (recommended for agents, always set a timeout):
```sh
QEMU_TIMEOUT=30 ./target-qemu/run-qemu.sh < /dev/null > qemu.log 2>&1 || true
```
Extra arguments are passed through to d1s-qemu's `run.sh`.
## 4. Pass/fail criteria
- **Pass:** `qemu.log` contains the RT-Thread banner (` \ | /`) and the
`msh />` prompt.
- Optional interactive check: at `msh />` run `list_thread` and `version`.
- Exit code 124 just means the timeout was reached. That's normal for a
smoke test, so judge the run by the log, not the exit code.
```sh
grep -q 'msh />' qemu.log && echo PASS || echo FAIL
```
## 5. Common failures
| Symptom | Cause / fix |
|---|---|
| `please set D1S_QEMU_DIR ...` | Export `D1S_QEMU_DIR` pointing at a *built* d1s-qemu checkout. |
| `rtthread.bin not found` | Run `scons` in `bsp/allwinner/d1s` first. |
| No output at all | Wrong console: this BSP uses UART0, and the script already passes `--console uart0`. Also check that the build succeeded and isn't stale. |
| Hangs after OpenSBI banner | `sbi.bin` or `u-boot.dtb` is missing or mismatched in the BSP directory, or the image was linked for the wrong address. |
| Agent session hangs | You forgot `QEMU_TIMEOUT`. Always set it when running non-interactively. |
The old entry point `bsp/allwinner/d1s/qemu-d1s.sh` still works as a thin
wrapper around this script.
+44
View File
@@ -0,0 +1,44 @@
#!/bin/sh
#
# Copyright (c) 2006-2026, RT-Thread Development Team
#
# SPDX-License-Identifier: Apache-2.0
#
# Boot this BSP's rtthread.bin on the d1s QEMU machine from
# https://github.com/cms19859230182-lang/d1s-qemu
#
# Usage (after building d1s-qemu and running scons in bsp/allwinner/d1s):
# D1S_QEMU_DIR=/path/to/d1s-qemu ./target-qemu/run-qemu.sh [run.sh options]
#
# Environment:
# D1S_QEMU_DIR built d1s-qemu checkout (must contain executable run.sh)
# QEMU_TIMEOUT seconds before QEMU is killed (default 0 = no limit,
# set e.g. 30 for CI / AI smoke tests)
#
# sbi.bin and u-boot.dtb are taken from the BSP directory; the console of
# this BSP is UART0, so it is connected to the terminal.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
bsp=$(cd "$here/.." && pwd)
dir=${D1S_QEMU_DIR:-}
tmo=${QEMU_TIMEOUT:-0}
if [ -z "$dir" ] || [ ! -x "$dir/run.sh" ]; then
echo "please set D1S_QEMU_DIR to a built d1s-qemu checkout" >&2
echo "see https://github.com/cms19859230182-lang/d1s-qemu" >&2
exit 1
fi
if [ ! -f "$bsp/rtthread.bin" ]; then
echo "$bsp/rtthread.bin not found, run scons in $bsp first" >&2
exit 1
fi
if [ "$tmo" -gt 0 ] 2>/dev/null; then
exec timeout --foreground "$tmo" \
"$dir/run.sh" "$bsp/rtthread.bin" --bsp "$bsp" --console uart0 "$@"
fi
exec "$dir/run.sh" "$bsp/rtthread.bin" --bsp "$bsp" --console uart0 "$@"