Merge "Implement an update simulator to verify BB OTA packages on host" am: 65d7d5b8cf am: 29d9d7bbbe
am: 55e82e2fc5
Change-Id: I67b8152c41b2e92a67f935488f631bff7f5cf6ee
This commit is contained in:
+4
-4
@@ -24,12 +24,16 @@ cc_library_static {
|
|||||||
|
|
||||||
// Minimal set of files to support host build.
|
// Minimal set of files to support host build.
|
||||||
srcs: [
|
srcs: [
|
||||||
|
"dirutil.cpp",
|
||||||
"paths.cpp",
|
"paths.cpp",
|
||||||
"rangeset.cpp",
|
"rangeset.cpp",
|
||||||
|
"sysutil.cpp",
|
||||||
],
|
],
|
||||||
|
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"libbase",
|
"libbase",
|
||||||
|
"libcutils",
|
||||||
|
"libselinux",
|
||||||
],
|
],
|
||||||
|
|
||||||
export_include_dirs: [
|
export_include_dirs: [
|
||||||
@@ -39,12 +43,10 @@ cc_library_static {
|
|||||||
target: {
|
target: {
|
||||||
android: {
|
android: {
|
||||||
srcs: [
|
srcs: [
|
||||||
"dirutil.cpp",
|
|
||||||
"logging.cpp",
|
"logging.cpp",
|
||||||
"mounts.cpp",
|
"mounts.cpp",
|
||||||
"parse_install_logs.cpp",
|
"parse_install_logs.cpp",
|
||||||
"roots.cpp",
|
"roots.cpp",
|
||||||
"sysutil.cpp",
|
|
||||||
"thermalutil.cpp",
|
"thermalutil.cpp",
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -57,10 +59,8 @@ cc_library_static {
|
|||||||
],
|
],
|
||||||
|
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"libcutils",
|
|
||||||
"libext4_utils",
|
"libext4_utils",
|
||||||
"libfs_mgr",
|
"libfs_mgr",
|
||||||
"libselinux",
|
|
||||||
],
|
],
|
||||||
|
|
||||||
export_static_lib_headers: [
|
export_static_lib_headers: [
|
||||||
|
|||||||
+3
-1
@@ -108,6 +108,7 @@ cc_test {
|
|||||||
defaults: [
|
defaults: [
|
||||||
"recovery_test_defaults",
|
"recovery_test_defaults",
|
||||||
"libupdater_defaults",
|
"libupdater_defaults",
|
||||||
|
"libupdater_device_defaults",
|
||||||
],
|
],
|
||||||
|
|
||||||
test_suites: ["device-tests"],
|
test_suites: ["device-tests"],
|
||||||
@@ -121,7 +122,8 @@ cc_test {
|
|||||||
"libfusesideload",
|
"libfusesideload",
|
||||||
"libminui",
|
"libminui",
|
||||||
"libotautil",
|
"libotautil",
|
||||||
"libupdater",
|
"libupdater_device",
|
||||||
|
"libupdater_core",
|
||||||
"libupdate_verifier",
|
"libupdate_verifier",
|
||||||
|
|
||||||
"libgtest_prod",
|
"libgtest_prod",
|
||||||
|
|||||||
+57
-4
@@ -30,7 +30,6 @@ cc_defaults {
|
|||||||
"libfec",
|
"libfec",
|
||||||
"libfec_rs",
|
"libfec_rs",
|
||||||
"libverity_tree",
|
"libverity_tree",
|
||||||
"libfs_mgr",
|
|
||||||
"libgtest_prod",
|
"libgtest_prod",
|
||||||
"liblog",
|
"liblog",
|
||||||
"liblp",
|
"liblp",
|
||||||
@@ -46,6 +45,14 @@ cc_defaults {
|
|||||||
"libcrypto_utils",
|
"libcrypto_utils",
|
||||||
"libcutils",
|
"libcutils",
|
||||||
"libutils",
|
"libutils",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_defaults {
|
||||||
|
name: "libupdater_device_defaults",
|
||||||
|
|
||||||
|
static_libs: [
|
||||||
|
"libfs_mgr",
|
||||||
"libtune2fs",
|
"libtune2fs",
|
||||||
|
|
||||||
"libext2_com_err",
|
"libext2_com_err",
|
||||||
@@ -54,11 +61,13 @@ cc_defaults {
|
|||||||
"libext2_uuid",
|
"libext2_uuid",
|
||||||
"libext2_e2p",
|
"libext2_e2p",
|
||||||
"libext2fs",
|
"libext2fs",
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_library_static {
|
cc_library_static {
|
||||||
name: "libupdater",
|
name: "libupdater_core",
|
||||||
|
|
||||||
|
host_supported: true,
|
||||||
|
|
||||||
defaults: [
|
defaults: [
|
||||||
"recovery_defaults",
|
"recovery_defaults",
|
||||||
@@ -68,12 +77,33 @@ cc_library_static {
|
|||||||
srcs: [
|
srcs: [
|
||||||
"blockimg.cpp",
|
"blockimg.cpp",
|
||||||
"commands.cpp",
|
"commands.cpp",
|
||||||
"dynamic_partitions.cpp",
|
|
||||||
"install.cpp",
|
"install.cpp",
|
||||||
"updater.cpp",
|
"updater.cpp",
|
||||||
|
],
|
||||||
|
|
||||||
|
export_include_dirs: [
|
||||||
|
"include",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_static {
|
||||||
|
name: "libupdater_device",
|
||||||
|
|
||||||
|
defaults: [
|
||||||
|
"recovery_defaults",
|
||||||
|
"libupdater_defaults",
|
||||||
|
"libupdater_device_defaults",
|
||||||
|
],
|
||||||
|
|
||||||
|
srcs: [
|
||||||
|
"dynamic_partitions.cpp",
|
||||||
"updater_runtime.cpp",
|
"updater_runtime.cpp",
|
||||||
],
|
],
|
||||||
|
|
||||||
|
static_libs: [
|
||||||
|
"libupdater_core",
|
||||||
|
],
|
||||||
|
|
||||||
include_dirs: [
|
include_dirs: [
|
||||||
"external/e2fsprogs/misc",
|
"external/e2fsprogs/misc",
|
||||||
],
|
],
|
||||||
@@ -82,3 +112,26 @@ cc_library_static {
|
|||||||
"include",
|
"include",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_library_host_static {
|
||||||
|
name: "libupdater_host",
|
||||||
|
|
||||||
|
defaults: [
|
||||||
|
"recovery_defaults",
|
||||||
|
"libupdater_defaults",
|
||||||
|
],
|
||||||
|
|
||||||
|
srcs: [
|
||||||
|
"simulator_runtime.cpp",
|
||||||
|
"target_files.cpp",
|
||||||
|
],
|
||||||
|
|
||||||
|
static_libs: [
|
||||||
|
"libupdater_core",
|
||||||
|
"libfstab",
|
||||||
|
],
|
||||||
|
|
||||||
|
export_include_dirs: [
|
||||||
|
"include",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|||||||
+65
-20
@@ -33,7 +33,6 @@ updater_common_static_libraries := \
|
|||||||
libfec \
|
libfec \
|
||||||
libfec_rs \
|
libfec_rs \
|
||||||
libverity_tree \
|
libverity_tree \
|
||||||
libfs_mgr \
|
|
||||||
libgtest_prod \
|
libgtest_prod \
|
||||||
liblog \
|
liblog \
|
||||||
liblp \
|
liblp \
|
||||||
@@ -48,9 +47,24 @@ updater_common_static_libraries := \
|
|||||||
libcrypto \
|
libcrypto \
|
||||||
libcrypto_utils \
|
libcrypto_utils \
|
||||||
libcutils \
|
libcutils \
|
||||||
libutils \
|
libutils
|
||||||
libtune2fs \
|
|
||||||
$(tune2fs_static_libraries)
|
|
||||||
|
# Each library in TARGET_RECOVERY_UPDATER_LIBS should have a function
|
||||||
|
# named "Register_<libname>()". Here we emit a little C function that
|
||||||
|
# gets #included by updater.cpp. It calls all those registration
|
||||||
|
# functions.
|
||||||
|
# $(1): the path to the register.inc file
|
||||||
|
# $(2): a list of TARGET_RECOVERY_UPDATER_LIBS
|
||||||
|
define generate-register-inc
|
||||||
|
$(hide) mkdir -p $(dir $(1))
|
||||||
|
$(hide) echo "" > $(1)
|
||||||
|
$(hide) $(foreach lib,$(2),echo "extern void Register_$(lib)(void);" >> $(1);)
|
||||||
|
$(hide) echo "void RegisterDeviceExtensions() {" >> $(1)
|
||||||
|
$(hide) $(foreach lib,$(2),echo " Register_$(lib)();" >> $(1);)
|
||||||
|
$(hide) echo "}" >> $(1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
|
||||||
# updater (static executable)
|
# updater (static executable)
|
||||||
# ===============================
|
# ===============================
|
||||||
@@ -69,33 +83,26 @@ LOCAL_CFLAGS := \
|
|||||||
-Werror
|
-Werror
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES := \
|
LOCAL_STATIC_LIBRARIES := \
|
||||||
libupdater \
|
libupdater_device \
|
||||||
|
libupdater_core \
|
||||||
$(TARGET_RECOVERY_UPDATER_LIBS) \
|
$(TARGET_RECOVERY_UPDATER_LIBS) \
|
||||||
$(TARGET_RECOVERY_UPDATER_EXTRA_LIBS) \
|
$(TARGET_RECOVERY_UPDATER_EXTRA_LIBS) \
|
||||||
$(updater_common_static_libraries)
|
$(updater_common_static_libraries) \
|
||||||
|
libfs_mgr \
|
||||||
|
libtune2fs \
|
||||||
|
$(tune2fs_static_libraries)
|
||||||
|
|
||||||
# Each library in TARGET_RECOVERY_UPDATER_LIBS should have a function
|
LOCAL_MODULE_CLASS := EXECUTABLES
|
||||||
# named "Register_<libname>()". Here we emit a little C function that
|
inc := $(call local-generated-sources-dir)/register.inc
|
||||||
# gets #included by updater.c. It calls all those registration
|
|
||||||
# functions.
|
|
||||||
|
|
||||||
# Devices can also add libraries to TARGET_RECOVERY_UPDATER_EXTRA_LIBS.
|
# Devices can also add libraries to TARGET_RECOVERY_UPDATER_EXTRA_LIBS.
|
||||||
# These libs are also linked in with updater, but we don't try to call
|
# These libs are also linked in with updater, but we don't try to call
|
||||||
# any sort of registration function for these. Use this variable for
|
# any sort of registration function for these. Use this variable for
|
||||||
# any subsidiary static libraries required for your registered
|
# any subsidiary static libraries required for your registered
|
||||||
# extension libs.
|
# extension libs.
|
||||||
|
|
||||||
LOCAL_MODULE_CLASS := EXECUTABLES
|
|
||||||
inc := $(call local-generated-sources-dir)/register.inc
|
|
||||||
|
|
||||||
$(inc) : libs := $(TARGET_RECOVERY_UPDATER_LIBS)
|
$(inc) : libs := $(TARGET_RECOVERY_UPDATER_LIBS)
|
||||||
$(inc) :
|
$(inc) :
|
||||||
$(hide) mkdir -p $(dir $@)
|
$(call generate-register-inc,$@,$(libs))
|
||||||
$(hide) echo "" > $@
|
|
||||||
$(hide) $(foreach lib,$(libs),echo "extern void Register_$(lib)(void);" >> $@;)
|
|
||||||
$(hide) echo "void RegisterDeviceExtensions() {" >> $@
|
|
||||||
$(hide) $(foreach lib,$(libs),echo " Register_$(lib)();" >> $@;)
|
|
||||||
$(hide) echo "}" >> $@
|
|
||||||
|
|
||||||
LOCAL_GENERATED_SOURCES := $(inc)
|
LOCAL_GENERATED_SOURCES := $(inc)
|
||||||
|
|
||||||
@@ -104,3 +111,41 @@ inc :=
|
|||||||
LOCAL_FORCE_STATIC_EXECUTABLE := true
|
LOCAL_FORCE_STATIC_EXECUTABLE := true
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
|
|
||||||
|
# update_host_simulator (static executable)
|
||||||
|
# ===============================
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE := update_host_simulator
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
update_simulator_main.cpp
|
||||||
|
|
||||||
|
LOCAL_C_INCLUDES := \
|
||||||
|
$(LOCAL_PATH)/include
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := \
|
||||||
|
-Wall \
|
||||||
|
-Werror
|
||||||
|
|
||||||
|
LOCAL_STATIC_LIBRARIES := \
|
||||||
|
libupdater_host \
|
||||||
|
libupdater_core \
|
||||||
|
$(TARGET_RECOVERY_UPDATER_HOST_LIBS) \
|
||||||
|
$(TARGET_RECOVERY_UPDATER_HOST_EXTRA_LIBS) \
|
||||||
|
$(updater_common_static_libraries) \
|
||||||
|
libfstab
|
||||||
|
|
||||||
|
LOCAL_MODULE_CLASS := EXECUTABLES
|
||||||
|
inc := $(call local-generated-sources-dir)/register.inc
|
||||||
|
|
||||||
|
$(inc) : libs := $(TARGET_RECOVERY_UPDATER_HOST_LIBS)
|
||||||
|
$(inc) :
|
||||||
|
$(call generate-register-inc,$@,$(libs))
|
||||||
|
|
||||||
|
LOCAL_GENERATED_SOURCES := $(inc)
|
||||||
|
|
||||||
|
inc :=
|
||||||
|
|
||||||
|
include $(BUILD_HOST_EXECUTABLE)
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "edify/updater_runtime_interface.h"
|
||||||
|
#include "updater/target_files.h"
|
||||||
|
|
||||||
|
class SimulatorRuntime : public UpdaterRuntimeInterface {
|
||||||
|
public:
|
||||||
|
explicit SimulatorRuntime(TargetFiles* source) : source_(source) {}
|
||||||
|
|
||||||
|
bool IsSimulator() const override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetProperty(const std::string_view key,
|
||||||
|
const std::string_view default_value) const override;
|
||||||
|
|
||||||
|
int Mount(const std::string_view location, const std::string_view mount_point,
|
||||||
|
const std::string_view fs_type, const std::string_view mount_options) override;
|
||||||
|
bool IsMounted(const std::string_view mount_point) const override;
|
||||||
|
std::pair<bool, int> Unmount(const std::string_view mount_point) override;
|
||||||
|
|
||||||
|
bool ReadFileToString(const std::string_view filename, std::string* content) const override;
|
||||||
|
bool WriteStringToFile(const std::string_view content,
|
||||||
|
const std::string_view filename) const override;
|
||||||
|
|
||||||
|
int WipeBlockDevice(const std::string_view filename, size_t len) const override;
|
||||||
|
int RunProgram(const std::vector<std::string>& args, bool is_vfork) const override;
|
||||||
|
int Tune2Fs(const std::vector<std::string>& args) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string FindBlockDeviceName(const std::string_view name) const override;
|
||||||
|
|
||||||
|
TargetFiles* source_;
|
||||||
|
std::map<std::string, std::string, std::less<>> mounted_partitions_;
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// This class parses a given target file for the build properties and image files. Then it creates
|
||||||
|
// and maintains the temporary files to simulate the block devices on host.
|
||||||
|
class TargetFiles {
|
||||||
|
public:
|
||||||
|
TargetFiles(std::string path, std::string work_dir)
|
||||||
|
: path_(std::move(path)), work_dir_(std::move(work_dir)) {}
|
||||||
|
|
||||||
|
std::string GetProperty(const std::string_view key, const std::string_view default_value) const;
|
||||||
|
|
||||||
|
std::string FindBlockDeviceName(const std::string_view name) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string path_; // Path to the target file.
|
||||||
|
|
||||||
|
std::string work_dir_; // A temporary directory to store the extracted image files
|
||||||
|
};
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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 "updater/simulator_runtime.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <android-base/file.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
|
#include <android-base/properties.h>
|
||||||
|
#include <android-base/strings.h>
|
||||||
|
#include <android-base/unique_fd.h>
|
||||||
|
#include <ext4_utils/wipe.h>
|
||||||
|
#include <selinux/label.h>
|
||||||
|
|
||||||
|
#include "otautil/mounts.h"
|
||||||
|
#include "otautil/sysutil.h"
|
||||||
|
|
||||||
|
std::string SimulatorRuntime::GetProperty(const std::string_view key,
|
||||||
|
const std::string_view default_value) const {
|
||||||
|
return source_->GetProperty(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorRuntime::Mount(const std::string_view location, const std::string_view mount_point,
|
||||||
|
const std::string_view /* fs_type */,
|
||||||
|
const std::string_view /* mount_options */) {
|
||||||
|
if (auto mounted_location = mounted_partitions_.find(mount_point);
|
||||||
|
mounted_location != mounted_partitions_.end() && mounted_location->second != location) {
|
||||||
|
LOG(ERROR) << mount_point << " has been mounted at " << mounted_location->second;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted_partitions_.emplace(mount_point, location);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SimulatorRuntime::IsMounted(const std::string_view mount_point) const {
|
||||||
|
return mounted_partitions_.find(mount_point) != mounted_partitions_.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<bool, int> SimulatorRuntime::Unmount(const std::string_view mount_point) {
|
||||||
|
if (!IsMounted(mount_point)) {
|
||||||
|
return { false, -1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted_partitions_.erase(std::string(mount_point));
|
||||||
|
return { true, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SimulatorRuntime::FindBlockDeviceName(const std::string_view name) const {
|
||||||
|
return source_->FindBlockDeviceName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(xunchang) implement the utility functions in simulator.
|
||||||
|
int SimulatorRuntime::RunProgram(const std::vector<std::string>& args, bool /* is_vfork */) const {
|
||||||
|
LOG(INFO) << "Running program with args " << android::base::Join(args, " ");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorRuntime::Tune2Fs(const std::vector<std::string>& args) const {
|
||||||
|
LOG(INFO) << "Running Tune2Fs with args " << android::base::Join(args, " ");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorRuntime::WipeBlockDevice(const std::string_view filename, size_t /* len */) const {
|
||||||
|
LOG(INFO) << "SKip wiping block device " << filename;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SimulatorRuntime::ReadFileToString(const std::string_view filename,
|
||||||
|
std::string* /* content */) const {
|
||||||
|
LOG(INFO) << "SKip reading filename " << filename;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SimulatorRuntime::WriteStringToFile(const std::string_view content,
|
||||||
|
const std::string_view filename) const {
|
||||||
|
LOG(INFO) << "SKip writing " << content.size() << " bytes to file " << filename;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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 "updater/target_files.h"
|
||||||
|
|
||||||
|
std::string TargetFiles::GetProperty(const std::string_view /*key*/,
|
||||||
|
const std::string_view default_value) const {
|
||||||
|
return std::string(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TargetFiles::FindBlockDeviceName(const std::string_view name) const {
|
||||||
|
return std::string(name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
|
||||||
|
#include <android-base/file.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
|
|
||||||
|
#include "otautil/error_code.h"
|
||||||
|
#include "otautil/paths.h"
|
||||||
|
#include "updater/blockimg.h"
|
||||||
|
#include "updater/install.h"
|
||||||
|
#include "updater/simulator_runtime.h"
|
||||||
|
#include "updater/target_files.h"
|
||||||
|
#include "updater/updater.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
// Write the logs to stdout.
|
||||||
|
android::base::InitLogging(argv, &android::base::StderrLogger);
|
||||||
|
|
||||||
|
if (argc != 3 && argc != 4) {
|
||||||
|
LOG(ERROR) << "unexpected number of arguments: " << argc << std::endl
|
||||||
|
<< "Usage: " << argv[0] << " <source_target-file> <ota_package>";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(xunchang) implement a commandline parser, e.g. it can take an oem property so that the
|
||||||
|
// file_getprop() will return correct value.
|
||||||
|
|
||||||
|
std::string source_target_file = argv[1];
|
||||||
|
std::string package_name = argv[2];
|
||||||
|
|
||||||
|
// Configure edify's functions.
|
||||||
|
RegisterBuiltins();
|
||||||
|
RegisterInstallFunctions();
|
||||||
|
RegisterBlockImageFunctions();
|
||||||
|
|
||||||
|
TemporaryFile temp_saved_source;
|
||||||
|
TemporaryFile temp_last_command;
|
||||||
|
TemporaryDir temp_stash_base;
|
||||||
|
|
||||||
|
Paths::Get().set_cache_temp_source(temp_saved_source.path);
|
||||||
|
Paths::Get().set_last_command_file(temp_last_command.path);
|
||||||
|
Paths::Get().set_stash_directory_base(temp_stash_base.path);
|
||||||
|
|
||||||
|
TemporaryFile cmd_pipe;
|
||||||
|
|
||||||
|
TemporaryDir source_temp_dir;
|
||||||
|
TargetFiles source(source_target_file, source_temp_dir.path);
|
||||||
|
|
||||||
|
Updater updater(std::make_unique<SimulatorRuntime>(&source));
|
||||||
|
if (!updater.Init(cmd_pipe.release(), package_name, false)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!updater.RunUpdate()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(INFO) << "\nscript succeeded, result: " << updater.GetResult();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+2
-1
@@ -175,7 +175,8 @@ bool Updater::ReadEntryToString(ZipArchiveHandle za, const std::string& entry_na
|
|||||||
int extract_err = ExtractToMemory(za, &entry, reinterpret_cast<uint8_t*>(&content->at(0)),
|
int extract_err = ExtractToMemory(za, &entry, reinterpret_cast<uint8_t*>(&content->at(0)),
|
||||||
entry.uncompressed_length);
|
entry.uncompressed_length);
|
||||||
if (extract_err != 0) {
|
if (extract_err != 0) {
|
||||||
LOG(ERROR) << "failed to read script from package: " << ErrorCodeString(extract_err);
|
LOG(ERROR) << "failed to read " << entry_name
|
||||||
|
<< " from package: " << ErrorCodeString(extract_err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user