Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
e7b1450a
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e7b1450a
编写于
2月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1745 support hooking device info api and extending ohos.boot. parameters from cmdline
Merge pull request !1745 from handy/0206
上级
74545390
33c4561f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
195 addition
and
94 deletion
+195
-94
begetd.gni
begetd.gni
+3
-2
interfaces/innerkits/BUILD.gn
interfaces/innerkits/BUILD.gn
+4
-0
interfaces/innerkits/syspara/param_comm.c
interfaces/innerkits/syspara/param_comm.c
+12
-0
interfaces/innerkits/syspara/param_comm.h
interfaces/innerkits/syspara/param_comm.h
+3
-0
services/include/init_utils.h
services/include/init_utils.h
+8
-0
services/param/include/param_utils.h
services/param/include/param_utils.h
+0
-11
services/param/linux/BUILD.gn
services/param/linux/BUILD.gn
+0
-7
services/param/manager/param_server.c
services/param/manager/param_server.c
+123
-74
services/utils/init_utils.c
services/utils/init_utils.c
+42
-0
未找到文件。
begetd.gni
浏览文件 @
e7b1450a
...
...
@@ -31,8 +31,6 @@ declare_args() {
# config memory size for liteos-m
config_ohos_startup_init_lite_memory_size = 5120
# boot_kernel_extended_cmdline for extend cmdline
startup_init_feature_decode_group_file = false
startup_init_test_performance = true
...
...
@@ -45,4 +43,7 @@ declare_args() {
startup_init_with_param_base = true
startup_init_feature_decode_group_file = true
}
# begetutil extension module
startup_begetutil_extra_modules = ""
}
interfaces/innerkits/BUILD.gn
浏览文件 @
e7b1450a
...
...
@@ -200,6 +200,10 @@ if (defined(ohos_lite)) {
"//third_party/mbedtls:mbedtls_shared",
]
deps += [ "//base/startup/init/services/param/base:param_base" ]
if (startup_begetutil_extra_modules != "") {
deps += [ startup_begetutil_extra_modules ]
}
external_deps = [
"c_utils:utils",
"hilog_native:libhilog_base",
...
...
interfaces/innerkits/syspara/param_comm.c
浏览文件 @
e7b1450a
...
...
@@ -92,6 +92,8 @@ INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value,
return
GetSystemError
(
ret
);
}
static
PropertyValueProcessor
propertyGetProcessor
=
NULL
;
INIT_LOCAL_API
const
char
*
GetProperty
(
const
char
*
key
,
const
char
**
paramHolder
)
{
BEGET_CHECK
(
paramHolder
!=
NULL
,
return
NULL
);
...
...
@@ -108,11 +110,21 @@ INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder
free
(
res
);
return
NULL
;
}
if
(
propertyGetProcessor
!=
NULL
)
{
res
=
propertyGetProcessor
(
key
,
res
);
}
*
paramHolder
=
res
;
}
return
*
paramHolder
;
}
INIT_LOCAL_API
PropertyValueProcessor
SetPropertyGetProcessor
(
PropertyValueProcessor
processor
)
{
PropertyValueProcessor
prev
=
propertyGetProcessor
;
propertyGetProcessor
=
processor
;
return
prev
;
}
INIT_LOCAL_API
const
char
*
GetProductModel_
(
void
)
{
static
const
char
*
productModel
=
NULL
;
...
...
interfaces/innerkits/syspara/param_comm.h
浏览文件 @
e7b1450a
...
...
@@ -30,7 +30,10 @@ extern "C" {
#define DEV_BUF_LENGTH 3
#define DEV_BUF_MAX_LENGTH 1024
typedef
char
*
(
*
PropertyValueProcessor
)(
const
char
*
key
,
char
*
value
);
INIT_LOCAL_API
const
char
*
GetProperty
(
const
char
*
key
,
const
char
**
paramHolder
);
INIT_LOCAL_API
PropertyValueProcessor
SetPropertyGetProcessor
(
PropertyValueProcessor
processor
);
INIT_LOCAL_API
int
GetParameter_
(
const
char
*
key
,
const
char
*
def
,
char
*
value
,
uint32_t
len
);
INIT_LOCAL_API
const
char
*
GetProductModel_
(
void
);
...
...
services/include/init_utils.h
浏览文件 @
e7b1450a
...
...
@@ -60,6 +60,14 @@ char *ReadFileToBuf(const char *configFile);
int
GetProcCmdlineValue
(
const
char
*
name
,
const
char
*
buffer
,
char
*
value
,
int
length
);
char
*
ReadFileData
(
const
char
*
fileName
);
typedef
struct
tagNAME_VALUE_PAIR
{
const
char
*
name
;
const
char
*
name_end
;
const
char
*
value
;
const
char
*
value_end
;
}
NAME_VALUE_PAIR
;
int
IterateNameValuePairs
(
const
char
*
src
,
void
(
*
iterator
)(
const
NAME_VALUE_PAIR
*
nv
,
void
*
context
),
void
*
context
);
int
SplitString
(
char
*
srcPtr
,
const
char
*
del
,
char
**
dstPtr
,
int
maxNum
);
void
WaitForFile
(
const
char
*
source
,
unsigned
int
maxSecond
);
size_t
WriteAll
(
int
fd
,
const
char
*
buffer
,
size_t
size
);
...
...
services/param/include/param_utils.h
浏览文件 @
e7b1450a
...
...
@@ -37,16 +37,6 @@ typedef enum {
#define PARAM_BUFFER_MAX (0x01 << 16)
#endif
struct
CmdLineEntry
{
char
*
key
;
int
set
;
};
typedef
struct
cmdLineInfo
{
const
char
*
name
;
int
(
*
processor
)(
const
char
*
name
,
const
char
*
value
,
int
);
}
cmdLineInfo
;
#define FILENAME_LEN_MAX 255
#define MS_UNIT 1000
#ifndef UNUSED
...
...
@@ -64,7 +54,6 @@ typedef struct cmdLineInfo {
#define OHOS_CTRL_START "ohos.ctl.start="
#define OHOS_CTRL_STOP "ohos.ctl.stop="
#define OHOS_SERVICE_CTRL_PREFIX "ohos.servicectrl."
#define OHOS_BOOT "ohos.boot."
#ifdef STARTUP_INIT_TEST
#define PARAM_STATIC
...
...
services/param/linux/BUILD.gn
浏览文件 @
e7b1450a
...
...
@@ -74,9 +74,6 @@ if (defined(ohos_lite)) {
include_dirs = param_include_dirs
public_configs = [ ":exported_header_files" ]
if (defined(boot_kernel_extended_cmdline)) {
defines += [ "BOOT_EXTENDED_CMDLINE=\"${boot_kernel_extended_cmdline}\"" ]
}
defines += [
"_GNU_SOURCE",
"__LINUX__",
...
...
@@ -112,10 +109,6 @@ if (defined(ohos_lite)) {
"PARAM_SUPPORT_REAL_CHECK",
]
if (defined(boot_kernel_extended_cmdline)) {
defines += [ "BOOT_EXTENDED_CMDLINE=\"${boot_kernel_extended_cmdline}\"" ]
}
if (param_base_log) {
defines += [ "PARAM_BASE_LOG" ]
}
...
...
services/param/manager/param_server.c
浏览文件 @
e7b1450a
...
...
@@ -18,43 +18,38 @@
#include "param_manager.h"
#include "param_trie.h"
static
int
LoadSecurityLabel
(
const
char
*
fileName
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
-
1
,
"Invalid paramSpace"
);
PARAM_WORKSPACE_CHECK
(
paramSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
fileName
!=
NULL
,
return
-
1
,
"Invalid filename for load"
);
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
// load security label
ParamSecurityOps
*
ops
=
GetParamSecurityOps
(
PARAM_SECURITY_DAC
);
if
(
ops
!=
NULL
&&
ops
->
securityGetLabel
!=
NULL
)
{
ops
->
securityGetLabel
(
fileName
);
}
#endif
return
0
;
}
/**
* Loading system parameter from /proc/cmdline by the following rules:
* 1) reserved cmdline with or without ohos.boot. prefix listed in CmdlineIterator
will be processed by the specified processor
* 2) cmdline not listed in CmdlineIterator but prefixed with ohos.boot will be add by default
*
* Special cases for sn:
* a) if sn value in cmdline is started with "/", it means a file to be read as parameter value
* b) if sn or ohos.boot.sn are not specified, try to generate sn by GenerateSnByDefault
*/
#define OHOS_CMDLINE_PARA_PREFIX "ohos.boot."
#define OHOS_CMDLINE_PARA_PREFIX_LEN 10
static
int
GetParamValueFromBuffer
(
const
char
*
name
,
const
char
*
buffer
,
char
*
value
,
int
length
)
{
size_t
bootLen
=
strlen
(
OHOS_BOOT
);
const
char
*
tmpName
=
name
+
bootLen
;
int
ret
=
GetProcCmdlineValue
(
tmpName
,
buffer
,
value
,
length
);
return
ret
;
}
typedef
struct
cmdLineInfo
{
const
char
*
name
;
int
(
*
processor
)(
const
char
*
name
,
const
char
*
value
);
}
cmdLineInfo
;
typedef
struct
cmdLineIteratorCtx
{
char
*
cmdline
;
bool
gotSn
;
}
cmdLineIteratorCtx
;
static
int
CommonDealFun
(
const
char
*
name
,
const
char
*
value
,
int
res
)
static
int
CommonDealFun
(
const
char
*
name
,
const
char
*
value
)
{
int
ret
=
0
;
if
(
res
==
0
)
{
PARAM_LOGV
(
"Add param from cmdline %s %s"
,
name
,
value
);
ret
=
CheckParamName
(
name
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid param name %s"
,
name
);
PARAM_LOGV
(
"Param name %s, value %s"
,
name
,
value
);
ret
=
WriteParam
(
name
,
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Failed to write param %s %s"
,
name
,
value
);
}
else
{
PARAM_LOGW
(
"Get %s parameter value is null."
,
name
);
}
PARAM_LOGV
(
"Add param from cmdline %s %s"
,
name
,
value
);
ret
=
CheckParamName
(
name
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid param name %s"
,
name
);
PARAM_LOGV
(
"Param name %s, value %s"
,
name
,
value
);
ret
=
WriteParam
(
name
,
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Failed to write param %s %s"
,
name
,
value
);
return
ret
;
}
...
...
@@ -82,71 +77,125 @@ static int ReadSnFromFile(const char *name, const char *file)
return
ret
;
}
static
int
SnDealFun
(
const
char
*
name
,
const
char
*
value
,
int
res
)
#define OHOS_SN_PARAM_NAME OHOS_CMDLINE_PARA_PREFIX"sn"
static
int
SnDealFun
(
const
char
*
name
,
const
char
*
value
)
{
const
char
*
snFileList
[]
=
{
"/sys/block/mmcblk0/device/cid"
,
"/proc/bootdevice/cid"
};
int
ret
=
CheckParamName
(
name
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid name %s"
,
name
);
if
(
value
!=
NULL
&&
res
==
0
&&
value
[
0
]
!=
'/'
)
{
if
(
value
!=
NULL
&&
value
[
0
]
!=
'/'
)
{
PARAM_LOGV
(
"**** name %s, value %s"
,
name
,
value
);
ret
=
WriteParam
(
name
,
value
,
NULL
,
0
);
ret
=
WriteParam
(
OHOS_SN_PARAM_NAME
,
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Failed to write param %s %s"
,
name
,
value
);
return
ret
;
}
if
(
value
!=
NULL
&&
value
[
0
]
==
'/'
)
{
ret
=
ReadSnFromFile
(
name
,
value
);
ret
=
ReadSnFromFile
(
OHOS_SN_PARAM_NAME
,
value
);
if
(
ret
==
0
)
{
return
ret
;
}
}
return
ret
;
}
static
void
CmdlineIterator
(
const
NAME_VALUE_PAIR
*
nv
,
void
*
context
)
{
const
char
*
name
;
char
fullName
[
PARAM_NAME_LEN_MAX
];
cmdLineIteratorCtx
*
ctx
=
(
cmdLineIteratorCtx
*
)
context
;
char
*
data
=
(
char
*
)
ctx
->
cmdline
;
static
const
cmdLineInfo
cmdLines
[]
=
{
{
"hardware"
,
CommonDealFun
},
{
"bootgroup"
,
CommonDealFun
},
{
"reboot_reason"
,
CommonDealFun
},
{
"bootslots"
,
CommonDealFun
},
{
"sn"
,
SnDealFun
},
{
"serialno"
,
SnDealFun
}
};
data
[
nv
->
name_end
-
data
]
=
'\0'
;
data
[
nv
->
value_end
-
data
]
=
'\0'
;
PARAM_LOGE
(
"proc cmdline: name [%s], value [%s]"
,
nv
->
name
,
nv
->
value
);
// Get name without prefix
name
=
nv
->
name
;
if
(
strncmp
(
name
,
OHOS_CMDLINE_PARA_PREFIX
,
OHOS_CMDLINE_PARA_PREFIX_LEN
)
==
0
)
{
name
=
name
+
OHOS_CMDLINE_PARA_PREFIX_LEN
;
}
// Matching reserved cmdlines
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
cmdLines
);
i
++
)
{
if
(
strcmp
(
name
,
cmdLines
[
i
].
name
)
==
0
)
{
snprintf_s
(
fullName
,
sizeof
(
fullName
),
sizeof
(
fullName
)
-
1
,
OHOS_CMDLINE_PARA_PREFIX
"%s"
,
cmdLines
[
i
].
name
);
PARAM_LOGE
(
"proc cmdline %s matched."
,
fullName
);
int
ret
=
cmdLines
[
i
].
processor
(
fullName
,
nv
->
value
);
if
((
ret
==
0
)
&&
(
SnDealFun
==
cmdLines
[
i
].
processor
))
{
ctx
->
gotSn
=
true
;
}
return
;
}
}
if
(
name
==
nv
->
name
)
{
return
;
}
// cmdline with prefix but not matched, add to param by default
PARAM_LOGE
(
"add proc cmdline param %s by default."
,
nv
->
name
);
CommonDealFun
(
nv
->
name
,
nv
->
value
);
}
static
void
GenerateSnByDefault
()
{
const
char
*
snFileList
[]
=
{
"/sys/block/mmcblk0/device/cid"
,
"/proc/bootdevice/cid"
};
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
snFileList
);
i
++
)
{
ret
=
ReadSnFromFile
(
name
,
snFileList
[
i
]);
int
ret
=
ReadSnFromFile
(
OHOS_CMDLINE_PARA_PREFIX
"sn"
,
snFileList
[
i
]);
if
(
ret
==
0
)
{
break
;
}
}
return
ret
;
}
INIT_LOCAL_API
int
LoadParamFromCmdLine
(
void
)
{
static
const
cmdLineInfo
cmdLines
[]
=
{
{
OHOS_BOOT
"hardware"
,
CommonDealFun
},
{
OHOS_BOOT
"bootgroup"
,
CommonDealFun
},
{
OHOS_BOOT
"reboot_reason"
,
CommonDealFun
},
{
OHOS_BOOT
"bootslots"
,
CommonDealFun
},
{
OHOS_BOOT
"sn"
,
SnDealFun
}
};
char
*
data
=
ReadFileData
(
BOOT_CMD_LINE
);
PARAM_CHECK
(
data
!=
NULL
,
return
-
1
,
"Failed to read file %s"
,
BOOT_CMD_LINE
);
char
*
value
=
calloc
(
1
,
PARAM_CONST_VALUE_LEN_MAX
+
1
);
PARAM_CHECK
(
value
!=
NULL
,
free
(
data
);
return
-
1
,
"Failed to read file %s"
,
BOOT_CMD_LINE
);
cmdLineIteratorCtx
ctx
;
for
(
size_t
i
=
0
;
i
<
ARRAY_LENGTH
(
cmdLines
);
i
++
)
{
int
ret
=
0
;
#ifdef BOOT_EXTENDED_CMDLINE
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
].
name
,
BOOT_EXTENDED_CMDLINE
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
if
(
ret
!=
0
)
{
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
].
name
,
data
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
}
#else
ret
=
GetParamValueFromBuffer
(
cmdLines
[
i
].
name
,
data
,
value
,
PARAM_CONST_VALUE_LEN_MAX
);
#endif
ctx
.
gotSn
=
false
;
ctx
.
cmdline
=
ReadFileData
(
BOOT_CMD_LINE
);
PARAM_CHECK
(
ctx
.
cmdline
!=
NULL
,
return
-
1
,
"Failed to read file %s"
,
BOOT_CMD_LINE
);
cmdLines
[
i
].
processor
(
cmdLines
[
i
].
name
,
value
,
ret
);
IterateNameValuePairs
(
ctx
.
cmdline
,
CmdlineIterator
,
(
void
*
)(
&
ctx
));
// sn is critical, it must be specified
if
(
!
ctx
.
gotSn
)
{
PARAM_LOGE
(
"Generate default sn now ..."
);
GenerateSnByDefault
();
}
PARAM_LOGV
(
"Parse cmdline finish %s"
,
BOOT_CMD_LINE
);
free
(
data
);
free
(
value
);
free
(
ctx
.
cmdline
);
return
0
;
}
/*
* Load parameters from files
*/
static
int
LoadSecurityLabel
(
const
char
*
fileName
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
-
1
,
"Invalid paramSpace"
);
PARAM_WORKSPACE_CHECK
(
paramSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
fileName
!=
NULL
,
return
-
1
,
"Invalid filename for load"
);
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
// load security label
ParamSecurityOps
*
ops
=
GetParamSecurityOps
(
PARAM_SECURITY_DAC
);
if
(
ops
!=
NULL
&&
ops
->
securityGetLabel
!=
NULL
)
{
ops
->
securityGetLabel
(
fileName
);
}
#endif
return
0
;
}
...
...
services/utils/init_utils.c
浏览文件 @
e7b1450a
...
...
@@ -202,6 +202,48 @@ char *ReadFileData(const char *fileName)
return
buffer
;
}
int
IterateNameValuePairs
(
const
char
*
src
,
void
(
*
iterator
)(
const
NAME_VALUE_PAIR
*
nv
,
void
*
context
),
void
*
context
)
{
int
cnt
=
0
;
const
char
*
seperator
;
NAME_VALUE_PAIR
nv
;
if
((
src
==
NULL
)
||
(
iterator
==
NULL
))
{
return
-
1
;
}
do
{
// Find space seperator
nv
.
name
=
src
;
seperator
=
strchr
(
src
,
' '
);
if
(
seperator
==
NULL
)
{
// Last nv
nv
.
value_end
=
src
+
strlen
(
src
);
src
=
NULL
;
}
else
{
nv
.
value_end
=
seperator
;
src
=
seperator
+
1
;
}
// Find equal seperator
seperator
=
strchr
(
nv
.
name
,
'='
);
if
(
seperator
==
NULL
)
{
// Invalid name value pair
continue
;
}
if
(
seperator
>
nv
.
value_end
)
{
// name without value, just ignore
continue
;
}
nv
.
name_end
=
seperator
;
nv
.
value
=
seperator
+
1
;
iterator
(
&
nv
,
context
);
cnt
+=
1
;
}
while
(
src
!=
NULL
);
return
cnt
;
}
int
GetProcCmdlineValue
(
const
char
*
name
,
const
char
*
buffer
,
char
*
value
,
int
length
)
{
INIT_ERROR_CHECK
(
name
!=
NULL
&&
buffer
!=
NULL
&&
value
!=
NULL
,
return
-
1
,
"Failed get parameters"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录