diff --git a/src/cli/h2hdf/docs/DEVELOP.md b/src/cli/h2hdf/docs/develop.md similarity index 43% rename from src/cli/h2hdf/docs/DEVELOP.md rename to src/cli/h2hdf/docs/develop.md index c9ef14562a38b2cc5cf82906ca1093a9dcbc9a16..a1c67999659306c12fa9ca1e2f48f6b4ce2b135d 100644 --- a/src/cli/h2hdf/docs/DEVELOP.md +++ b/src/cli/h2hdf/docs/develop.md @@ -47,9 +47,15 @@ h2hdf 运行逻辑 -![image-20240724093743837](./figures/pic_code_frame.png) +![image-20240724093743837](./figures/pic_code_process.png) + +main.js为脚本入口,其中使用stdio.getopt获取参数,其中,参数详情如下: + + -n, drivername,例如:hello -main.js为脚本入口,其中使用stdio.getopt获取参数,参数分别为: -n, drivername,例如:hello;-v, 可选参数,版本,默认为4.1;-o, 可选参数,默认为当前目录,指定生成框架代码输出路径。 + -v, 可选参数,版本,默认为4.1 + + -o, 可选参数,默认为当前目录,指定生成框架代码输出路径。 ``` let ops = stdio.getopt({ @@ -66,7 +72,7 @@ let ops = stdio.getopt({ ``` ... -const allowedVersion = ['4.0', '4.1', '5.0', '5.1']; +const allowedVersion = ['4.1']; function isValidValue(value, allowedVersion) { return allowedVersion.includes(value); } @@ -77,17 +83,6 @@ function checkInput(input) { } ``` -使用getJsonCfg读取json文件中hdf框架模板的路径: - -``` -function getJsonCfg(jsonFilePath) { - let jsonCfg = null; - let jsonFile = fs.readFileSync(jsonFilePath, { encoding: 'utf8' }); - jsonCfg = JSON.parse(jsonFile); - return jsonCfg; -} -``` - 获取到每个模板的路径后,根据路径读取模板文件,并替换模板文件中的drivername等: ``` @@ -106,178 +101,25 @@ function genDriverFramework(driverName, frameworkJson, version, out = '') { } ``` -## 工具使用方法说明 - -### 生成 - -1.安装typescript:在napi_generator/src/cli/h2hdf/src目录下执行命令: - - npm i typescript - -2.安装stdio:在napi_generator/src/cli/h2hdf目录下执行命令: - - npm i stdio - -3.在napi_generator/src/cli/h2hdf/src下执行以下命令生成ts声明文件: - -``` -node main.js -n hello -``` - -其中,参数详情如下: - - -n, drivername,例如:hello - - -v, 可选参数,版本,默认为4.1 - - -o, 可选参数,默认为当前目录,指定生成框架代码输出路径。 - -6.执行成功后在napi_generator/src/cli/h2hdf/src/下生成hellohdf文件夹,文件夹中目录结构如下所示: - -``` -hellohdf -├── HcsConfig # hcs配置文件 -│ ├── device_info.hcs # 内容配置到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中 -├── IdlInterface -│ ├── hello # 拷贝到源码drivers/interface -│ │ ├── v1_0 -│ │ │ ├── BUILD.gn -│ │ │ ├── IHelloInterface.idl # idl接口 -│ │ ├── bundle.json -├── Peripheral # 拷贝到源码drivers/peripheral -│ ├── hello -│ │ ├── hal -│ │ │ ├── include -│ │ │ │ ├── hello_dump.h -│ │ │ ├── BUILD.gn -│ │ │ ├── hello_dump.c # hidump实现 -│ │ ├── hdi_service # hdi_service -│ │ │ ├── BUILD.gn # 编译两个动态库:libhello_driver、libhello_interface_service_1.0 -│ │ │ ├── hello_interface_driver.cpp # driver:定义驱动入口的对象,将驱动入口注册到HDF框架中;在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动;当Init调用异常时,HDF框架会调用Release释放驱动资源并退出 -│ │ │ ├── hello_interface_service.cpp # 驱动服务 -│ │ │ ├── hello_interface_service.h -│ │ ├── utils/interface -│ │ │ ├── hello_log.h # 日志文件 -│ │ ├── BUILD.gn -│ │ ├── bundle.json -``` - -### 编译 - -1.将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下 - -``` -cp hellohdf/Peripheral/hello 源码/drivers/peripheral -``` - -将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下 - -``` -cp hellohdf/IdlInterface/hello 源码/drivers/interface -``` - -将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中,如下所示: - -``` - root { - device_info { - ... - hello :: host { - hostName = "hello_host"; - priority = 50; - hello_device :: device { - device0 :: deviceNode { - preload = 0; - policy = 2; - priority = 100; - moduleName = "libhello_driver.z.so"; - serviceName = "hello_interface_service"; - } - } - } - ... - } - } -``` - -2.配置产品:以rk3568为例,在源码vendor/hihope/rk3568/config.json文件中hdf子系统的components中增加以下内容: - -``` -{ - "component": "drivers_interface_hello", - "features": [] -}, -{ - "component": "drivers_peripheral_hello", - "features": [] -} -``` - -注意:drivers_interface_hello为drivers/interface/hello/v1_0/BUILD.gn中的part_name。drivers_peripheral_hello为drivers/peripheral/hello/bundle.json中的component。 - -3.编译,在源码下执行以下命令进行编译: - -``` -./build.sh --product-name rk3568 -``` - -编译成功后,将源码下out/rk3568/packages/phone/image镜像烧录在dayu200开发板上 - -### 验证 - -#### 动态加载 - -1.查看hostId:hdc连接开发板,进入/vendor/etc/init路径下,并查看hdf_devhost.cfg文件,使用hdc命令如下: - -``` -cat hdf_devhost.cfg -``` +## 开发指导 -根据hostName找到对应hostId,如本例的hostName为hello_host,对应找到“name”为“hello_host”那一项,查看“path”的第二个参数,则为hostName对应的hostId,即14,如下所示: +### 适配新版本 -![image-20240724093743837](./figures/pic_show_hostid.png) +适配新版本的步骤如下: -2.运行可执行文件hdf_devhost,手动拉起host:进入/vendor/bin路径下,运行可执行文件hdf_devhost,传入一个参数为hostId,第二个参数为hostName;运行命令如下所示: +1.在main.js中,在allowedVersion数组中加入适配的版本号,其中版本号需统一写法,如4.1 -``` -./hdf_devhost 14 hello_host -``` - -![image-20240903114845035](./figures/pic_show_exe.png) - -注意 :不可将进程kill - -3.查看host是否加载:新开一个命令行窗口,hdc进入开发板,执行以下命令查看进程是否拉起: - -``` -ps -A | grep host -``` - -屏幕显示hello_host进程号,则表明host已被拉起 - -![image-20240724093743837](./figures/pic_show_devhostPid.png) - -4.使用hidumper查看更多细节信息: - -查询所有正在运行的host - -``` - hidumper -s HdfDeviceServiceManager -a "-query" -``` - -![image-20240724093543096](./figures/pic_show_host.png) - -使用hidumper查看更多信息 - -``` -hidumper -s HdfDeviceServiceManager -a "-host hello_host -c" -``` +2.在templete目录下,IdlInterfaceTemplete目录下新建适配版本文件夹,如v4_1,在适配版本文件夹下新增bundle.json模板,在 Periphheral, Periphheral/DumpExampleTemplete, Periphheral/HdiServiceTemplete新增适配版本文件夹,在适配版本下新增对应的BUILD.gn模板,并在framework.json中新增版本的bundle.json,BUILD.gn模板路径。 -打印出Hello, World! +3.在generate.js中,在genInterface方法、genExampleDumpfile方法、genHdiService方法、genBuildFile方法中修改相应代码:当rootInfo.version为新增版本时,替换对应的BUILD.gn, bundle.json模板路径。 -![image-20240724093535915](./figures/pic_show_dump.png) +4.适配新版本增加其它配置时,可在templete目录下增加配置模板,并在framework.json中增加配置文件模板的路径,然后在generate.js中替换模板并生成配置文件。 -#### 静态加载 +## Roadmap -// todo 待补充 +| 工作目标 | 工作内容 | 验收要求 | 时间节点 | +| ----------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ---------------- | +| 支持一个简单的sample_host模板 | 根据工具基于OpenHarmony4.1源码,编写脚本生成Hdf框架模板,其中包括hcsconfig模板,idl接口模板,peripheral模板 | 生成之后可动态加载Host,并能使用Hidump查看日志,打印出"hello word!" | 2024.8(已完成) | +| 完善host模板 | 增加testapp测试程序;完善模板中hitrace日志跟踪定位工具的使用;模板中增加死亡监听:客户端监听服务端消亡、服务端监听客户端消亡、服务端监听底层HDI侧消亡 | 驱动host能随镜像起来,服务端/客户端/HDI侧消亡时能打印出日志;检测接口被调用时打印hitrace日志 | 2024.10 | +| 适配5.0 | 适配5.0release版本 | 适配5.0时,可以编译出对应版本的工具,且编译验证成功 | 2024.11 | diff --git a/src/cli/h2hdf/docs/figures/pic_code_frame.png b/src/cli/h2hdf/docs/figures/pic_code_frame.png index 1f77649365e6174e8f482ffef45c86f8dc0d9c05..8b21ad852e85b4cf16aaae5639fdd7144ae8916f 100644 Binary files a/src/cli/h2hdf/docs/figures/pic_code_frame.png and b/src/cli/h2hdf/docs/figures/pic_code_frame.png differ diff --git a/src/cli/h2hdf/docs/figures/pic_code_process.png b/src/cli/h2hdf/docs/figures/pic_code_process.png new file mode 100644 index 0000000000000000000000000000000000000000..1f77649365e6174e8f482ffef45c86f8dc0d9c05 Binary files /dev/null and b/src/cli/h2hdf/docs/figures/pic_code_process.png differ diff --git a/src/cli/h2hdf/docs/figures/pic_show_dumpc.png b/src/cli/h2hdf/docs/figures/pic_show_dumpc.png new file mode 100644 index 0000000000000000000000000000000000000000..e563e26996fe48b539f4bbe3cc52052ee92e275f Binary files /dev/null and b/src/cli/h2hdf/docs/figures/pic_show_dumpc.png differ diff --git a/src/cli/h2hdf/docs/figures/pic_show_dumph.png b/src/cli/h2hdf/docs/figures/pic_show_dumph.png new file mode 100644 index 0000000000000000000000000000000000000000..bab6314a3281d898daaf29cd12a503d2ae61c78a Binary files /dev/null and b/src/cli/h2hdf/docs/figures/pic_show_dumph.png differ diff --git a/src/cli/h2hdf/docs/figures/pic_show_exe.png b/src/cli/h2hdf/docs/figures/pic_show_exe.png index d63fc90ae6b621654350bc608bf014cae1384ba7..fdbdca856d36825d4cc459aa65ac918403fc49f5 100644 Binary files a/src/cli/h2hdf/docs/figures/pic_show_exe.png and b/src/cli/h2hdf/docs/figures/pic_show_exe.png differ diff --git a/src/cli/h2hdf/docs/figures/pic_show_hostid.png b/src/cli/h2hdf/docs/figures/pic_show_hostid.png index 7faaa1dbfd96a47ed8a1745b242428d0c458756e..76317e5c51cb1b8c750df1d5b3597e6107a46c37 100644 Binary files a/src/cli/h2hdf/docs/figures/pic_show_hostid.png and b/src/cli/h2hdf/docs/figures/pic_show_hostid.png differ diff --git a/src/cli/h2hdf/docs/usage.md b/src/cli/h2hdf/docs/usage.md index dedb587bb0d12980579a81316a9a5b98455f191d..a2dae64f36df8b4a87ffc921c456c50d35b3984a 100644 --- a/src/cli/h2hdf/docs/usage.md +++ b/src/cli/h2hdf/docs/usage.md @@ -1,10 +1,8 @@ -# Usage guide +# Usage Guide ## 简介 在OpenHarmony系统中,上层应用或服务层通过调用HDF框架提供的HDI接口,能够以一种标准化和抽象化的方式与底层硬件设备进行交互。使用h2hdf工具,用户只需提供一个drivername,工具会自动生成整个框架的代码,包含驱动配置文件、idl接口、驱动程序driver和驱动服务框架。 -![image-20240724093743837](./figures/pic_code_frame.png) - ## 约束 系统:建议Ubuntu 20.04或者Windows 10 @@ -22,7 +20,7 @@ npm i stdio -3.在napi_generator/src/cli/h2hdf/src下执行以下命令生成ts声明文件: +3.在napi_generator/src/cli/h2hdf/src下执行以下命令: ``` node main.js -n hello @@ -68,24 +66,25 @@ hellohdf ### 编译 -1.将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下 +1. **拷目录:** 将hellohdf/Peripheral文件夹下的hello文件夹拷贝到源码drivers/peripheral目录下 ``` -cp hellohdf/Peripheral/hello 源码/drivers/peripheral +cp hellohdf/Peripheral/hello 源码/drivers/peripheral -r ``` -将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下 +2. **拷目录:** 将hellohdf/IdlInterface文件夹下的hello文件夹拷贝到源码drivers/interface目录下 ``` -cp hellohdf/IdlInterface/hello 源码/drivers/interface +cp hellohdf/IdlInterface/hello 源码/drivers/interface -r ``` -将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中,如下所示: +3. **改文件:** 将hellohdf/HcsConfig/device_info.hcs中的内容拷贝到源码vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs文件中,如下所示: ``` root { device_info { ... + // 增加以下内容 hello :: host { hostName = "hello_host"; priority = 50; @@ -99,12 +98,13 @@ cp hellohdf/IdlInterface/hello 源码/drivers/interface } } } + // 增加上述内容 ... } } ``` -2.配置产品:以rk3568为例,在源码vendor/hihope/rk3568/config.json文件中hdf子系统的components中增加以下内容: +4. **配置产品:** 以rk3568为例,在源码vendor/hihope/rk3568/config.json文件中hdf子系统的components中增加以下内容: ``` { @@ -117,34 +117,32 @@ cp hellohdf/IdlInterface/hello 源码/drivers/interface } ``` -注意:drivers_interface_hello为drivers/interface/hello/v1_0/BUILD.gn中的part_name。drivers_peripheral_hello为drivers/peripheral/hello/bundle.json中的component。 +"drivers_interface_hello"为生成的drivers/interface/hello/v1_0/BUILD.gn中的part_name,其中"drivers_interface_"为固定格式。drivers_peripheral_hello"为生成的drivers/peripheral/hello/bundle.json中的component,"drivers_peripheral_"为固定格式。 -3.编译,在源码下执行以下命令进行编译: +5. **编译:** 在源码下执行以下命令进行编译: ``` ./build.sh --product-name rk3568 ``` -编译成功后,将源码下out/rk3568/packages/phone/image镜像烧录在dayu200开发板上 +编译成功后,镜像位置在out/rk3568/packages/phone/image目录下 ### 验证 #### 动态加载 -1.查看hostId:hdc连接开发板,进入/vendor/etc/init路径下,并查看hdf_devhost.cfg文件,使用hdc命令如下: +1.查看hostId:镜像烧录后,在vendor/etc/init/hdf_devhost.cfg文件里查看hostId ``` -cat hdf_devhost.cfg +cat vendor/etc/init/hdf_devhost.cfg ``` -根据hostName找到对应hostId,如本例的hostName为hello_host,对应找到“name”为“hello_host”那一项,查看“path”的第二个参数,则为hostName对应的hostId,即14,如下所示: - ![image-20240724093743837](./figures/pic_show_hostid.png) -2.运行可执行文件hdf_devhost,手动拉起host:进入/vendor/bin路径下,运行可执行文件hdf_devhost,传入一个参数为hostId,第二个参数为hostName;运行命令如下所示: +2.加载hello_host,命令如下: ``` -./hdf_devhost 14 hello_host +./vendor/bin/hdf_devhost 14 hello_host ``` ![image-20240903114845035](./figures/pic_show_exe.png) @@ -163,7 +161,7 @@ ps -A | grep host 4.使用hidumper查看更多细节信息: -查询所有正在运行的host +通过DeviceServiceManager查询用户空间的设备信息 ``` hidumper -s HdfDeviceServiceManager -a "-query" @@ -171,16 +169,30 @@ ps -A | grep host ![image-20240724093543096](./figures/pic_show_host.png) -使用hidumper查看更多信息 +通过DeviceServiceManager查询hello_host提供什么功能 + +``` +hidumper -s HdfDeviceServiceManager -a "-host hello_host -h" +``` + +-h:打印dump help信息 + +![image-20240724093543096](./figures/pic_show_dumph.png) + +通过DeviceServiceManager查询hello_host提供的helloworld功能 ``` hidumper -s HdfDeviceServiceManager -a "-host hello_host -c" ``` -打印出Hello, World! +-c:打印出Hello, World! ![image-20240724093535915](./figures/pic_show_dump.png) +其中,-h、-c定义在生成的hellohdf/Peripheral/hello/hal/hello_dump.c中: + +![image-20240724093543096](./figures/pic_show_dumpc.png) + #### 静态加载 // todo 待补充 diff --git a/src/cli/h2hdf/src/generate.js b/src/cli/h2hdf/src/generate.js index f7d6d4e9349173e8dc54abf01dea36f40b3bd734..e4936b26a67153df2cb5fcd5df79983c645dfbd2 100644 --- a/src/cli/h2hdf/src/generate.js +++ b/src/cli/h2hdf/src/generate.js @@ -16,7 +16,7 @@ const fs = require('fs'); const path = require('path'); /* 根据用户输入的driver名字生成framework框架 - * drivername:用户输入的驱动名,frameworkJson: 模板内容,out:生成框架路径 + * drivername:用户输入的驱动名,version: 版本号,frameworkJson: 模板内容,out:生成框架路径 * 替换模板中的名字并写文件输出 */ function genDriverFramework(driverName, frameworkJson, version, out = '') { diff --git a/src/cli/h2hdf/src/main.js b/src/cli/h2hdf/src/main.js index 50f5b1c571dae2f822e7626e1bdd4cf16e3deb81..15138aa01899e496f47237ff0cf0695d37c302be 100644 --- a/src/cli/h2hdf/src/main.js +++ b/src/cli/h2hdf/src/main.js @@ -26,7 +26,7 @@ let ops = stdio.getopt({ 'out': { key: 'o', args: 1, description: 'output directory', default: '' }, }); -const allowedVersion = ['4.1', '4-1', '4_1', '4.0', '5.0', '5.1']; +const allowedVersion = ['4.1']; let drivername = ops.drivername; let version = ops.version; @@ -40,7 +40,7 @@ if (drivername.trim().length !== 0 && checkInput(drivername)) { // 在这里读取cfg文件 let frameworkJsonPath = path.join(__dirname, './templete/framework.json'); let frameworkJson = getJsonCfg(frameworkJsonPath); - if (version === '4.1' || version === '4-1' || version === '4_1') { + if (version === '4.1') { version = 'v4_1'; } else { console.log('其他版本暂不支持...'); diff --git a/src/cli/h2hdf/src/templete/PeripheralTemplete/DumpExampleTemplete/dumpCTemplete.gen b/src/cli/h2hdf/src/templete/PeripheralTemplete/DumpExampleTemplete/dumpCTemplete.gen index b3f17584664346b71ee79cf83604f8fea81b932e..9254a3409c34a75280921782fb1ac09489ad6fed 100644 --- a/src/cli/h2hdf/src/templete/PeripheralTemplete/DumpExampleTemplete/dumpCTemplete.gen +++ b/src/cli/h2hdf/src/templete/PeripheralTemplete/DumpExampleTemplete/dumpCTemplete.gen @@ -26,7 +26,7 @@ static const char *g_dumpHelp = " usage:\n" " -h, --help: dump help\n" - " -c, --channel: dump the [driver_name] channel info\n"; + " -c, --hello: dump the helloworld info\n"; static uint32_t ShowHelloworldInfo(struct HdfSBuf *reply) {