OpenHarmony-2.DeviceInfo适配
- DeviceInfo适配说明
1.启动子系统设备信息说明
2.OHOS
2.1.OHOS 固定值参数适配
- OHOS 固定值参数:
const.ohos.version.security_patch
const.ohos.releasetype
const.ohos.apiversion
const.ohos.fullname
- 适配说明:
OHOS 固定值参数由OHOS系统填充,厂商不能也不需适配,参数主要定义:
/base/startup/init/services/etc/param/ohos_const/ohos.para:
13 const.ohos.version.security_patch=2024/08/01
14 const.ohos.releasetype=Release
15 const.ohos.apiversion=11
16 const.ohos.fullname=OpenHarmony-4.1.7.8
2.2.厂商固定值参数适配:
- 厂商固定值参数:
const.product.devicetype
const.product.manufacturer
const.product.brand
const.product.name
const.build.product
const.product.model
const.software.model
const.product.hardwareversion
const.product.hardwareprofile
const.product.software.version
const.product.bootloader.version
const.build.characteristics
... ...
- 适配说明:
由各产品根据自身情况在vendor目录下适配。
- 标准系统以RK3568为例,在/vendor/hihope/rk3568/etc/para/hardware_rk3568.para中适配,并安装到指定目录。
vendor/hihope/rk3568/etc/param/hardware_rk3568.para :
const.product.hardwareversion=default
vendor/hihope/rk3568/etc/BUILD.gn:
16 ohos_prebuilt_etc("para_for_chip_prod") {
17 source = "./param/hardware_rk3568.para"
18 install_images = [ chip_prod_base_dir ]
19 relative_install_dir = "param"
20 part_name = "product_rk3568"
21 }
3.厂商动态参数适配
厂商动态值参数,目前有三种获取形式:cmdline读取,编译宏定义,在BUILD.gn中定义。
-
cmdline中读取的值有:ohos.boot.hardware、ohos.boot.bootslots、ohos.boot.sn等,其中ohos.boot.sn的获取略有不同,具体如下:
-
标准系统 Serial从参数ohos.boot.sn读取。
ohos.boot.sn参数值的获取方式:首先从cmdline(由uboot生成)获取,如果获取到的是sn值则直接读取,若获取的是文件路径,则从文件中读取;当获取不到时从默认的Sn文件读取,默认文件为:/sys/block/mmcblk0/device/cid;/proc/bootdevice/cid。 -
轻量系统与小型系统的Serial各产品在实现过程中可能有自己特殊的算法,因此OpenHarmony支持在hals/utils/sys_param目录下hal_sys_param.c文件中通过HalGetSerial()接口自定算法来获取Serial。
-
-
在BUILD.gn中定义,参考文件/base/startup/init/services/etc/BUILD.gn
4.代码分析
startup/init/services/init/standard/init.c :
SystemConfig->LoadSpecialParam
429 void LoadSpecialParam(void)
430 {
431 // read param area size from cfg and save to dac
432 LoadParamAreaSize();
433 // read selinux label
434 LoadSelinuxLabel("init");
435 // from cmdline
436 LoadParamFromCmdLine();
437 // from build
438 LoadParamFromBuild();
439 }
- LoadParamAreaSize
startup/init/services/etc/param/ohos.para.size:
14 default_param=4096
15 hilog_param=40960
16 const_product_param=4096
17 startup_param=40960
18 persist_param=40960
19 const_param=40960
20 persist_sys_param=4096
21 devinfo_public_param=40960
22 sys_param=4096
23 bootevent_param=4096
24 startup_init_param=81920
25 hiviewdfx_profiler_param=2048
26 ohos_boot_param = 8192
27 bluetooth_param = 8192
28 hiviewdfx_hiview_param = 2048
29 telephony_param = 20480
30 vendor_camera_param=6144
31 edm_writable_param = 4096
- LoadParamFromCmdLine
startup/init/services/param/manager/param_server.c:
230 INIT_LOCAL_API int LoadParamFromCmdLine(void)
231 {
232 CmdLineIteratorCtx ctx;
233
234 ctx.gotSn = false;
235 ctx.cmdline = ReadFileData(BOOT_CMD_LINE);
236 PARAM_CHECK(ctx.cmdline != NULL, return -1, "Failed to read file %s", BOOT_CMD_LINE);
237
238 IterateNameValuePairs(ctx.cmdline, CmdlineIterator, (void *)(&ctx));
239
240 // sn is critical, it must be specified
241 if (!ctx.gotSn) {
242 PARAM_LOGE("Generate default sn now ...");
243 GenerateSnByDefault();
244 }
245
246 free(ctx.cmdline);
247 return 0;
248 }
215 static void GenerateSnByDefault(void)
216 {
217 const char *snFileList [] = {
218 "/sys/block/mmcblk0/device/cid",
219 "/proc/bootdevice/cid"
220 };
221
222 for (size_t i = 0; i < ARRAY_LENGTH(snFileList); i++) {
223 int ret = ReadSnFromFile(OHOS_CMDLINE_PARA_PREFIX "sn", snFileList[i]);
224 if (ret == 0) {
225 break;
226 }
227 }
228 }
refer to
- docs/en/device-dev/subsystems/subsys-boot-init-deviceInfo.md
- https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-deviceInfo.md
原文地址:https://blog.csdn.net/weixin_41028621/article/details/143849507
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!