|
|
@ -1,308 +0,0 @@
|
|
|
|
# LiteOS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 一、环境安装
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 1. 安装docker环境
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[docker加载镜像下载]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
链接: https://pan.baidu.com/s/1GVossI98riHL2xEzo7HmMQ?pwd=we75 提取码: we75
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
$ cd docker_package
|
|
|
|
|
|
|
|
$ sudo dpkg -i containerd.io_1.5.11-1_amd64.deb
|
|
|
|
|
|
|
|
$ sudo dpkg -i docker-ce-cli_20.10.14_3-0_ubuntu-focal_amd64.deb
|
|
|
|
|
|
|
|
$ sudo dpkg -i docker-ce_20.10.14_3-0_ubuntu-focal_amd64.deb
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docker加载liteos-env镜像
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
$ cd docker_images
|
|
|
|
|
|
|
|
$ sudo docker load -i openharmony-v31.tar
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2. 下载源代码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[LiteOS v3.1](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fharmonyos%2Fos%2F3.1-Release%2Fcode-v3.1-Release.tar.gz)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3. 将用户添加到docker用户组
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
$ sudo groupadd docker
|
|
|
|
|
|
|
|
$ sudo gpasswd -a $USER docker
|
|
|
|
|
|
|
|
$ newgrp docker
|
|
|
|
|
|
|
|
$ ./run_docker.sh
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 4.编译liteos-a内核和应用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
编译 hb set 使用上下方向键盘选择"qemu_small_system_demo"
|
|
|
|
|
|
|
|
hb build编译
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
root@62deba27a240:/home/openharmony# hb set
|
|
|
|
|
|
|
|
root@62deba27a240:/home/openharmony# hb build -f
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
运行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
root@62deba27a240:/home/openharmony# ./qemu-run -f
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
等待内核在qemu下加载完成,回车,进入OHOS shell
|
|
|
|
|
|
|
|
如果无法进入,请检查out目录下是否存在smallmmc.img,不存在请复制smallmmc.img到out目录下
|
|
|
|
|
|
|
|
并重新编译执行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
root@62deba27a240:/home/openharmony# ./qemu-run -f
|
|
|
|
|
|
|
|
Redo making flash.img...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Start making flash.img...
|
|
|
|
|
|
|
|
1+0 records in
|
|
|
|
|
|
|
|
1+0 records out
|
|
|
|
|
|
|
|
67108864 bytes (67 MB, 64 MiB) copied, 0.498911 s, 135 MB/s
|
|
|
|
|
|
|
|
2191+1 records in
|
|
|
|
|
|
|
|
2191+1 records out
|
|
|
|
|
|
|
|
1122100 bytes (1.1 MB, 1.1 MiB) copied, 0.0123126 s, 91.1 MB/s
|
|
|
|
|
|
|
|
0+1 records in
|
|
|
|
|
|
|
|
0+1 records out
|
|
|
|
|
|
|
|
89 bytes copied, 0.000333672 s, 267 kB/s
|
|
|
|
|
|
|
|
9818+1 records in
|
|
|
|
|
|
|
|
9818+1 records out
|
|
|
|
|
|
|
|
5027048 bytes (5.0 MB, 4.8 MiB) copied, 0.0291576 s, 172 MB/s
|
|
|
|
|
|
|
|
63+1 records in
|
|
|
|
|
|
|
|
63+1 records out
|
|
|
|
|
|
|
|
32492 bytes (32 kB, 32 KiB) copied, 0.000204982 s, 159 MB/s
|
|
|
|
|
|
|
|
Success making flash.img...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Enter to start qemu[y/n]:Waiting VNC connection on: 5920 ...(Ctrl-C exit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
******************Welcome******************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Processor : Cortex-A7
|
|
|
|
|
|
|
|
Run Mode : UP
|
|
|
|
|
|
|
|
GIC Rev : GICv2
|
|
|
|
|
|
|
|
build time : Nov 15 2022 11:40:20
|
|
|
|
|
|
|
|
Kernel : Huawei LiteOS 2.0.0.37/debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*******************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main core booting up...
|
|
|
|
|
|
|
|
cpu 0 entering scheduler
|
|
|
|
|
|
|
|
mem dev init ...
|
|
|
|
|
|
|
|
DevMmzRegister...
|
|
|
|
|
|
|
|
Date:Nov 15 2022.
|
|
|
|
|
|
|
|
Time:11:40:19.
|
|
|
|
|
|
|
|
net init ...
|
|
|
|
|
|
|
|
[ERR]virtio-mmio ID=1 device not found
|
|
|
|
|
|
|
|
[ERR]add virtio-mmio net device failed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
************************************************************
|
|
|
|
|
|
|
|
DeviceManagerStart start ...
|
|
|
|
|
|
|
|
[CfiFlashInit]CFI flash init start ...
|
|
|
|
|
|
|
|
[CfiFlashInit]CFI flash init end ...
|
|
|
|
|
|
|
|
[CfiFlashInit]CFI flash init start ...
|
|
|
|
|
|
|
|
DeviceManagerStart end ...
|
|
|
|
|
|
|
|
OsMountRootfs start ...
|
|
|
|
|
|
|
|
OsMountRootfs end ...
|
|
|
|
|
|
|
|
virtual_serial_init start ...
|
|
|
|
|
|
|
|
virtual_serial_init end ...
|
|
|
|
|
|
|
|
system_console_init start ...
|
|
|
|
|
|
|
|
system_console_init end ...
|
|
|
|
|
|
|
|
OsUserInitProcess start ...
|
|
|
|
|
|
|
|
OsUserInitProcess end ...
|
|
|
|
|
|
|
|
[ERR]Failed to find block driver /dev/mmcblk0
|
|
|
|
|
|
|
|
[ERR]Failed to find block driver /dev/mmcblk1
|
|
|
|
|
|
|
|
hilog ringbuffer full, drop 19 line(s) log
|
|
|
|
|
|
|
|
hilog ringbuffer full, drop 7 line(s) log
|
|
|
|
|
|
|
|
hilog ringbuffer full, drop 2 line(s) log
|
|
|
|
|
|
|
|
Set log level : 3
|
|
|
|
|
|
|
|
Default log level: 3
|
|
|
|
|
|
|
|
[ERR]Unsupported API tcgetpgrp
|
|
|
|
|
|
|
|
01-01 00:00:00.081 2 4 D 02500/devmgr_service: DevmgrServiceUpdateStatus host:storage_host 2 device:HDF_PLATFORM_CFI_0 0 status:1
|
|
|
|
|
|
|
|
...............
|
|
|
|
|
|
|
|
01-01 00:00:26.001 7 29 I 01800/Samgr: Goto next boot step return code:-9
|
|
|
|
|
|
|
|
01-01 00:00:26.002 7 14 I 00000/(null): [appspawn] HOS_SystemInit is called!
|
|
|
|
|
|
|
|
01-01 00:00:26.003 7 14 I 00000/(null): [appspawn] main, entering wait.
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
回车之后进入OHOS shell
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
|
|
|
OHOS:/$ cd bin
|
|
|
|
|
|
|
|
OHOS:/bin$
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
测试结束
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ctrl-A + x 退出Qemu模拟环境
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 二、命令行调试liteOS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 1、安装`gdb-multiarch`工具包(docker 容器中安装):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
$ apt install gdb-multiarch
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2、修改`debug.config`文件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
$ cd ./vendor/ohemu/qemu_small_system_demo/kernel_configs
|
|
|
|
|
|
|
|
$ vim debug.config
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
将 `LOSCFG_CC_STACKPROTECTOR_ALL=y` 修改为:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
# LOSCFG_CC_STACKPROTECTOR_ALL is not set
|
|
|
|
|
|
|
|
LOSCFG_COMPILE_DEBUG=y
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3、重新编译项目
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
保存并退出,在OHOS根目录重新编译:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
$ hb build -f
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 4、debug LiteOS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在一个窗口中输入命令:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
$ ./qemu-run -g
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在另一个窗口中输入命令:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
$ docker exec -it ohos /bin/bash
|
|
|
|
|
|
|
|
$ gdb-multiarch out/arm_virt/qemu_small_system_demo/OHOS_Image
|
|
|
|
|
|
|
|
(gdb) target remote localhost:1234
|
|
|
|
|
|
|
|
(gdb) b main
|
|
|
|
|
|
|
|
Breakpoint 1 at 0x4005110c: file ../../../kernel/liteos_a/kernel/common/main.c, line 36.
|
|
|
|
|
|
|
|
(gdb) c
|
|
|
|
|
|
|
|
Continuing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Breakpoint 1, main () at ../../../kernel/liteos_a/kernel/common/main.c:36
|
|
|
|
|
|
|
|
36 {
|
|
|
|
|
|
|
|
(gdb) l
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32 #include "los_config.h"
|
|
|
|
|
|
|
|
33 #include "los_sched_pri.h"
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35 LITE_OS_SEC_TEXT_INIT INT32 main(VOID)
|
|
|
|
|
|
|
|
36 {
|
|
|
|
|
|
|
|
37 UINT32 ret = OsMain();
|
|
|
|
|
|
|
|
38 if (ret != LOS_OK) {
|
|
|
|
|
|
|
|
39 return (INT32)LOS_NOK;
|
|
|
|
|
|
|
|
40 }
|
|
|
|
|
|
|
|
(gdb) q
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* gdb 调试常用代码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1、 b (break) :设置断点
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2、 r (run): 运行程序
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3、 bt (backtrace): 显示程序栈
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4、 Print : 打印变量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5、 c (continue): 继续运行程序,直到下一个断点停止
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6、 n (next) : 单步运行程序,不进入函数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7、 l (list) : 查看当前代码(显示当前后10行)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8、 edit (+function): 查看函数代码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9、 S (step) : 进入函数执行代码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10、 Q(Quit):退出gdb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11、 Info b : 查看断点信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 三、VSCode调试liteOS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 1、安装VScode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shel
|
|
|
|
|
|
|
|
$ sudo apt install code
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2、安装VScode 插件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3、连接docker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
选择CONTAINERS目录下openharmony:v3.1...,右键选择附加VScode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 4、给docker安装VScode插件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 注意插件一定要安装在docker容器中
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 5、配置launch.json文件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"version": "0.2.0",
|
|
|
|
|
|
|
|
"configurations": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "debug liteOS",
|
|
|
|
|
|
|
|
"type": "cppdbg",
|
|
|
|
|
|
|
|
"request": "launch",
|
|
|
|
|
|
|
|
"program": "${workspaceFolder}/out/arm_virt/qemu_small_system_demo/OHOS_Image",
|
|
|
|
|
|
|
|
"args": [],
|
|
|
|
|
|
|
|
"stopAtEntry": true,
|
|
|
|
|
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
|
|
|
|
|
"miDebuggerServerAddress": "localhost:1234",
|
|
|
|
|
|
|
|
"miDebuggerPath": "/usr/bin/gdb-multiarch",
|
|
|
|
|
|
|
|
"environment": [],
|
|
|
|
|
|
|
|
"externalConsole": false,
|
|
|
|
|
|
|
|
"MIMode": "gdb",
|
|
|
|
|
|
|
|
"setupCommands": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"description": "pretty printing",
|
|
|
|
|
|
|
|
"text": "-enable-pretty-printing",
|
|
|
|
|
|
|
|
"ignoreFailures": true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"logging": {
|
|
|
|
|
|
|
|
"engineLogging": true,
|
|
|
|
|
|
|
|
"programOutput": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 6、新建终端
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
运行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
./qemu-run -g
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 7、vscode debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
点击debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|