Openharmony - 3516應用調用到驅動嘗試
一、簡介
ipcamera_hispark_taurus(代碼版本openharmony3.1 liteos-a), 編譯myapptest調用驅動GPIO_TEST。從配置、編譯,燒錄到運行。
1.下載openharmony 3.1代碼。
2.添加myapp子系統。
3.編譯燒錄。
4.運行。
二、代碼下載
代碼下載參考:openharmony 3.1。
三、添加myapp子系統
子系統配置:
添加:build\lite\components\myapp.json。
{
"components": [
{
"component": "myapptest",
"description": "myapptest",
"optional": "false",
"dirs": [
"myapp"
],
"targets": [
"http://myapp:myapp"
],
"rom": "",
"ram": "",
"output": [
],
"adapted_kernel": [
"liteos_a",
"liteos_m"
],
"features": [],
"deps": {
"third_party": [
"bounds_checking_function"
],
"components": []
}
}
]
}
編譯配置:
在vendor\hisilicon\hispark_taurus\config.json中添加:
{
"subsystem": "myapp",
"components": [
{ "component": "myapp", "features":[] }
]
}
修改驅動日志輸出:
修改文件:drivers\framework\test\unittest\platform\common\gpio_driver_test.c。
static int32_t GpioTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
{
// 開始修改----------------
HDF_LOGD("%s: my app test enter!", __func__);
if (cmd == 0) {
const char *readData = HdfSbufReadString(data);
if (readData != NULL) {
HDF_LOGE("%s: read data is %s!", __func__, readData);
}
// 結束修改--------------
if (reply == NULL) {
HDF_LOGE("%s: reply is null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) {
HDF_LOGE("%s: write reply failed", __func__);
return HDF_ERR_IO;
}
} else {
return HDF_ERR_NOT_SUPPORT;
}
return HDF_SUCCESS;
}
myapp代碼目錄添加:
添加在根目錄下,代碼見附件。目錄結構如下圖:
四、編譯燒錄
在代碼根目錄下,執行編譯docker環境:
sudo docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5
docker編譯環境參考:docker。
編譯:
執行下面三條命令:
hb set
.
hb build -f
如果hb set報錯Invalid vendor path,刪除ohos_config.json再執行上面的命令。
燒錄:
燒錄使用hitool:
四個文件中 三個是編譯生成的,一個是源代碼目錄中的二進制。
源代碼目錄中的二進制:device\hisilicon\hispark_taurus\sdk_liteos\uboot\out\boot\u-boot-hi3516dv300.bin。
將二進制拷貝到同一的目錄D:\harmony_tool\hispark_taurus中:
添加的Hi3516DV300-emmc.xml內容如下:
<?xml version="1.0" encoding="GB2312" ?>
<Partition_Info>
<Part Sel="1" PartitionName="fastboot" FlashType="emmc" FileSystem="none" Start="0" Length="1M" SelectFile="D:\harmony_tool\hispark_taurus\u-boot-hi3516dv300.bin"/>
<Part Sel="1" PartitionName="kernel" FlashType="emmc" FileSystem="none" Start="1M" Length="9M" SelectFile="D:\harmony_tool\hispark_taurus\OHOS_Image.bin"/>
<Part Sel="1" PartitionName="rootfs" FlashType="emmc" FileSystem="none" Start="10M" Length="35M" SelectFile="D:\harmony_tool\hispark_taurus\rootfs_vfat.img"/>
<Part Sel="1" PartitionName="userfs" FlashType="emmc" FileSystem="none" Start="45M" Length="120M" SelectFile="D:\harmony_tool\hispark_taurus\userfs_vfat.img"/>
</Partition_Info>
Length > 文件的大小, 下一條的start = 本條的start + 本條Length。
kernel的開始地址=fastboot的開始地址+fastboot的長度,即kernel的開始地址=0 + 1M。
燒錄完成,實際上沒有進入系統OHOS #, 需要進行啟動配置。
啟動配置:
每一行是一條命令。
setenv bootcmd "mmc read 0x0 0x80000000 0x800 0x4800;go 0x80000000;";
setenv bootargs "console=ttyAMA0,115200n8 root=emmc fstype=vfat rw rootaddr=10M rootsize=35M";
setenv bootdelay 3
saveenv
reset
rootaddr的值是Hi3516DV300-emmc.xml文件中rootfs的開始地址,rootsize的值是rootfs的長度。
啟動配置參考:Hi3516DV300開發板->運行。
執行啟動配置最后一條命令reset后,進入系統。 即進入OHOS #。
五、運行
執行:myapptest。
此文檔是在??HDF驅動框架探路(二):openharmony最新源碼,打通應用態到內核態??的基礎上實踐。
編譯和啟動配置這篇文章可參考。