diff --git a/README.md b/README.md index 7953eb83c86adbbbf032d232136ff9b4d66e9d4c..cdf37172fc7b0933d77e463e89bb7fe941c612f2 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ## Introduction -The updater runs in the recovery partition. It reads the misc partition information to obtain the update package status and verifies the update package to ensure that the update package is valid. Then, the updater parses the executable program from the update package, creates a subprocess, and starts the update program. After that, update operations will be automatically implemented by the update script. +The updater runs in the updater partition. It reads the misc partition information to obtain the update package status and verifies the update package to ensure that the update package is valid. Then, the updater parses the executable program from the update package, creates a subprocess, and starts the update program. After that, update operations will be automatically implemented by the update script. ## Directory Structure @@ -37,11 +37,11 @@ base/update/updater/ ### Usage Guidelines -The updater runs in the recovery partition. To ensure proper functioning of the updater, perform the following operations: +The updater runs in the updater partition. To ensure proper functioning of the updater, perform the following operations: -1. Create a recovery partition. +1. Create a updater partition. -The recovery partition is independent of other partitions. It is recommended that the size of the recovery partition be greater than or equal to 20 MB. The recovery partition image is an ext4 file system. Ensure that the **config** option of the ext4 file system in the system kernel is enabled. +The updater partition is independent of other partitions. It is recommended that the size of the updater partition be greater than or equal to 20 MB. The updater partition image is an ext4 file system. Ensure that the **config** option of the ext4 file system in the system kernel is enabled. 2. Create the misc partition. @@ -53,7 +53,7 @@ During the update process, the updater needs to operate the partitions through t 4. Start the updater. -The init process in the recovery partition has an independent configuration file named **init.cfg**. The startup configuration of the updater is stored in this file. +The init process in the updater partition has an independent configuration file named **init.cfg**. The startup configuration of the updater is stored in this file. 5. Compile the updater. @@ -78,7 +78,7 @@ For example, to add the updater for Hi3516D V300, add the following code to the "updater:updater":{}, ``` -6. Compile the recovery partition image. +6. Compile the updater partition image. Add the compilation configuration to the **build\_updater\_image.sh** script, which is stored in the **build** repository and called by the OpenHarmony compilation system. diff --git a/README_zh.md b/README_zh.md index 62c79a58d6bb97d11e1446188f4fb0827a9b4e50..e8900d27e211e017119d5b88ec19cf2c07e74640 100755 --- a/README_zh.md +++ b/README_zh.md @@ -9,7 +9,7 @@ ## 简介 -升级包安装组件运行在recovery分区,其功能主要包括读取misc分区信息获取升级包状态,对升级包进行校验,确保升级包合法有效;然后从升级包中解析出升级的可执行程序,创建子进程并启动升级程序。具体升级的动作由升级脚本控制。 +升级包安装组件运行在updater分区,其功能主要包括读取misc分区信息获取升级包状态,对升级包进行校验,确保升级包合法有效;然后从升级包中解析出升级的可执行程序,创建子进程并启动升级程序。具体升级的动作由升级脚本控制。 ## 目录 @@ -37,11 +37,11 @@ base/update/updater/ ### 使用说明 -升级包安装组件运行在recovery分区里,需要如下的操作 +升级包安装组件运行在updater分区里,需要如下的操作 -1、创建recovery分区 +1、创建updater分区 -recovery是一个独立的分区,分区大小建议不小于20MB。recovery分区镜像是ext4 格式文件系统。确保系统内核ext4 文件系统的config 是打开状态。 +updater是一个独立的分区,分区大小建议不小于20MB。updater分区镜像是ext4 格式文件系统。确保系统内核ext4 文件系统的config 是打开状态。 2、创建misc分区 @@ -53,7 +53,7 @@ misc 分区中存储了升级子系统在升级过程中需要的元数据\(meta 4、升级包安装组件启动 -recovery分区的init 进程有单独的配置文件 init.cfg,升级包安装进程启动配置在该文件中。 +updater分区的init 进程有单独的配置文件 init.cfg,升级包安装进程启动配置在该文件中。 5、升级包安装组件编译 @@ -78,7 +78,7 @@ b、 产品中添加需要编译的组件 "updater:updater":{}, ``` -6、recovery分区镜像编译 +6、updater分区镜像编译 编译配置在build仓下,build\_updater\_image.sh 脚本中,该脚本由OHOS 编译系统调用。 diff --git a/interfaces/kits/include/misc_info/misc_info.h b/interfaces/kits/include/misc_info/misc_info.h index 38f781fd0587162ee6c24bec5f31138cee882cbe..a69cc8e29ddcbbe3d67c9fdc566d65192e286b5a 100755 --- a/interfaces/kits/include/misc_info/misc_info.h +++ b/interfaces/kits/include/misc_info/misc_info.h @@ -47,5 +47,7 @@ struct UpdateMessage { bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot); bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot); +bool WriteUpdaterMiscMsg(const UpdateMessage &boot); +bool ReadUpdaterMiscMsg(UpdateMessage &boot); } // updater #endif /* MISC_INFO_H */ diff --git a/interfaces/kits/misc_info/BUILD.gn b/interfaces/kits/misc_info/BUILD.gn index a184f973724040a4762002764e1d189cbc7a3dc5..37a3aedcd846fe3a88e63f358d36b6f31e9fbbb6 100755 --- a/interfaces/kits/misc_info/BUILD.gn +++ b/interfaces/kits/misc_info/BUILD.gn @@ -30,4 +30,7 @@ ohos_static_library("libmiscinfo") { ] external_deps = [ "init:libbegetutil" ] + + subsystem_name = "updater" + part_name = "updater" } diff --git a/interfaces/kits/misc_info/misc_info.cpp b/interfaces/kits/misc_info/misc_info.cpp index cf40c7f46df782ca909a7ca3797f00208990e6b0..83d9e6c81d2dc4f008585de6fe35c01b9b5dc02e 100755 --- a/interfaces/kits/misc_info/misc_info.cpp +++ b/interfaces/kits/misc_info/misc_info.cpp @@ -19,6 +19,7 @@ #include "fs_manager/mount.h" #include "log/log.h" #include "securec.h" +#include "updater/updater_const.h" namespace updater { bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot) @@ -55,4 +56,20 @@ bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot) "ReadUpdaterMessage memcpy failed", return false); return true; } + +bool WriteUpdaterMiscMsg(const UpdateMessage &boot) +{ + auto path = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", path = MISC_FILE); + LOG(INFO) << "WriteUpdaterMiscMsg::misc path : " << path; + return WriteUpdaterMessage(path, boot); +} + +bool ReadUpdaterMiscMsg(UpdateMessage &boot) +{ + auto path = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", path = MISC_FILE); + LOG(INFO) << "ReadUpdaterMiscMsg::misc path : " << path; + return ReadUpdaterMessage(path, boot); +} } // updater diff --git a/interfaces/kits/packages/BUILD.gn b/interfaces/kits/packages/BUILD.gn index aad7ffe481546e0eac38bc98a3e3c8c71f7e9f51..9d8efcd3da25bbf9ac63d66e60a5fa59479456df 100755 --- a/interfaces/kits/packages/BUILD.gn +++ b/interfaces/kits/packages/BUILD.gn @@ -33,4 +33,6 @@ ohos_static_library("libpackageExt") { "//third_party/openssl:ssl_source", "//third_party/zlib:libz", ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/interfaces/kits/updaterkits/BUILD.gn b/interfaces/kits/updaterkits/BUILD.gn index 6cd54b647b212e9e5d3d13b30e3deed2757aaf9d..2c68114f85aefa181ba731b310200d73021ff3ca 100755 --- a/interfaces/kits/updaterkits/BUILD.gn +++ b/interfaces/kits/updaterkits/BUILD.gn @@ -29,4 +29,8 @@ ohos_static_library("libupdaterkits") { "//base/update/updater/utils:libutils", "//third_party/bounds_checking_function:libsec_static", ] + + external_deps = [ "init:libbegetutil" ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index bfc2a6a4ff47c3b5648d39fc1f2ec13f305d9ab7..227621f56eea5211cd0c3b2acbc576a027af477d 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "misc_info/misc_info.h" #include "parameters.h" #include "securec.h" @@ -38,12 +39,8 @@ static bool WriteToMiscAndRebootToUpdater(const std::string &miscFile, #ifndef UPDATER_UT int32_t propertyMaxSize = 92; char updateCmd[propertyMaxSize]; - void(snprintf_s(updateCmd, propertyMaxSize, propertyMaxSize - 1, "reboot,updater:%s", updateMsg.update)); - bool bRet = OHOS::system::SetParameter("ohos.startup.powerctrl", updateCmd); - if (!bRet) { - std::cout << "WriteToMiscAndRebootToUpdater SetParameter failed, errno: " << errno << std::endl; - return false; - } + void(snprintf_s(updateCmd, propertyMaxSize, propertyMaxSize - 1, "updater:%s", updateMsg.update)); + DoReboot(updateCmd); while (true) { pause(); } diff --git a/services/BUILD.gn b/services/BUILD.gn index a82b38f5aef2a220642ab9e557c4632261c61efd..d807484c8796d3c87a04156c95ca9aafd71a2b1d 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -15,47 +15,6 @@ import("//build/ohos.gni") SUBSYSTEM_DIR = "//base/update/updater" -ohos_prebuilt_etc("updater_init.cfg") { - source = "//base/update/updater/services/etc/init.cfg" - install_images = [ "updater" ] - part_name = "updater" -} - -ohos_prebuilt_etc("updater_usb_init.cfg") { - source = "//base/update/updater/services/etc/init.usb.cfg" - install_images = [ "updater" ] - part_name = "updater" -} - -ohos_prebuilt_etc("updater_init_usb_configfs.cfg") { - source = "//base/update/updater/services/etc/init.usb.configfs.cfg" - install_images = [ "updater" ] - part_name = "updater" -} - -ohos_prebuilt_etc("signing_cert.crt") { - source = "//device/board/hisilicon/hispark_taurus/linux/updater/config/signing_cert.crt" - module_install_dir = "certificate" - install_images = [ "updater" ] - part_name = "updater" -} - -ohos_prebuilt_etc("fstab.updater") { - source = "//device/board/hisilicon/hispark_taurus/linux/updater/config/fstab.updater" - install_images = [ "updater" ] - part_name = "updater" -} - -group("updater_etc") { - deps = [ - ":fstab.updater", - ":signing_cert.crt", - ":updater_init.cfg", - ":updater_init_usb_configfs.cfg", - ":updater_usb_init.cfg", - ] -} - ohos_executable("updater") { defines = [ "BUILD_OHOS" ] sources = [ diff --git a/services/applypatch/BUILD.gn b/services/applypatch/BUILD.gn index f758e3cc064f84e3ba17d14f3cf5bf95c1a94e1d..ec459547cd3c18d3424584c3aba5b7d68d5d1cc8 100644 --- a/services/applypatch/BUILD.gn +++ b/services/applypatch/BUILD.gn @@ -48,4 +48,6 @@ ohos_static_library("libapplypatch") { "//third_party/bzip2:libbz2", ] external_deps = [ "init:libbegetutil" ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/applypatch/transfer_manager.cpp b/services/applypatch/transfer_manager.cpp index 6ba2e13db99a2acbba140fb4c3ce6eed32a22dc9..f2281560815dbe6222e4beafd35b3bade0b040d2 100644 --- a/services/applypatch/transfer_manager.cpp +++ b/services/applypatch/transfer_manager.cpp @@ -156,12 +156,10 @@ bool TransferManager::CheckResult(const CommandResult result, const std::string LOG(INFO) << "Running command need retry!"; UPDATER_CHECK_ONLY_RETURN(!globalParams->env, globalParams->env->PostMessage("retry_update", cmd)); return false; - break; case FAILED: default: LOG(ERROR) << "Running command failed"; return false; - break; } return true; } diff --git a/services/diffpatch/diff/BUILD.gn b/services/diffpatch/diff/BUILD.gn index e9e37cdee270ad35859ae98f8105d1d423cdff5b..c980ca099717c89aa3d83201ae30e2c039a9934b 100644 --- a/services/diffpatch/diff/BUILD.gn +++ b/services/diffpatch/diff/BUILD.gn @@ -46,4 +46,7 @@ ohos_static_library("libdiff") { "//third_party/bzip2:libbz2", ] configs = [ ":diff_config" ] + + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/diffpatch/patch/BUILD.gn b/services/diffpatch/patch/BUILD.gn index 0a28158aa93ee6af534a8ef9af6c58e846ffdd52..912a88b2e9b70e5d3794ee1cb2fdd6bd141de3bd 100644 --- a/services/diffpatch/patch/BUILD.gn +++ b/services/diffpatch/patch/BUILD.gn @@ -52,4 +52,6 @@ ohos_static_library("libpatch") { ] configs = [ ":patch_config" ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/etc/init.cfg b/services/etc/init.cfg deleted file mode 100755 index c69e192aa5112637b528b009ebf6f69cb579ca94..0000000000000000000000000000000000000000 --- a/services/etc/init.cfg +++ /dev/null @@ -1,100 +0,0 @@ -{ - "import" : [ - "/etc/init.Hi3516DV300.updater.cfg" - ], - "jobs" : [{ - "name" : "pre-init", - "cmds" : [ - "symlink /system/bin /bin", - "start ueventd" - ] - }, { - "name" : "init", - "cmds" : [ - "mkdir /system", - "mkdir /vendor", - "mkdir /tmp", - "mkdir /param", - "mount tmpfs tmpfs /tmp", - "chown 0 2000 /tmp", - "chmod 0755 /tmp", - "chmod 0755 /param", - "mkdir /dev/usb-ffs 0770 shell shell", - "mkdir /dev/usb-ffs/hdc 0770 shell shell", - "mkdir /dev/usb-ffs/hdc 0770 shell shell", - "mkdir /config 0770 shell shell", - "mount configfs none /config", - "mkdir /config/usb_gadget/g1 0770 shell shell", - "write /config/usb_gadget/g1/idVendor 0x12D1", - "write /config/usb_gadget/g1/idProduct 0x5000", - "write /config/usb_gadget/g1/os_desc/use 1", - "write /config/usb_gadget/g1/bcdDevice 0x0223", - "write /config/usb_gadget/g1/bcdUSB 0x0200", - "mkdir /config/usb_gadget/g1/strings/0x409 0770", - "copy /sys/block/mmcblk0/device/cid /config/usb_gadget/g1/strings/0x409/serialnumber", - "write /config/usb_gadget/g1/strings/0x409/manufacturer HISILICON", - "write /config/usb_gadget/g1/strings/0x409/product \"HDC Device\"", - "mkdir /config/usb_gadget/g1/functions/ffs.hdc", - "mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell", - "mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell", - "write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1", - "write /config/usb_gadget/g1/os_desc/qw_sign MSFT100", - "write /config/usb_gadget/g1/configs/b.1/MaxPower 500", - "symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1", - "mount functionfs hdc /dev/usb-ffs/hdc uid=2000,gid=2000", - "load_persist_params ", - "setparam sys.usb.controller 100e0000.hidwc3_0", - "setparam sys.usb.config hdc", - "setparam sys.usb.configfs 1" - ] - }, { - "name" : "post-init", - "cmds" : [ - "start shell", - "start updater" - ] - } - ], - "services" : [{ - "name" : "shell", - "path" : ["/bin/sh"], - "uid" : 0, - "gid" : 2000, - "once" : 0, - "importance" : 0, - "console" : 1 - }, { - "name" : "updater", - "path" : ["/bin/updater"], - "uid" : 0, - "gid" : 0, - "importance" : 0, - "caps" : [0, 1] - }, { - "name" : "ueventd", - "path" : ["/bin/ueventd"], - "uid" : 0, - "gid" : 2000, - "once" : 0, - "importance" : 0, - "caps" : [0, 1], - "socket" : [{ - "name" : "ueventd", - "family" : "AF_NETLINK", - "type" : "SOCK_DGRAM", - "protocol" : "NETLINK_KOBJECT_UEVENT", - "permissions" : "0660", - "uid" : "0", - "gid" : "2000", - "option" : [ - "SOCKET_OPTION_PASSCRED", - "SOCKET_OPTION_RCVBUFFORCE", - "SOCK_CLOEXEC", - "SOCK_NONBLOCK" - ] - }], - "critical" : [ 0, 15, 5], - "ondemand" : true - } - ] -} diff --git a/services/etc/init.usb.cfg b/services/etc/init.usb.cfg deleted file mode 100755 index 1a3072219b4bc774fbfc5b69fc6a755767b26c8c..0000000000000000000000000000000000000000 --- a/services/etc/init.usb.cfg +++ /dev/null @@ -1,15 +0,0 @@ -{ - "jobs" : [{ - "name" : "boot", - "cmds" : [ - "setparam sys.usb.configfs 0" - ] - }, { - "name" : "boot && param:persist.sys.usb.config=*", - "condition" : "boot && persist.sys.usb.config=*", - "cmds" : [ - "setparam sys.usb.config ${persist.sys.usb.config}" - ] - } - ] -} diff --git a/services/etc/init.usb.configfs.cfg b/services/etc/init.usb.configfs.cfg deleted file mode 100755 index 4474b0989ec5a86369126a73fe228eecfc113192..0000000000000000000000000000000000000000 --- a/services/etc/init.usb.configfs.cfg +++ /dev/null @@ -1,25 +0,0 @@ -{ - "jobs" : [{ - "name" : "param:sys.usb.config=none && param:sys.usb.configfs=1", - "condition" : "sys.usb.config=none && sys.usb.configfs=1", - "cmds" : [ - "write /config/usb_gadget/g1/UDC none", - "setparam sys.usb.ffs.ready 0", - "write /config/usb_gadget/g1/bDeviceClass 0", - "write /config/usb_gadget/g1/bDeviceSubClass 0", - "write /config/usb_gadget/g1/bDeviceProtocol 0", - "rm /config/usb_gadget/g1/configs/b.1/f1", - "setparam sys.usb.state ${sys.usb.config}" - ] - }, { - "name" : "param:sys.usb.ffs.ready=1 && param:sys.usb.config=hdc && param:sys.usb.configfs=1", - "condition" : "sys.usb.ffs.ready=1 && sys.usb.config=hdc && sys.usb.configfs=1", - "cmds" : [ - "write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration hdc", - "symlink /config/usb_gadget/g1/functions/ffs.hdc /config/usb_gadget/g1/configs/b.1/f1", - "write /config/usb_gadget/g1/UDC ${sys.usb.controller}", - "setparam sys.usb.state ${sys.usb.config}" - ] - } - ] -} diff --git a/services/flashd/BUILD.gn b/services/flashd/BUILD.gn index c505c593e36598b8c5626cd0b526b8cc86d2e64a..8f37f8a17e7535ef5a208608822c652999117c38 100755 --- a/services/flashd/BUILD.gn +++ b/services/flashd/BUILD.gn @@ -84,6 +84,9 @@ ohos_source_set("flashd_deamon") { "//third_party/openssl/include", "//third_party/libuv", ] + + subsystem_name = "updater" + part_name = "updater" } ohos_static_library("libflashd") { diff --git a/services/flashd/host/translate.cpp b/services/flashd/host/translate.cpp index dc7bc09dad65682eda494600612fd920e8bdf909..a300c7454d70a851e2d5ed127e68c43c84053096 100755 --- a/services/flashd/host/translate.cpp +++ b/services/flashd/host/translate.cpp @@ -208,8 +208,6 @@ namespace TranslateCommand { TargetReboot(input.c_str(), outCmd); } else if (!strncmp(input.c_str(), CMDSTR_TARGET_MODE.c_str(), CMDSTR_TARGET_MODE.size())) { RunMode(input.c_str(), outCmd); - } else if (!strcmp(input.c_str(), CMDSTR_CONNECT_ANY.c_str())) { - outCmd->cmdFlag = CMD_KERNEL_TARGET_ANY; } else if (!strncmp(input.c_str(), CMDSTR_HILOG.c_str(), CMDSTR_HILOG.size())) { outCmd->cmdFlag = CMD_UNITY_HILOG; if (strstr(input.c_str(), " -v")) { diff --git a/services/fs_manager/BUILD.gn b/services/fs_manager/BUILD.gn index 911b235edf07b43a9959c5547aa63bdae14da870..604e9096a4d9e691f54b754398cf3f4e563ba8c1 100644 --- a/services/fs_manager/BUILD.gn +++ b/services/fs_manager/BUILD.gn @@ -34,4 +34,6 @@ ohos_static_library("libfsmanager") { ] external_deps = [ "init:libbegetutil" ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/fs_manager/mount.cpp b/services/fs_manager/mount.cpp index 0a71611fd7b56546b29e177a9c16d9c511e611a0..a2424bf06fbdaf079e0941fee7546a805ba83e32 100644 --- a/services/fs_manager/mount.cpp +++ b/services/fs_manager/mount.cpp @@ -28,7 +28,9 @@ namespace updater { using updater::utils::SplitString; static std::string g_defaultUpdaterFstab = ""; -static Fstab *g_fstab; +static Fstab *g_fstab = nullptr; +static const std::string PARTITION_PATH = "/dev/block/by-name"; + static std::string GetFstabFile() { /* check vendor fstab files from specific directory */ @@ -187,8 +189,12 @@ int SetupPartitions() const std::string GetBlockDeviceByMountPoint(const std::string &mountPoint) { - std::string blockDevice = ""; - if (!mountPoint.empty()) { + if (mountPoint.empty()) { + LOG(ERROR) << "mountPoint empty error."; + return ""; + } + std::string blockDevice = PARTITION_PATH + mountPoint; + if (g_fstab != nullptr) { FstabItem *item = FindFstabItemForMountPoint(*g_fstab, mountPoint.c_str()); if (item != NULL) { blockDevice = item->deviceName; diff --git a/services/include/updater/updater_const.h b/services/include/updater/updater_const.h index 6b447687201e76eb889baabf32d68f4300f15302..f1f21ceead9ed79ef2a32b5d800474a123cb9a43 100644 --- a/services/include/updater/updater_const.h +++ b/services/include/updater/updater_const.h @@ -24,7 +24,10 @@ const std::string TMP_STAGE_LOG = "/tmp/updater_stage.log"; const std::string TMP_ERROR_CODE_PATH = "/tmp/error_code.log"; const std::string UPDATER_LOG_DIR = "/data/updater/log"; const std::string UPDATER_PATH = "/data/updater"; +const std::string DATA_PATH = "/data"; +const std::string UPDATER_RESULT_FILE = "updater_result"; const std::string MISC_FILE = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc"; +const std::string MISC_PATH = "/misc"; const std::string UPDATER_BINARY = "updater_binary"; const std::string SDCARD_PATH = "/sdcard"; const std::string UPDATER_HDC_LOG = "/data/updater/log/flashd_hdc.log"; diff --git a/services/log/BUILD.gn b/services/log/BUILD.gn index a063f69d4bf11ffdb8a55502a6a45022c303222d..f4d07de8e42a6a9140556f8001d37e18f13688c5 100644 --- a/services/log/BUILD.gn +++ b/services/log/BUILD.gn @@ -23,4 +23,6 @@ ohos_static_library("libupdaterlog") { ] deps = [ "//third_party/bounds_checking_function:libsec_static" ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/package/BUILD.gn b/services/package/BUILD.gn index d947f2f836ea36b3d07ddd58dd9452dc0e003087..142054f0ff68aa3ece976ce8785228ecafea00cb 100644 --- a/services/package/BUILD.gn +++ b/services/package/BUILD.gn @@ -58,4 +58,6 @@ ohos_static_library("libupdaterpackage") { deps = [ "//third_party/bounds_checking_function:libsec_static" ] configs = [ ":package_config" ] + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/package/pkg_algorithm/pkg_algo_digest.cpp b/services/package/pkg_algorithm/pkg_algo_digest.cpp index 0c1b89343d2d09d6498690d7168a0605df5080f1..4bb6eef67b32ac66d9743c6d81dae1b381d58cec 100644 --- a/services/package/pkg_algorithm/pkg_algo_digest.cpp +++ b/services/package/pkg_algorithm/pkg_algo_digest.cpp @@ -151,7 +151,6 @@ DigestAlgorithm::DigestAlgorithmPtr PkgAlgorithmFactory::GetDigestAlgorithm(uint return std::make_shared(); default: return std::make_shared(); - break; } return nullptr; } diff --git a/services/package/pkg_package/pkg_upgradefile.cpp b/services/package/pkg_package/pkg_upgradefile.cpp index 72e466ea0305225c3db9c29d6cf1d2fa1a561707..ecda48ae12f5b262a0db716df72bccbdf39c3581 100644 --- a/services/package/pkg_package/pkg_upgradefile.cpp +++ b/services/package/pkg_package/pkg_upgradefile.cpp @@ -129,10 +129,10 @@ int32_t UpgradePkgFile::SavePackage(size_t &signOffset) WriteLE32(reinterpret_cast(&header->updateFileVersion), pkgInfo_.updateFileVersion); int32_t ret = memcpy_s(header->softwareVersion, sizeof(header->softwareVersion), pkgInfo_.softwareVersion.data(), pkgInfo_.softwareVersion.size()); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret:%d", pkgStream_->GetFileName().c_str(), ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret: %d", pkgStream_->GetFileName().c_str(), ret); ret = memcpy_s(header->productUpdateId, sizeof(header->productUpdateId), pkgInfo_.productUpdateId.data(), pkgInfo_.productUpdateId.size()); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret:%d", pkgStream_->GetFileName().c_str(), ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret: %d", pkgStream_->GetFileName().c_str(), ret); offset += sizeof(UpgradePkgHeader); // 时间tlv WriteLE16(buffer.data() + offset, 0x02); // Type is 2 for time in TLV format @@ -140,16 +140,16 @@ int32_t UpgradePkgFile::SavePackage(size_t &signOffset) offset += sizeof(PkgTlv); UpgradePkgTime *time = reinterpret_cast(buffer.data() + offset); ret = memcpy_s(time->date, sizeof(time->date), pkgInfo_.date.data(), pkgInfo_.date.size()); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret:%d", pkgStream_->GetFileName().c_str(), ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret: %d", pkgStream_->GetFileName().c_str(), ret); ret = memcpy_s(time->time, sizeof(time->time), pkgInfo_.time.data(), pkgInfo_.time.size()); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret:%d", pkgStream_->GetFileName().c_str(), ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s %s ret: %d", pkgStream_->GetFileName().c_str(), ret); offset += sizeof(UpgradePkgTime); // 组件的tlv WriteLE16(buffer.data() + offset, 0x05); // Type is 5 for component in TLV format WriteLE16(buffer.data() + offset + sizeof(uint16_t), pkgInfo_.pkgInfo.entryCount * sizeof(UpgradeCompInfo)); offset += sizeof(PkgTlv); ret = pkgStream_->Write(buffer, UPGRADE_FILE_HEADER_LEN, 0); - PKG_CHECK(ret == PKG_SUCCESS, return ret, "Fail write upgrade file header for %s ret:%d", + PKG_CHECK(ret == PKG_SUCCESS, return ret, "Fail write upgrade file header for %s ret: %d", pkgStream_->GetFileName().c_str(), ret); // Clear buffer and save signature information @@ -374,7 +374,7 @@ int32_t UpgradeFileEntry::EncodeHeader(PkgStreamPtr inStream, size_t startOffset PKG_CHECK(ret == PKG_SUCCESS, return PKG_INVALID_PARAM, "outStream or inStream null for %s", fileName_.c_str()); ret = memcpy_s(comp.digest, sizeof(comp.digest), fileInfo_.digest, sizeof(fileInfo_.digest)); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s ret:%d", ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s ret: %d", ret); WriteLE32(reinterpret_cast(&comp.size), fileInfo_.fileInfo.unpackedSize); WriteLE16(reinterpret_cast(&comp.id), fileInfo_.id); WriteLE32(reinterpret_cast(&comp.originalSize), fileInfo_.originalSize); @@ -436,7 +436,7 @@ int32_t UpgradeFileEntry::DecodeHeader(const PkgBuffer &buffer, size_t headerOff fileInfo_.fileInfo.packMethod = PKG_COMPRESS_METHOD_NONE; fileInfo_.fileInfo.digestMethod = PKG_DIGEST_TYPE_NONE; int32_t ret = memcpy_s(fileInfo_.digest, sizeof(fileInfo_.digest), info->digest, sizeof(info->digest)); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s ret:%d", ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s ret: %d", ret); PkgFile::ConvertBufferToString(fileInfo_.fileInfo.identity, {info->address, sizeof(info->address)}); PkgFile::ConvertBufferToString(fileInfo_.version, {info->version, sizeof(info->version)}); fileName_ = fileInfo_.fileInfo.identity; @@ -468,7 +468,7 @@ int32_t UpgradeFileEntry::Unpack(PkgStreamPtr outStream) 0, fileInfo_.fileInfo.digestMethod }; int32_t ret = memcpy_s(context.digest, sizeof(context.digest), fileInfo_.digest, sizeof(fileInfo_.digest)); - PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s ret:%d", ret); + PKG_CHECK(ret == EOK, return ret, "Fail to memcpy_s ret: %d", ret); ret = algorithm->Unpack(inStream, outStream, context); PKG_CHECK(ret == PKG_SUCCESS, return ret, "Fail Decompress for %s", fileName_.c_str()); PKG_LOGI("Unpack %s data offset:%zu packedSize:%zu unpackedSize:%zu", fileName_.c_str(), dataOffset_, diff --git a/services/package/pkg_package/pkg_zipfile.cpp b/services/package/pkg_package/pkg_zipfile.cpp index 5ea2eb6b2ae033764c93e7e0fefcecbc32ee557e..df5626c44a7322c1c3c1cf1b33719c155d9e47f8 100644 --- a/services/package/pkg_package/pkg_zipfile.cpp +++ b/services/package/pkg_package/pkg_zipfile.cpp @@ -109,7 +109,7 @@ int32_t ZipPkgFile::LoadPackage(std::vector &fileNames, const PkgBu (endDir.startDiskOfCentralDir != 0) #ifndef UPDATER_UT || (endDir.offset >= fileLen) || (endDir.totalEntriesInThisDisk != endDir.totalEntries) || - (endDir.commentLen = 0) || ((endDir.offset + endDir.sizeOfCentralDir + endDirLen) > fileLen) + ((endDir.offset + endDir.sizeOfCentralDir + endDirLen) > fileLen) #endif ) { PKG_LOGE("end dir format error %s", pkgStream_->GetFileName().c_str()); diff --git a/services/script/BUILD.gn b/services/script/BUILD.gn index 641fe9eadf629d2467e8bdc76a8a467f58f5bb58..41ddffafa9871e602a4b60ff2f778697a115680c 100644 --- a/services/script/BUILD.gn +++ b/services/script/BUILD.gn @@ -66,4 +66,7 @@ ohos_static_library("libupdaterscript") { "//third_party/bounds_checking_function:libsec_static", "//utils/native/base:utils", ] + + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/ui/BUILD.gn b/services/ui/BUILD.gn index edab2abd0f5fc712c97419885cfb0b13ca053c44..760019c030b028c862319fc561391129160deca3 100644 --- a/services/ui/BUILD.gn +++ b/services/ui/BUILD.gn @@ -55,4 +55,7 @@ ohos_static_library("libui") { "//third_party/libdrm:libdrm", "//third_party/libpng:libpng", ] + + subsystem_name = "updater" + part_name = "updater" } diff --git a/services/ui/drm_driver.cpp b/services/ui/drm_driver.cpp index 201194285e7d56c9082279c560c4401804c1a9d7..44a5ae01564202329db835ce8b07bca6494b003b 100644 --- a/services/ui/drm_driver.cpp +++ b/services/ui/drm_driver.cpp @@ -72,32 +72,204 @@ int DrmDriver::ModesetCreateFb(struct BufferObject *bo) return 0; } +drmModeCrtc *DrmDriver::GetCrtc(const drmModeRes &res, const int fd, const drmModeConnector &conn) const +{ + // if connector has one encoder, use it + drmModeEncoder *encoder = nullptr; + if (conn.encoder_id != 0) { + encoder = drmModeGetEncoder(fd, conn.encoder_id); + } + if (encoder != nullptr && encoder->crtc_id != 0) { + uint32_t crtcId = encoder->crtc_id; + drmModeFreeEncoder(encoder); + return drmModeGetCrtc(fd, crtcId); + } + + if (encoder != nullptr) { + drmModeFreeEncoder(encoder); + } + + // try get a vaild encoder and crtc + for (int i = 0; i < conn.count_encoders; i++) { + encoder = drmModeGetEncoder(fd, conn.encoders[i]); + if (encoder == nullptr) { + continue; + } + + for (int j = 0; j < res.count_crtcs; j++) { + if ((encoder->possible_crtcs & (1u << static_cast(j))) != 0) { + drmModeFreeEncoder(encoder); + return drmModeGetCrtc(fd, res.crtcs[j]); + } + } + drmModeFreeEncoder(encoder); + } + return nullptr; +} + +drmModeConnector *DrmDriver::GetFirstConnector(const drmModeRes &res, const int fd) const +{ + // get connected connector + for (int i = 0; i < res.count_connectors; i++) { + drmModeConnector *conn = drmModeGetConnector(fd, res.connectors[i]); + if (conn == nullptr) { + continue; + } + if (conn->count_modes > 0 && + conn->connection == DRM_MODE_CONNECTED) { + return conn; + } + drmModeFreeConnector(conn); + } + return nullptr; +} + +drmModeConnector *DrmDriver::GetConnectorByType(const drmModeRes &res, const int fd, const uint32_t type) const +{ + // get connected connector + for (int i = 0; i < res.count_connectors; i++) { + drmModeConnector *conn = drmModeGetConnector(fd, res.connectors[i]); + if (conn == nullptr) { + continue; + } + if (conn->connector_type == type && + conn->count_modes > 0 && + conn->connection == DRM_MODE_CONNECTED) { + return conn; + } + drmModeFreeConnector(conn); + } + return nullptr; +} + + +drmModeConnector *DrmDriver::GetConnector(const drmModeRes &res, const int fd, uint32_t &modeId) const +{ + // get main connector : lvds edp and dsi + uint32_t mainConnector[] = { + DRM_MODE_CONNECTOR_LVDS, + DRM_MODE_CONNECTOR_eDP, + DRM_MODE_CONNECTOR_DSI, + }; + + drmModeConnector *conn = nullptr; + for (uint32_t i = 0; i < sizeof(mainConnector) / sizeof(mainConnector[0]); i++) { + conn = GetConnectorByType(res, fd, mainConnector[i]); + if (conn != nullptr) { + break; + } + } + + if (conn == nullptr) { + conn = GetFirstConnector(res, fd); + } + + if (conn == nullptr) { + LOG(ERROR) << "DrmDriver cannot get vaild connector"; + return nullptr; + } + + // get preferred mode index + modeId = 0; + for (int i = 0; i < conn->count_modes; i++) { + if ((conn->modes[i].type & DRM_MODE_TYPE_PREFERRED) != 0) { + modeId = i; + break; + } + } + + return conn; +} + +drmModeRes *DrmDriver::GetResources(int &fd) const +{ + // 1: open drm resource + drmModeRes *res = nullptr; + for (int i = 0; i < DRM_MAX_MINOR; i++) { + res = GetOneResources(i, fd); + if (res != nullptr) { + break; + } + } + return res; +} + +drmModeRes *DrmDriver::GetOneResources(const int devIndex, int &fd) const +{ + // 1: open drm device + fd = -1; + std::string devName = std::string("/dev/dri/card") + std::to_string(devIndex); + int tmpFd = open(devName.c_str(), O_RDWR | O_CLOEXEC); + if (tmpFd < 0) { + LOG(ERROR) << "open failed " << devName; + return nullptr; + } + // 2: check drm capacity + uint64_t cap = 0; + int ret = drmGetCap(tmpFd, DRM_CAP_DUMB_BUFFER, &cap); + if (ret != 0 || cap == 0) { + LOG(ERROR) << "drmGetCap failed"; + close(tmpFd); + return nullptr; + } + + // 3: get drm resources + drmModeRes *res = drmModeGetResources(tmpFd); + if (res == nullptr) { + LOG(ERROR) << "drmModeGetResources failed"; + close(tmpFd); + return nullptr; + } + + // 4: check it has connected connector and crtc + if (res->count_crtcs > 0 && res->count_connectors > 0 && res->count_encoders > 0) { + drmModeConnector *conn = GetFirstConnector(*res, tmpFd); + if (conn != nullptr) { + // don't close fd + LOG(INFO) << "drm dev:" << devName; + drmModeFreeConnector(conn); + fd = tmpFd; + return res; + } + } + close(tmpFd); + drmModeFreeResources(res); + return nullptr; +} + int DrmDriver::DrmInit(void) { - fd_ = open("/dev/dri/card0", O_RDWR | O_CLOEXEC); - if (fd_ < 0) { - LOG(ERROR) << "open failed"; + // 1: open drm resource + res_ = GetResources(fd_); + if (fd_ < 0 || res_ == nullptr) { + LOG(ERROR) << "DrmInit: GetResources failed"; return -1; } - res_ = drmModeGetResources(fd_); - if (res_ == nullptr) { - LOG(ERROR) << "drmModeGetResources"; + // 2 : get connected connector + uint32_t modeId; + conn_ = GetConnector(*res_, fd_, modeId); + if (conn_ == nullptr) { + LOG(ERROR) << "DrmInit: GetConnector failed"; return -1; } - uint32_t crtcId = res_->crtcs[0]; - uint32_t connId = res_->connectors[1]; - conn_ = drmModeGetConnector(fd_, connId); - if (conn_ == nullptr) { - LOG(ERROR) << "drmModeGetConnector"; + // 3: get vaild encoder and crtc + crtc_ = GetCrtc(*res_, fd_, *conn_); + if (crtc_ == nullptr) { + LOG(ERROR) << "DrmInit: GetCrtc failed"; return -1; } - buff_.width = conn_->modes[0].hdisplay; - buff_.height = conn_->modes[0].vdisplay; + // 4: create userspace buffer + buff_.width = conn_->modes[modeId].hdisplay; + buff_.height = conn_->modes[modeId].vdisplay; ModesetCreateFb(&buff_); - drmModeSetCrtc(fd_, crtcId, buff_.fbId, 0, 0, &connId, 1, &conn_->modes[0]); + + // 5: bind ctrc and connector + drmModeSetCrtc(fd_, crtc_->crtc_id, buff_.fbId, 0, 0, &conn_->connector_id, 1, &conn_->modes[modeId]); + LOG(INFO) << "DrmInit: buff_.width:" << buff_.width << " buff_.height:" << buff_.height; + LOG(INFO) << "DrmInit: crtc_id:" << crtc_->crtc_id << " connector_id:" << conn_->connector_id; LOG(INFO) << " drm init success."; return 0; } @@ -111,14 +283,29 @@ void DrmDriver::LoadDrmDriver() void DrmDriver::ModesetDestroyFb(struct BufferObject *bo) { - struct drm_mode_destroy_dumb destroy = {}; - drmModeRmFB(fd_, bo->fbId); - munmap(bo->vaddr, bo->size); - destroy.handle = bo->handle; - drmIoctl(fd_, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy); - drmModeFreeConnector(conn_); - drmModeFreeResources(res_); - close(fd_); + if (fd_ > 0 && bo->fbId != 0) { + drmModeRmFB(fd_, bo->fbId); + } + if (bo->vaddr != nullptr) { + munmap(bo->vaddr, bo->size); + } + if (fd_ > 0) { + struct drm_mode_destroy_dumb destroy = {}; + destroy.handle = bo->handle; + drmIoctl(fd_, DRM_IOCTL_GEM_CLOSE, &destroy); + } + if (crtc_ != nullptr) { + drmModeFreeCrtc(crtc_); + } + if (conn_ != nullptr) { + drmModeFreeConnector(conn_); + } + if (res_ != nullptr) { + drmModeFreeResources(res_); + } + if (fd_ > 0) { + close(fd_); + } } DrmDriver::~DrmDriver() diff --git a/services/ui/drm_driver.h b/services/ui/drm_driver.h index 1e0749293dd69d8e6e3db5bfbcba766313abc6fd..2d10391f3dcb514802ca8eaa623c2b19bf881e6e 100644 --- a/services/ui/drm_driver.h +++ b/services/ui/drm_driver.h @@ -40,7 +40,7 @@ struct BufferObject { class DrmDriver { protected: - DrmDriver() : fd_(-1), conn_(nullptr), res_(nullptr) {} + DrmDriver() : fd_(-1), conn_(nullptr), res_(nullptr), crtc_(nullptr) {} virtual ~DrmDriver(); void FlipBuffer(const void* buf); void LoadDrmDriver(); @@ -48,9 +48,16 @@ private: int ModesetCreateFb(struct BufferObject *bo); void ModesetDestroyFb(struct BufferObject *bo); int DrmInit(); + drmModeCrtc *GetCrtc(const drmModeRes &res, const int fd, const drmModeConnector &conn) const; + drmModeConnector *GetFirstConnector(const drmModeRes &res, const int fd) const; + drmModeConnector *GetConnectorByType(const drmModeRes &res, const int fd, const uint32_t type) const; + drmModeConnector *GetConnector(const drmModeRes &res, const int fd, uint32_t &modeId) const; + drmModeRes *GetResources(int &fd) const; + drmModeRes *GetOneResources(const int devIndex, int &fd) const; int fd_; drmModeConnector *conn_; drmModeRes *res_; + drmModeCrtc *crtc_; struct BufferObject buff_ {}; }; } // namespace updater diff --git a/services/ui/input_event.cpp b/services/ui/input_event.cpp index 5867bb6eb06252d5998a7361df04b42021ded55a..2c97f10668783805ae48039b37f6eefd275c22ee 100644 --- a/services/ui/input_event.cpp +++ b/services/ui/input_event.cpp @@ -22,7 +22,7 @@ namespace updater { constexpr int TOUCH_LOW_TH = 50; constexpr int TOUCH_HIGH_TH = 90; constexpr int INIT_DEFAULT_VALUE = 255; -constexpr int LABEL_HEIGHT = 64; +constexpr int LABEL_HEIGHT = 80; constexpr int LABEL_OFFSET_2 = 2; constexpr int LABEL_OFFSET_3 = 3; constexpr int DIALOG_START_Y = 550; diff --git a/services/ui/text_label.cpp b/services/ui/text_label.cpp index d94a90a649f072867ff6b4b366269f8087108bc4..6037f3e17376a1f9984d6d7936a37a016055bb30 100644 --- a/services/ui/text_label.cpp +++ b/services/ui/text_label.cpp @@ -37,7 +37,6 @@ TextLabel::TextLabel(int mStartX, int mStartY, int w, int h, Frame *mparent) outlineColor_.b = 0x00; outlineColor_.a = 0x00; boldTopLine_ = false; - boldTopLine_ = false; const char midAlpha = 0xAA; actionBgColor_.r = 0x00; diff --git a/services/ui/updater_ui_const.h b/services/ui/updater_ui_const.h index 99381a701fa5358c3648bc06b065a40f42d008ad..5dd2d03b0b1752862df7741cdcf856a02cf141fc 100644 --- a/services/ui/updater_ui_const.h +++ b/services/ui/updater_ui_const.h @@ -53,8 +53,8 @@ constexpr int DIALOG_OK_ID = 200; constexpr int DIALOG_CANCEL_ID = 201; constexpr int DIALOG_CANCEL_X = 340; constexpr int DIALOG_OK_WIDTH = 150; -constexpr int SCREEN_WIDTH = 480; -constexpr int SCREEN_HEIGHT = 960; +constexpr int SCREEN_WIDTH = 720; +constexpr int SCREEN_HEIGHT = 1280; constexpr int MEDIAN_NUMBER = 2; } // namespace updater #endif /* UPDATE_UI_HOS_UPDATER_H */ \ No newline at end of file diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index cd042792d841272a5d5945ddbbc1e1496d55b8a5..32ff33b9fb8f82320fe0b823c565677d1ba8bbfd 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -345,11 +345,11 @@ int32_t UScriptInstructionBlockCheck::Execute(uscript::UScriptEnv &env, uscript: LOG(INFO) << "BlockSet::ReadDataFromBlock lseek64"; ret = lseek64(fd, static_cast(it->first * H_BLOCK_SIZE), SEEK_SET); UPDATER_ERROR_CHECK(ret != -1, "Failed to seek", - return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); + close(fd); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); size_t size = (it->second - it->first) * H_BLOCK_SIZE; LOG(INFO) << "BlockSet::ReadDataFromBlock Read " << size << " from block"; UPDATER_ERROR_CHECK(utils::ReadFully(fd, block_buff.data() + pos, size), "Failed to read", - return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); + close(fd); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); pos += size; } @@ -365,6 +365,7 @@ int32_t UScriptInstructionBlockCheck::Execute(uscript::UScriptEnv &env, uscript: } LOG(INFO) << "UScriptInstructionBlockCheck::Execute Success"; context.PushParam(USCRIPT_SUCCESS); + close(fd); return USCRIPT_SUCCESS; } @@ -405,11 +406,11 @@ int32_t UScriptInstructionShaCheck::Execute(uscript::UScriptEnv &env, uscript::U for (; it != blk.End(); ++it) { ret = lseek64(fd, static_cast(it->first * H_BLOCK_SIZE), SEEK_SET); UPDATER_ERROR_CHECK(ret != -1, "Failed to seek", - return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); + close(fd); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); for (size_t i = it->first; i < it->second; ++i) { UPDATER_ERROR_CHECK(utils::ReadFully(fd, block_buff.data(), H_BLOCK_SIZE), "Failed to read", - return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); + close(fd); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); SHA256_Update(&ctx, block_buff.data(), H_BLOCK_SIZE); } } @@ -417,9 +418,10 @@ int32_t UScriptInstructionShaCheck::Execute(uscript::UScriptEnv &env, uscript::U SHA256_Final(digest, &ctx); std::string resultSha = utils::ConvertSha256Hex(digest, SHA256_DIGEST_LENGTH); UPDATER_ERROR_CHECK(resultSha == contrastSha, "Different sha256, cannot continue", - return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); + close(fd); return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); LOG(INFO) << "UScriptInstructionShaCheck::Execute Success"; context.PushParam(USCRIPT_SUCCESS); + close(fd); return USCRIPT_SUCCESS; } } diff --git a/services/updater_binary/update_partitions.cpp b/services/updater_binary/update_partitions.cpp index edd7fcabec86f244ee7c4d3396c284c808f3ac67..89c13a3165560a7d10ee657bb8d88c5b8f3a3e4b 100644 --- a/services/updater_binary/update_partitions.cpp +++ b/services/updater_binary/update_partitions.cpp @@ -117,7 +117,8 @@ int32_t UpdatePartitions::Execute(uscript::UScriptEnv &env, uscript::UScriptCont std::string tmpPath1 = tmpPath + filePath; ret = env.GetPkgManager()->CreatePkgStream(outStream, tmpPath1, info->unpackedSize, PkgStream::PkgStreamType_Write); - UPDATER_ERROR_CHECK(outStream != nullptr, "Error to create output stream", return USCRIPT_ERROR_EXECUTE); + UPDATER_ERROR_CHECK(ret == USCRIPT_SUCCESS && outStream != nullptr, "Error to create output stream", + return USCRIPT_ERROR_EXECUTE); ret = env.GetPkgManager()->ExtractFile(filePath, outStream); UPDATER_ERROR_CHECK(ret == USCRIPT_SUCCESS, "Error to extract file", env.GetPkgManager()->ClosePkgStream(outStream); return USCRIPT_ERROR_EXECUTE); diff --git a/services/updater_binary/update_processor.cpp b/services/updater_binary/update_processor.cpp index 34675148a930621353f3cd58b7cb53871f7c23e0..8bcc08c0af0badf4efa0a63807de54f4f9041ebd 100644 --- a/services/updater_binary/update_processor.cpp +++ b/services/updater_binary/update_processor.cpp @@ -146,7 +146,7 @@ int32_t UScriptInstructionRawImageWrite::Execute(uscript::UScriptEnv &env, uscri totalSize_ = info->unpackedSize; ret = env.GetPkgManager()->CreatePkgStream(outStream, imageFilename, RawImageWriteProcessor, writer.get()); - UPDATER_ERROR_CHECK(outStream != nullptr, "Error to create output stream", + UPDATER_ERROR_CHECK(ret == USCRIPT_SUCCESS && outStream != nullptr, "Error to create output stream", DataWriter::ReleaseDataWriter(writer); return USCRIPT_ERROR_EXECUTE); ret = env.GetPkgManager()->ExtractFile(imageFilename, outStream); @@ -187,7 +187,8 @@ int32_t UScriptInstructionSparseImageWrite::Execute(uscript::UScriptEnv &env, us ret = env.GetPkgManager()->CreatePkgStream(outStream, partitionName, info->unpackedSize, PkgStream::PkgStreamType_MemoryMap); - UPDATER_ERROR_CHECK(outStream != nullptr, "Error to create output stream", return USCRIPT_ERROR_EXECUTE); + UPDATER_ERROR_CHECK(ret == USCRIPT_SUCCESS && outStream != nullptr, "Error to create output stream", + return USCRIPT_ERROR_EXECUTE); ret = env.GetPkgManager()->ExtractFile(partitionName, outStream); UPDATER_ERROR_CHECK(ret == USCRIPT_SUCCESS, "Error to extract file", diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 9b393a6d3f2354c575c7d419565461fb553ad043..a71dab05bff8f841051b3f7b0d1eea787e847b01 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -77,7 +77,7 @@ static void SetRetryCountToMisc(int retryCount, const std::vector a "SetRetryCountToMisc snprintf_s failed", return); UPDATER_ERROR_CHECK(!strncat_s(msg.update, sizeof(msg.update), buffer, strlen(buffer) + 1), "SetRetryCountToMisc strncat_s failed", return); - UPDATER_ERROR_CHECK_NOT_RETURN(WriteUpdaterMessage(MISC_FILE, msg) == true, "Write command to misc failed."); + UPDATER_ERROR_CHECK_NOT_RETURN(WriteUpdaterMiscMsg(msg) == true, "Write command to misc failed."); } static int DoFactoryReset(FactoryResetMode mode, const std::string &path) @@ -194,6 +194,7 @@ static UpdaterStatus StartUpdaterEntry(PkgManager::PkgManagerPtr manager, if (upParams.updatePackage != "") { ShowUpdateFrame(true); status = InstallUpdaterPackage(upParams, args, manager); + WriteOtaResult(status); UPDATER_CHECK_ONLY_RETURN(status == UPDATE_SUCCESS, return status); } else if (upParams.factoryWipeData) { LOG(INFO) << "Factory level FactoryReset begin"; diff --git a/services/updater_utils.cpp b/services/updater_utils.cpp index dc928c749c9385ec5f244a57ee364f11bad13224..d88330af9e649186a5bc7f3d0e29bff79773b21e 100755 --- a/services/updater_utils.cpp +++ b/services/updater_utils.cpp @@ -129,7 +129,8 @@ static bool DeleteUpdaterPath(const std::string &path) struct dirent *dp = nullptr; while ((dp = readdir(pDir.get())) != nullptr) { std::string currentName(dp->d_name); - if (currentName[0] != '.' && (currentName.compare("log") != 0)) { + if (currentName[0] != '.' && (currentName.compare("log") != 0) && + (currentName.compare(UPDATER_RESULT_FILE) != 0)) { std::string tmpName(path); tmpName.append("/" + currentName); if (IsDir(tmpName)) { @@ -146,9 +147,12 @@ static bool DeleteUpdaterPath(const std::string &path) static bool ClearMisc() { struct UpdateMessage cleanBoot {}; - UPDATER_ERROR_CHECK(WriteUpdaterMessage(MISC_FILE, cleanBoot) == true, + UPDATER_ERROR_CHECK(WriteUpdaterMiscMsg(cleanBoot) == true, "ClearMisc clear boot message to misc failed", return false); - auto fp = std::unique_ptr(fopen(MISC_FILE.c_str(), "rb+"), fclose); + auto miscBlockDev = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!miscBlockDev.empty(), "cannot get block device of partition", miscBlockDev = MISC_FILE); + LOG(INFO) << "ClearMisc::misc path : " << miscBlockDev; + auto fp = std::unique_ptr(fopen(miscBlockDev.c_str(), "rb+"), fclose); UPDATER_FILE_CHECK(fp != nullptr, "WriteVersionCode fopen failed", return false); (void)fseek(fp.get(), PARTITION_RECORD_OFFSET, SEEK_SET); off_t clearOffset = 0; @@ -260,7 +264,7 @@ int IsSpaceCapacitySufficient(const std::string &packagePath) UPDATER_ERROR_CHECK(ret >= 0, "Statvfs read /sdcard error!", return UPDATE_ERROR); } else { needSpace += MAX_LOG_SPACE; - ret = statvfs64(UPDATER_PATH.c_str(), &updaterVfs); + ret = statvfs64(DATA_PATH.c_str(), &updaterVfs); UPDATER_ERROR_CHECK(ret >= 0, "Statvfs read /data error!", return UPDATE_ERROR); } auto freeSpaceSize = static_cast(updaterVfs.f_bfree); @@ -275,7 +279,7 @@ std::vector ParseParams(int argc, char **argv) { struct UpdateMessage boot {}; // read from misc - UPDATER_ERROR_CHECK_NOT_RETURN(ReadUpdaterMessage(MISC_FILE, boot) == true, + UPDATER_ERROR_CHECK_NOT_RETURN(ReadUpdaterMiscMsg(boot) == true, "ReadUpdaterMessage MISC_FILE failed!"); // if boot.update is empty, read from command.The Misc partition may have dirty data, // so strlen(boot.update) is not used, which can cause system exceptions. @@ -300,7 +304,7 @@ int GetBootMode(int &mode) #endif struct UpdateMessage boot {}; // read from misc - bool ret = ReadUpdaterMessage(MISC_FILE, boot); + bool ret = ReadUpdaterMiscMsg(boot); if (!ret) { return -1; } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index f1cc048ffbb93f1ad110e2fe2dc9a2925e9897e1..7a945c0c9fa2b216b0588e8a97cec7590d60addd 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -25,6 +25,9 @@ ohos_static_library("libutils") { deps = [ "//third_party/bounds_checking_function:libsec_static" ] external_deps = [ "init:libbegetutil" ] + + subsystem_name = "updater" + part_name = "updater" } ohos_executable("updater_reboot") { diff --git a/utils/include/utils.h b/utils/include/utils.h index 62366084e62e2ca8e8aab82947224f6cd2a734a6..f1b6f92853ae3b3593f6a25c7a6cda816f305eb7 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -55,6 +55,7 @@ bool ReadFully(int fd, void* data, size_t size); bool ReadFileToString(int fd, std::string &content); bool WriteStringToFile(int fd, const std::string& content); std::string GetLocalBoardId(); +void WriteOtaResult(const int status); } // utils } // updater #endif // UPDATER_UTILS_H diff --git a/utils/utils.cpp b/utils/utils.cpp index 3da6a9a1b0d257080c8287bf23a6639085b1ece1..569998fa98525b8624dca14e7b72c3a3ccd1e8f6 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -39,6 +39,9 @@ using namespace hpackage; namespace utils { constexpr uint32_t MAX_PATH_LEN = 256; constexpr uint8_t SHIFT_RIGHT_FOUR_BITS = 4; +constexpr int USER_ROOT_AUTHORITY = 0; +constexpr int GROUP_SYS_AUTHORITY = 1000; +constexpr int MAX_RESULT_SIZE = 20; int32_t DeleteFile(const std::string& filename) { UPDATER_ERROR_CHECK (!filename.empty(), "Invalid filename", return -1); @@ -287,5 +290,37 @@ std::string GetLocalBoardId() { return "HI3516"; } + +void WriteOtaResult(const int status) +{ + if (access(UPDATER_PATH.c_str(), 0) != 0) { + UPDATER_ERROR_CHECK(!MkdirRecursive(UPDATER_PATH, 0644), + "MkdirRecursive error!", return); + } + + const std::string resultPath = UPDATER_PATH + "/" + UPDATER_RESULT_FILE; + FILE *fp = fopen(resultPath.c_str(), "w+"); + if (fp != nullptr) { + LOG(ERROR) << "open result file fialed"; + return; + } + char buf[MAX_RESULT_SIZE] = "pass\n"; + if (status != 0) { + if (sprintf_s(buf, MAX_RESULT_SIZE - 1, "fail:%d\n", status) < 0) { + LOG(WARNING) << "sprintf status failed"; + } + } + + if (fwrite(buf, 1, strlen(buf) + 1, fp) <= 0) { + LOG(WARNING) << "write result file failed, err:" << errno; + } + + if (fclose(fp) != 0) { + LOG(WARNING) << "close result file failed"; + } + + (void)chown(resultPath.c_str(), USER_ROOT_AUTHORITY, GROUP_SYS_AUTHORITY); + (void)chmod(resultPath.c_str(), 0640); // 0640: -rw-r----- +} } // utils } // namespace updater