Skip to content

Commit e9f6992

Browse files
unicornxRbb666
authored andcommitted
bsp: k230: add flashsd script
Add a script to call rttpkgtool's sdcard.sh. Ths script encapsulate checking and downloading of rttpkgtool and call ./script/sdcard.sh. It also print new message so user need not learn how to use sdcard.sh. Update README.md. Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
1 parent 4fb64e3 commit e9f6992

File tree

4 files changed

+98
-46
lines changed

4 files changed

+98
-46
lines changed

bsp/k230/README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ CanMV-K230 Board Support Package 使用说明
1313
- [3.3. 下载 RT-Thread 并更新依赖的软件包](#33-下载-rt-thread-并更新依赖的软件包)
1414
- [3.4. 构建](#34-构建)
1515
- [4. 采用 rttpkgtool 对内核打包](#4-采用-rttpkgtool-对内核打包)
16-
- [5. 制作基础 SD 卡](#5-制作基础-sd-卡)
17-
- [6. 单独更新 RT-Thread 内核](#6-单独更新-rt-thread-内核)
18-
- [7. 上电启动](#7-上电启动)
16+
- [5. 烧写内核](#5-烧写内核)
17+
- [5.1. 制作基础 SD 卡](#51-制作基础-sd-卡)
18+
- [5.2. 单独更新 RT-Thread 内核](#52-单独更新-rt-thread-内核)
19+
- [6. 上电启动](#6-上电启动)
1920

2021
<!-- /TOC -->
2122

@@ -156,7 +157,14 @@ The image file is located at /home/u/ws/canaan/rt-thread/bsp/k230/rttpkgtool/out
156157

157158
如果希望重新下载 rttpkgtool 以及 opensbi,可以删除 `rt-thread/bsp/k230` 下的 `rttpkgtool` 目录后重新执行 `build.sh` 脚本即可。
158159

159-
# 5. 制作基础 SD 卡
160+
# 5. 烧写内核
161+
162+
我们采用 SD 卡方式启动开发板,基于 SD 卡烧写内核的步骤可以大致分为两步:
163+
164+
- 制作基础 SD 卡。**注意本步骤只要做一次**,以后只要单独更新 RT-Thread 内核的镜像即可。
165+
- 单独更新 RT-Thread 内核
166+
167+
## 5.1. 制作基础 SD 卡
160168

161169
在单独更新内核镜像之前,我们需要先制作一个基础的 SD 卡。可以参考 K230 RTOS Only SDK 用户指南中的 “如何编译固件”:<https://developer.canaan-creative.com/k230_rtos/zh/dev/userguide/how_to_build.html> 生成一个完整的 image。
162170

@@ -187,27 +195,32 @@ The image file is located at /home/u/ws/canaan/rt-thread/bsp/k230/rttpkgtool/out
187195

188196
然后参考 K230 RTOS Only SDK 用户指南中的 “如何烧录固件”:<https://developer.canaan-creative.com/k230_rtos/zh/dev/userguide/how_to_flash.html>, 通过 SD 卡烧录。熟悉 Windows 平台的可以使用 balenaEtcher。烧录后,SD 卡上会自动分区和格式化。
189197

190-
**注意本小节的操作只要做一次**。以后只要单独更新 RT-Thread 内核的镜像即可。
198+
## 5.2. 单独更新 RT-Thread 内核
191199

192-
# 6. 单独更新 RT-Thread 内核
193-
194-
我们可以利用 rttpkgtool 提供的脚本 `sdcard.sh` 快速更新打包后生成的内核镜像 `opensbi_rtt_system.bin`
200+
我们可以利用 rttpkgtool 提供的脚本 `sdcard.sh` 快速更新 SD 卡中打包后生成的内核镜像 `opensbi_rtt_system.bin`
195201

196202
先将 SD 卡通过 USB 读卡器接入 Ubuntu 机器。以下假设 USB 读卡器设备枚举为 `/dev/sdb`。如果不同请阅读 `sdcard.sh` 脚本代码。
197203

204+
为方便使用,在本 bsp 下提供了一份封装脚本 `flashsd.sh` 封装了对 rttpkgtool 的 `sdcard.sh` 脚本的调用。
205+
198206
```shell
199207
$ cd rt-thread/bsp/k230 # 确保在本 bsp 目录下
200-
$ ./rttpkgtool/script/sdcard.sh
201-
SRC: /home/u/ws/canaan/rt-thread/bsp/k230/rttpkgtool/output/k230_rtos_01studio_defconfig/images/opensbi/opensbi_rtt_system.bin
202-
DEST: /dev/sdb
208+
$ ./flashsd.sh
209+
BSP_PATH: /home/u/ws/canaan/rt-thread/bsp/k230
210+
rttpkgtool already exists
211+
~/ws/canaan/rt-thread/bsp/k230/rttpkgtool ~/ws/canaan/rt-thread/bsp/k230
212+
Already on 'for-k230'
213+
Your branch is up to date with 'origin/for-k230'.
214+
Already up to date.
215+
~/ws/canaan/rt-thread/bsp/k230
203216
[sudo] password for u:
204-
766+1 records in
205-
766+1 records out
206-
392569 bytes (393 kB, 383 KiB) copied, 0.0886941 s, 4.4 MB/s
207-
Done!
217+
767+1 records in
218+
767+1 records out
219+
393140 bytes (393 kB, 384 KiB) copied, 0.121172 s, 3.2 MB/s
220+
INFO: The kernel file has been flashed to the USB/SDcard successfully!
208221
```
209222

210-
# 7. 上电启动
223+
# 6. 上电启动
211224

212225
将 SD 卡插入 01Studio 开发板的 SD 卡槽。
213226

bsp/k230/build.sh

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
11
#!/bin/bash
22

3-
function download_rttpkgtool()
4-
{
5-
local project_path=$1
6-
local restult=$(curl -m 10 -s http://www.ip-api.com/json)
7-
local country=$(echo $restult | sed 's/.*"country":"\([^"]*\)".*/\1/')
8-
#echo "Country: $country"
9-
10-
if [ "$country" == "China" ]; then
11-
local url_rttpkgtool="https://gitee.com/unicornx/rttpkgtool.git"
12-
else
13-
local url_rttpkgtool="https://github.com/plctlab/rttpkgtool.git"
14-
fi
15-
#echo "rttpkgtool URL: ${url_rttpkgtool}"
16-
17-
if [ ! -d ${project_path}/rttpkgtool ]; then
18-
echo "rttpkgtool does not exist, clone it from ${url_rttpkgtool}"
19-
git clone -b for-k230 ${url_rttpkgtool} ${project_path}/rttpkgtool
20-
21-
if [ $? -ne 0 ]; then
22-
echo "Failed to clone ${url_rttpkgtool} !"
23-
exit 1
24-
fi
25-
else
26-
echo "rttpkgtool already exists"
27-
pushd ${project_path}/rttpkgtool
28-
git checkout for-k230
29-
git pull
30-
popd
31-
fi
32-
}
3+
source ./utils.sh
334

345
BSP_PATH=$(realpath $(dirname $0))
356
echo "BSP_PATH: $BSP_PATH"
367

378
download_rttpkgtool $BSP_PATH
9+
result=$?
10+
if [ $result -ne 0 ]; then
11+
echo "ERROR: rttpkgtool is unavailable! Please check your network connection!"
12+
exit 1
13+
fi
3814

3915
pushd $BSP_PATH/rttpkgtool > /dev/null
4016
DPT_PATH_KERNEL=$BSP_PATH ./script/mkpkg.sh

bsp/k230/flashsd.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
source ./utils.sh
4+
5+
BSP_PATH=$(realpath $(dirname $0))
6+
echo "BSP_PATH: $BSP_PATH"
7+
8+
download_rttpkgtool $BSP_PATH
9+
result=$?
10+
if [ $result -ne 0 ]; then
11+
echo "ERROR: rttpkgtool is unavailable! Please check your network connection!"
12+
exit 1
13+
fi
14+
15+
pushd $BSP_PATH/rttpkgtool > /dev/null
16+
17+
./script/sdcard.sh > /dev/null
18+
result=$?
19+
20+
if [ $result -eq 1 ]; then
21+
echo "ERROR: The kernel file to be flashed does not exist!"
22+
exit 1
23+
fi
24+
if [ $result -eq 2 ]; then
25+
echo "ERROR: The USB/SDcard does not exist!"
26+
exit 1
27+
fi
28+
29+
echo "INFO: The kernel file has been flashed to the USB/SDcard successfully!"
30+
31+
popd > /dev/null

bsp/k230/utils.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function download_rttpkgtool()
2+
{
3+
local project_path=$1
4+
local restult=$(curl -m 10 -s http://www.ip-api.com/json)
5+
local country=$(echo $restult | sed 's/.*"country":"\([^"]*\)".*/\1/')
6+
#echo "Country: $country"
7+
8+
if [ "$country" == "China" ]; then
9+
local url_rttpkgtool="https://gitee.com/unicornx/rttpkgtool.git"
10+
else
11+
local url_rttpkgtool="https://github.com/plctlab/rttpkgtool.git"
12+
fi
13+
#echo "rttpkgtool URL: ${url_rttpkgtool}"
14+
15+
if [ ! -d ${project_path}/rttpkgtool ]; then
16+
echo "rttpkgtool does not exist, clone it from ${url_rttpkgtool}"
17+
git clone -b for-k230 ${url_rttpkgtool} ${project_path}/rttpkgtool
18+
19+
if [ $? -ne 0 ]; then
20+
echo "Failed to clone ${url_rttpkgtool} !"
21+
return 1
22+
fi
23+
else
24+
echo "rttpkgtool already exists"
25+
pushd ${project_path}/rttpkgtool
26+
git checkout for-k230
27+
git pull
28+
popd
29+
fi
30+
31+
return 0
32+
}

0 commit comments

Comments
 (0)