技术标签: android 嵌入式 Android系统开发
从事Android BSP开发一年有余,都是在驱动上的工作,每每涉及HAL层面的工作,总是“望而却步”却又心有不甘。前期系统性的学习了一些C++(记录整理后补上)后,再反过来看HAL相关的code,稍有熟悉感。趁热打铁,小试牛刀,尝试一下HIDL 的hal。
平台介绍:firefly RK 3399 pc pro, 系统是Android10。
第一步:创建文件夹
# mkdir -p hardware/interfaces/hidltest/1.0
第二步:新建 .hal 文件
# touch hardware/interfaces/hidltest/1.0/IHidlTest.hal
第三步: .hal 添加接口声明
package [email protected];
interface IHidlTest {
//声明了一个函数名为 helloWorld、参数为 字符串、返回值为 字符串 类型的接口。
helloWorld(string name) generates (string result);
};
第四步:执行 hardware/interface/ 1.0/下的脚本生成 Android.bp 文件
# ./hardware/interfaces/update-makefiles.sh
此时,hidltest 文件夹下的目录为
.
└── 1.0
├── Android.bp
└── IHidlTest.hal
1 directory, 2 files
第五步:编译试试
# make -j8 [email protected]
==》 生成:out/target/product/rk3399_roc_pc_plus/obj/SHARED_LIBRARIES/[email protected]_intermediates/[email protected]
不知道怎么用 ~_~.....
# make -j8 hidl-gen
==> 没生成啥,提示编译成功。
第六步:用 hidl-gen 生成.cpp 和 .h 文件
export [email protected]
export LOC=./hardware/interfaces/hidltest/1.0/default
hidl-gen -o $LOC -L c++-impl -r android.hardware:hardware/interfaces -r android.hidl:system/libhidl/transport $PACKAGE
执行完成后,hidltest 文件夹下的目录为
readme 是手动添加的一个说明文档;HidlTest.cpp and HidlTest.h 是通过以上 hidl-gen 生成的。
HidlTest.cpp 有些什么内容?
// FIXME: your file license if you have one
#include "HidlTest.h"
namespace android {
namespace hardware {
namespace hidltest {
namespace V1_0 {
namespace implementation {
// Methods from ::android::hardware::hidltest::V1_0::IHidlTest follow.
Return<void> HidlTest::helloWorld(const hidl_string& name, helloWorld_cb _hidl_cb) {
// TODO implement
return Void();
}
// Methods from ::android::hidl::base::V1_0::IBase follow.
//IHidlTest* HIDL_FETCH_IHidlTest(const char* /* name */) {
//return new HidlTest();
//}
//
} // namespace implementation
} // namespace V1_0
} // namespace hidltest
} // namespace hardware
} // namespace android
Hidltest.h 文件中的内容
// FIXME: your file license if you have one
#pragma once
#include <android/hardware/hidltest/1.0/IHidlTest.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace hidltest {
namespace V1_0 {
namespace implementation {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
struct HidlTest : public IHidlTest {
// Methods from ::android::hardware::hidltest::V1_0::IHidlTest follow.
Return<void> helloWorld(const hidl_string& name, helloWorld_cb _hidl_cb) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
};
// FIXME: most likely delete, this is only for passthrough implementations
// extern "C" IHidlTest* HIDL_FETCH_IHidlTest(const char* name);
} // namespace implementation
} // namespace V1_0
} // namespace hidltest
} // namespace hardware
} // namespace android
第七步:在Hidltest.cpp添加功能 , 在 Hidltest.h中选择hidl实现的方式
cpp文件
// FIXME: your file license if you have one
#include "HidlTest.h"
namespace android {
namespace hardware {
namespace hidltest {
namespace V1_0 {
namespace implementation {
// Methods from ::android::hardware::hidltest::V1_0::IHidlTest follow.
Return<void> HidlTest::helloWorld(const hidl_string& name, helloWorld_cb _hidl_cb) {
// TODO implement
char buf[128];
::memset(buf, 0, 128);
::snprintf(buf, 128, "Hello World, %s", name.c_str());
hidl_string result(buf);
_hidl_cb(result);
return Void();
}
// Methods from ::android::hidl::base::V1_0::IBase follow.
//IHidlTest* HIDL_FETCH_IHidlTest(const char* /* name */) {
//return new HidlTest();
//}
//
} // namespace implementation
} // namespace V1_0
} // namespace hidltest
} // namespace hardware
} // namespace android
添加红框内的code
h头文件
// FIXME: your file license if you have one
#pragma once
#include <android/hardware/hidltest/1.0/IHidlTest.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace hidltest {
namespace V1_0 {
namespace implementation {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
struct HidlTest : public IHidlTest {
// Methods from ::android::hardware::hidltest::V1_0::IHidlTest follow.
Return<void> helloWorld(const hidl_string& name, helloWorld_cb _hidl_cb) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
};
// FIXME: most likely delete, this is only for passthrough implementations
extern "C" IHidlTest* HIDL_FETCH_IHidlTest(const char* name);
} // namespace implementation
} // namespace V1_0
} // namespace hidltest
} // namespace hardware
} // namespace android
打开红框内的code
这里很多都是多说选择了Passthrough模式,还有一个是Binderized模式,具体而这有何区别,了解后写入专题。
第八步: 添加server.cpp 和编译脚本
这里产生一个问题:server.cpp 是用来干嘛的?
创建server.cpp文件
# touch hardware/interfaces/hidltest/1.0/default/service.cpp
添加code到 server.cpp
# define LOG_TAG "[email protected]"
# include <android/hardware/hidltest/1.0/IHidlTest.h>
# include <hidl/LegacySupport.h>
using android::hardware::hidltest::V1_0::IHidlTest;
using android::hardware::defaultPassthroughServiceImplementation;
int main() {
return defaultPassthroughServiceImplementation<IHidlTest>();
}
再次生成Android.bp
# hidl-gen -o $LOC -L androidbp-impl -r android.hardware:hardware/interfaces -r android.hidl:system/libhidl/transport $PACKAGE
增加了 defalut 文件夹下面的Android.bp 文件。
第八步:创建rc文件
# touch hardware/interfaces/hidltest/1.0/default/[email protected]
添加内容到rc
service hidltest_hal_service /vendor/bin/hw/[email protected]
class hal
user system
group system
rc 文件主要是限制 hidltest service的用户和用户组的权限。
第九步: 添加default 目录下的Android.bp 添加 server.cpp编译的指令并尝试编译
cc_binary {
proprietary: true,
relative_install_path: "hw",
defaults: ["hidl_defaults"],
name: "[email protected]",
init_rc: ["[email protected]"],
srcs: ["service.cpp"],
cflags: [
"-Wall",
"-Werror",
],
shared_libs: [
"liblog",
"libdl",
"libutils",
"libhardware",
"libhidlbase",
"libhidltransport",
"[email protected]",
"[email protected]",
],
}
编译
# mmm hardware/interfaces/hidltest/1.0/
# mmm hardware/interfaces/hidltest/1.0/default/
编译生成库
生成了so库
out/target/product/rk3399_roc_pc_plus/vendor/lib64/hw/[email protected]
out/target/product/rk3399_roc_pc_plus/vendor/lib64/[email protected]
out/target/product/rk3399_roc_pc_plus/vendor/bin/hw/[email protected]
out/target/product/rk3399_roc_pc_plus/obj/SHARED_LIBRARIES/[email protected]_intermediates/[email protected]
执行拷贝命令:
$ adb root
$ adb remount
$ adb push out/target/product/rk3399_roc_pc_plus/vendor/lib64/hw/[email protected] /vendor/lib64
$ adb push out/target/product/rk3399_roc_pc_plus/obj/SHARED_LIBRARIES/[email protected]_intermediates/[email protected] /vendor/lib64
$ adb push out/target/product/rk3399_roc_pc_plus/vendor/bin/hw/[email protected] /vendor/bin/hw
运行server 结果如下:
但是不能一值运行,ps -A查看不到服务,暂时还没有找到原因。如果有知道的师兄,可以留言哟~~
此外,本记录参考:
Android HIDL第一个HelloWorld demo_慢慢的燃烧的博客-程序员宅基地
Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC_Heisenberg海森堡的博客-程序员宅基地
还有测试步骤暂时么有完善。
文章浏览阅读141次。简介:菜鸟高手裸奔工具沙盘Sandboxie是一款国外著名的系统安全工具,它可以让选定程序在安全的隔离环境下运行,只要在此环境中运行的软件,浏览器或注册表信息等都可以完整的进行清空,不留一点痕迹。同时可以防御些带有木马或者病毒的恶意网站,对于经常测试软件或者不放心的软件,可放心在沙盘里面运行!下载地址:http://www.bytepan.com/J7BwpqQdKzR..._sandboxie系统安全工具
文章浏览阅读230次,点赞4次,收藏5次。Mac老用户都知道之前的老版本系统是可以设置一位数登陆密码的,但是更新到10.14以后就不可以了,今天就教大家怎么在新版本下设置Mac一位数登陆密码。
文章浏览阅读3.4k次。本该到此结束,但是上述实现的时候其实是把生成的每一步的奖励都使用统一的句子级reward,但该代码其实也额外按照每个token来计算奖励值的,为了获取每个token的奖励,我们在生成模型的隐层表示上,多加一个线性层,映射到一维,作为每个状态的预测奖励值。类似的,在文本生成中我们也可以用蒙特卡洛方法来估计一个模型的状态价值。假如我们只采样到了s1和s2,没有采样到s3,由于7和3都是正向奖励,s1和s2的训练后生成的概率都会变大,且s1的概率变的更大,这看似合理,但是s3是未参与训练的,它的概率反而减小了。_chatgpt使用的强化学习
文章浏览阅读433次,点赞10次,收藏8次。尝试了3种方法,都失败了!_truf计算重心
文章浏览阅读406次。学习LIS_poj 1631 hdu 1950为啥是最长上升子序列
文章浏览阅读550次。一、节点规划主机名称IP域名解析k8s-m-01192.168.12.51m1k8s-m-02192.168.12.52m2k8s-m-03192.168.12.53m3k8s-n-01192.168.12.54n1k8s-n-02192.168.12.55n2k8s-m-vip192.168.12.56vip二、插件规划#1.master节点规划kube-apiserverkube-controller-manage_sed -ie 's#image.*#image: ${ epic_image_fullname }#g
文章浏览阅读106次。UAC绕过提权_uac白名单 提权
文章浏览阅读664次,点赞7次,收藏12次。每次架设OpenVPN Server就很痛苦,步骤太多,会出错的地方也多,基本很少一次性成功的。
文章浏览阅读397次。 今天看了继承以及派生类,并且运行了教程中的一个实例,但是仍然有好多坑。主要如下:建立了一个基类bClass以及由基类bClass派生的一个dClass,并且建立两个头文件.h分别申明这两个类,在cpp程序中进行运行来检验。具体程序如下:#ifndef ITEM_BASE//为避免类重复定义,需要在头文件的开头和结尾加上如这个所示 #define ITEM_BASEclass bClass..._多个头文件相互包含
文章浏览阅读1.3w次,点赞19次,收藏88次。PyQt5安装详细教程,安装步骤很详细
文章浏览阅读154次。官方文档:https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html。_scroll-view去除滚动条
文章浏览阅读146次。S(k)=A^1+A^2...+A^k.保利求解就超时了,我们考虑一下当k为偶数的情况,A^1+A^2+A^3+A^4...+A^k,取其中前一半A^1+A^2...A^k/2,后一半提取公共矩阵A^k/2后可以发现也是前一半A^1+A^2...A^k/2。因此我们可以考虑只算其中一半,然后A^k/2用矩阵快速幂处理。对于k为奇数,只要转化为k-1+A^k即可。n为矩阵数量,m为矩阵..._a^1 a^2 ... a^k