未验证 提交 0051965d 编写于 作者: O openharmony_ci 提交者: Gitee

!1933 Add: 挂载新增eng_system, eng_chipset分区

Merge pull request !1933 from cheng_jinsong/init_eng_mode
......@@ -19,5 +19,7 @@
{ "name": "GetServiceExtData" },
{ "name": "UpdateMiscMessage" },
{ "name": "AddRebootCmdExecutor" },
{ "name": "GetBootEventList" }
{ "name": "GetBootEventList" },
{ "name": "WaitForFile" },
{ "name": "DoCmdByName" }
]
......@@ -17,6 +17,7 @@ group("static_modules") {
deps = [
"bootchart:libbootchart_static",
"bootevent:libbootevent_static",
"init_eng:libiniteng_static",
"init_hook:inithook",
"reboot:libreboot_static",
"udid:libudid_static",
......@@ -38,6 +39,7 @@ group("modulesgroup") {
if (!defined(ohos_lite)) {
deps = [
"bootchart:bootchart",
"init_eng:init_eng",
"reboot:rebootmodule",
"sysevent:eventmodule",
"trace:inittrace",
......
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/startup/init/begetd.gni")
import("//build/ohos.gni")
comm_include = [
".",
"..",
"../../include",
"../../include/param",
]
ohos_shared_library("init_eng") {
sources = [ "init_eng.c" ]
include_dirs = comm_include
include_dirs += [ "../../init/include" ]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
external_deps = [ "init:libinit_module_engine" ]
part_name = "init"
subsystem_name = "startup"
if (target_cpu == "arm64") {
module_install_dir = "lib64/init"
} else {
module_install_dir = "lib/init"
}
}
config("initeng_static_config") {
include_dirs = comm_include
}
ohos_source_set("libiniteng_static") {
sources = [ "init_eng_static.c" ]
include_dirs = comm_include
public_configs = [ ":initeng_static_config" ]
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
part_name = "init"
subsystem_name = "startup"
}
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dirent.h>
#include <limits.h>
#include <sys/mount.h>
#include "plugin_adapter.h"
#include "init_cmds.h"
#include "init_utils.h"
#include "init_module_engine.h"
#include "securec.h"
#define MOUNT_CMD_MAX_LEN 128U
#define ENG_SYSTEM_DEVICE_PATH "/dev/block/by-name/eng_system"
#define ENG_CHIPSET_DEVICE_PATH "/dev/block/by-name/eng_chipset"
typedef enum {
TYPE_DIR = 0,
TYPE_REG,
TYPE_LINK,
TYPE_ANY
} FileType;
static bool IsFileExistWithType(const char *file, FileType type)
{
bool isExist = false;
struct stat st = {};
if (lstat(file, &st) == 0) {
switch (type) {
case TYPE_DIR:
if (S_ISDIR(st.st_mode)) {
isExist = true;
}
break;
case TYPE_REG:
if (S_ISREG(st.st_mode)) {
isExist = true;
}
break;
case TYPE_LINK:
if (S_ISLNK(st.st_mode)) {
isExist = true;
}
break;
case TYPE_ANY: // fallthrough
default:
isExist = true;
break;
}
}
return isExist;
}
static bool IsRegularFile(const char *file)
{
return file == NULL ? false : IsFileExistWithType(file, TYPE_REG);
}
static bool IsExistFile(const char *file)
{
return file == NULL ? false : IsFileExistWithType(file, TYPE_ANY);
}
static void BuildMountCmd(char *buffer, size_t len, const char *mp, const char *dev, const char *fstype)
{
int ret = snprintf_s(buffer, len, len - 1, "%s %s %s ro barrier=1",
fstype, dev, mp);
if (ret == -1) {
*buffer = '\0';
}
}
static void MountEngPartitions(void)
{
char mountCmd[MOUNT_CMD_MAX_LEN] = {};
// Mount eng_system
BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_system",
"/dev/block/by-name/eng_system", "ext4");
WaitForFile(ENG_SYSTEM_DEVICE_PATH, WAIT_MAX_SECOND);
DoCmdByName("mount ", mountCmd);
// Mount eng_chipset
BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_chipset",
"/dev/block/by-name/eng_chipset", "ext4");
WaitForFile(ENG_CHIPSET_DEVICE_PATH, WAIT_MAX_SECOND);
DoCmdByName("mount ", mountCmd);
}
static void BindMountFile(const char *source, const char *target)
{
char targetFullPath[PATH_MAX] = {};
const char *p = source;
char *q = NULL;
const char *end = source + strlen(source);
if (*p != '/') { // source must start with '/'
return;
}
// Get next '/'
q = strchr(p + 1, '/');
if (q == NULL) {
PLUGIN_LOGI("path \' %s \' without extra slash, ignore it", source);
return;
}
if (q == end - 1) {
PLUGIN_LOGI("path \' %s \' ends with slash, ignore it", source);
return;
}
// OK, now get sub dir and combine it with target
int ret = snprintf_s(targetFullPath, PATH_MAX, PATH_MAX - 1, "%s%s", strcmp(target, "/") == 0 ? "" : target, q);
if (ret == -1) {
PLUGIN_LOGE("Failed to build target path");
return;
}
PLUGIN_LOGI("target full path is %s", targetFullPath);
if (IsRegularFile(targetFullPath)) {
if (mount(source, targetFullPath, NULL, MS_BIND, NULL) != 0) {
PLUGIN_LOGE("Failed to bind mount %s to %s, err = %d", source, targetFullPath, errno);
} else {
PLUGIN_LOGI("Bind mount %s to %s done", source, targetFullPath);
}
} else {
if (!IsExistFile(targetFullPath)) {
if (symlink(source, targetFullPath) < 0) {
PLUGIN_LOGE("Failed to link %s to %s, err = %d", source, targetFullPath, errno);
}
} else {
PLUGIN_LOGW("%s without expected type, skip overlay", targetFullPath);
}
}
}
static void DebugFilesOverlay(const char *source, const char *target)
{
DIR *dir = NULL;
struct dirent *de = NULL;
if ((dir = opendir(source)) == NULL) {
PLUGIN_LOGE("Open path \' %s \' failed. err = %d", source, errno);
return;
}
int dfd = dirfd(dir);
char srcPath[PATH_MAX] = {};
while ((de = readdir(dir)) != NULL) {
if (de->d_name[0] == '.') {
continue;
}
if (snprintf_s(srcPath, PATH_MAX, PATH_MAX - 1, "%s/%s",source, de->d_name) == -1) {
PLUGIN_LOGE("Failed to build path for overlaying");
break;
}
// Determine file type
struct stat st = {};
if (fstatat(dfd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
continue;
}
if (S_ISDIR(st.st_mode)) {
DebugFilesOverlay(srcPath, target);
} else if (S_ISREG(st.st_mode)) {
BindMountFile(srcPath, target);
} else { // Ignore any other file types
PLUGIN_LOGI("Ignore %s while overlaying", srcPath);
}
}
closedir(dir);
dir = NULL;
}
static void EngineerOverlay(void)
{
PLUGIN_LOGI("system overlay...");
DebugFilesOverlay("/eng_system", "/");
PLUGIN_LOGI("vendor overlay...");
DebugFilesOverlay("/eng_chipset", "/chipset");
}
MODULE_CONSTRUCTOR(void)
{
PLUGIN_LOGI("Start eng mode now ...");
MountEngPartitions();
EngineerOverlay();
}
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
#include "init_module_engine.h"
#include "plugin_adapter.h"
#include "init_utils.h"
static int InitEngEarlyHook(const HOOK_INFO *info, void *cookie)
{
char value[MAX_BUFFER_LEN] = {0};
int ret = GetParameterFromCmdLine("eng_mode", value, MAX_BUFFER_LEN);
if (ret == 0 && strcmp(value, "on") == 0) {
InitModuleMgrInstall("init_eng");
InitModuleMgrUnInstall("init_eng");
PLUGIN_LOGI("eng_mode enable.");
}
return 0;
}
MODULE_CONSTRUCTOR(void)
{
InitAddGlobalInitHook(0, InitEngEarlyHook);
}
......@@ -115,6 +115,7 @@ static void CmdlineIterator(const NAME_VALUE_PAIR *nv, void *context)
{ "reboot_reason", CommonDealFun },
{ "bootslots", CommonDealFun },
{ "sn", SnDealFun },
{ "eng_mode", CommonDealFun },
{ "serialno", SnDealFun }
};
......
......@@ -368,7 +368,8 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
void WaitForFile(const char *source, unsigned int maxSecond)
{
INIT_ERROR_CHECK(maxSecond <= WAIT_MAX_SECOND, maxSecond = WAIT_MAX_SECOND, "WaitForFile max time is 5s");
INIT_ERROR_CHECK(maxSecond <= WAIT_MAX_SECOND, maxSecond = WAIT_MAX_SECOND,
"WaitForFile max time is %us", WAIT_MAX_SECOND);
struct stat sourceInfo = {0};
unsigned int waitTime = 500000;
/* 500ms interval, check maxSecond*2 times total */
......
......@@ -184,6 +184,7 @@ static void HandleRequiredBlockDeviceNodes(const struct Uevent *uevent, char **d
} else if (strstr(devices[i], uevent->partitionName) != NULL ||
strstr(uevent->partitionName, "vendor") != NULL ||
strstr(uevent->partitionName, "system") != NULL ||
strstr(uevent->partitionName, "chipset") != NULL ||
strstr(uevent->partitionName, "boot") != NULL ||
strstr(uevent->partitionName, "ramdisk") != NULL ||
strstr(uevent->partitionName, "rvt") != NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册