From 87d41f7dd7a69bbf15973506faf113a83bd60511 Mon Sep 17 00:00:00 2001 From: Etienne Cordonnier Date: Mon, 6 Mar 2023 11:51:28 +0100 Subject: android-tools: add adb daemon Signed-off-by: Etienne Cordonnier --- .../selinux/android-tools/android-tools/adbd.mk | 72 +++++++++ .../core/0016-Adapt-adbd-to-work-with-yocto.patch | 161 +++++++++++++++++++++ .../android-tools/android-tools_10.0.0.r36.bb | 3 + 3 files changed, 236 insertions(+) create mode 100644 dynamic-layers/selinux/android-tools/android-tools/adbd.mk create mode 100644 dynamic-layers/selinux/android-tools/android-tools/core/0016-Adapt-adbd-to-work-with-yocto.patch (limited to 'dynamic-layers') diff --git a/dynamic-layers/selinux/android-tools/android-tools/adbd.mk b/dynamic-layers/selinux/android-tools/android-tools/adbd.mk new file mode 100644 index 0000000..cb82683 --- /dev/null +++ b/dynamic-layers/selinux/android-tools/android-tools/adbd.mk @@ -0,0 +1,72 @@ +include ../../rules_yocto.mk +NAME = adbd + +SOURCES = \ + adb/daemon/main.cpp \ + adb/daemon/auth.cpp \ + adb/daemon/jdwp_service.cpp \ + adb/daemon/file_sync_service.cpp \ + adb/daemon/services.cpp \ + adb/daemon/shell_service.cpp \ + adb/daemon/remount_service.cpp \ + adb/daemon/restart_service.cpp \ + adb/daemon/reboot_service.cpp \ + adb/daemon/framebuffer_service.cpp \ + adb/daemon/set_verity_enable_state_service.cpp \ + adb/shell_service_protocol.cpp \ + adb/adb.cpp \ + adb/adb_io.cpp \ + adb/adb_listeners.cpp \ + adb/adb_trace.cpp \ + adb/adb_unique_fd.cpp \ + adb/adb_utils.cpp \ + adb/fdevent.cpp \ + adb/services.cpp \ + adb/sockets.cpp \ + adb/socket_spec.cpp \ + adb/sysdeps/errno.cpp \ + adb/transport.cpp \ + adb/transport_fd.cpp \ + adb/transport_local.cpp \ + adb/transport_usb.cpp \ + adb/sysdeps_unix.cpp \ + adb/sysdeps/posix/network.cpp \ + adb/daemon/usb_legacy.cpp \ + adb/daemon/usb_ffs.cpp \ + adb/daemon/usb.cpp \ + diagnose_usb/diagnose_usb.cpp \ + libasyncio/AsyncIO.cpp \ + +CXXFLAGS += -std=gnu++20 +CPPFLAGS += -Iinclude -Iadb -Ibase/include -I$(OUT_DIR)/usr/include/ -Imkbootimg/include/bootimg -Ifs_mgr/include \ + -Ifs_mgr/include_fstab \ + -DADB_VERSION='"$(DEB_VERSION)"' -D_GNU_SOURCE +LDFLAGS += -Wl,-rpath=/usr/lib/$(DEB_HOST_MULTIARCH)/android -Wl,-rpath-link=$(OUT_DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/android/ \ + -lpthread -L$(OUT_DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/android/ -lbase -lcrypto_utils -lcrypto -lcutils -llog -lresolv + +PAGE_SIZE ?= 4096 + +CXXFLAGS += -UADB_HOST +CXXFLAGS += -DADB_HOST=0 +CXXFLAGS += -DALLOW_ADBD_DISABLE_VERITY +CXXFLAGS += -DALLOW_ADBD_NO_AUTH +CXXFLAGS += -DPLATFORM_TOOLS_VERSION='"28.0.2"' +CXXFLAGS += -Idiagnose_usb/include +CXXFLAGS += -Iadb/daemon/include +CXXFLAGS += -Ilibasyncio/include +CXXFLAGS += -Wno-c++11-narrowing +CXXFLAGS += -DPAGE_SIZE=$(PAGE_SIZE) + + +# -latomic should be the last library specified +# https://github.com/android/ndk/issues/589 +ifneq ($(filter armel mipsel,$(DEB_HOST_ARCH)),) + LDFLAGS += -latomic +endif + +build: $(SOURCES) + mkdir --parents ../../../android-tools/adbd + $(CXX) $^ -o ../../../android-tools/adbd/adbd $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) + +clean: + $(RM) $(OUT_DIR)/usr/bin/$(NAME) diff --git a/dynamic-layers/selinux/android-tools/android-tools/core/0016-Adapt-adbd-to-work-with-yocto.patch b/dynamic-layers/selinux/android-tools/android-tools/core/0016-Adapt-adbd-to-work-with-yocto.patch new file mode 100644 index 0000000..8819431 --- /dev/null +++ b/dynamic-layers/selinux/android-tools/android-tools/core/0016-Adapt-adbd-to-work-with-yocto.patch @@ -0,0 +1,161 @@ +From 1c836e4402ae170b3e0bf31da9012b7a3b1c40a1 Mon Sep 17 00:00:00 2001 +From: Etienne Cordonnier +Date: Wed, 8 Mar 2023 15:21:49 +0100 +Subject: [PATCH] Adapt adbd to work with yocto + +Co-authored-by: JJ Robertson +Co-authored-by: Wejdene Smida +Signed-off-by: Etienne Cordonnier +--- + adb/daemon/file_sync_service.cpp | 4 ++-- + adb/daemon/main.cpp | 4 ++-- + adb/daemon/reboot_service.cpp | 5 ++++- + adb/daemon/set_verity_enable_state_service.cpp | 6 +++++- + adb/daemon/shell_service.cpp | 4 ++++ + adb/types.h | 1 + + 6 files changed, 18 insertions(+), 6 deletions(-) + +diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp +index e82a51f2..ba112cbe 100644 +--- a/adb/daemon/file_sync_service.cpp ++++ b/adb/daemon/file_sync_service.cpp +@@ -111,7 +111,7 @@ static bool secure_mkdirs(const std::string& path) { + partial_path += path_component; + + if (should_use_fs_config(partial_path)) { +- fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); ++ // fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); + } + if (adb_mkdir(partial_path.c_str(), mode) == -1) { + if (errno != EEXIST) { +@@ -434,7 +434,7 @@ static bool do_send(int s, const std::string& spec, std::vector& buffer) { + uint64_t capabilities = 0; + if (should_use_fs_config(path)) { + unsigned int broken_api_hack = mode; +- fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities); ++ // fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities); + mode = broken_api_hack; + } + +diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp +index e5a49171..c75263c4 100644 +--- a/adb/daemon/main.cpp ++++ b/adb/daemon/main.cpp +@@ -191,6 +191,8 @@ int adbd_main(int server_port) { + umask(0); + + signal(SIGPIPE, SIG_IGN); ++ signal(SIGINT, SIG_DFL); ++ signal(SIGQUIT, SIG_DFL); + + #if defined(__BIONIC__) + auto fdsan_level = android_fdsan_get_error_level(); +@@ -232,13 +234,11 @@ int adbd_main(int server_port) { + + bool is_usb = false; + +-#if defined(__ANDROID__) + if (access(USB_FFS_ADB_EP0, F_OK) == 0) { + // Listen on USB. + usb_init(); + is_usb = true; + } +-#endif + + // If one of these properties is set, also listen on that port. + // If one of the properties isn't set and we couldn't listen on usb, listen +diff --git a/adb/daemon/reboot_service.cpp b/adb/daemon/reboot_service.cpp +index a5a11b86..6bd069d4 100644 +--- a/adb/daemon/reboot_service.cpp ++++ b/adb/daemon/reboot_service.cpp +@@ -28,7 +28,9 @@ + #include + #include + #include +-#include ++// #include ++#include ++#include + #include + + #include "adb_io.h" +@@ -76,6 +78,7 @@ void reboot_service(unique_fd fd, const std::string& arg) { + return; + } + } ++ syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_arg.c_str()); + // Don't return early. Give the reboot command time to take effect + // to avoid messing up scripts which do "adb reboot && adb wait-for-device" + while (true) { +diff --git a/adb/daemon/set_verity_enable_state_service.cpp b/adb/daemon/set_verity_enable_state_service.cpp +index 889229fe..51e9be93 100644 +--- a/adb/daemon/set_verity_enable_state_service.cpp ++++ b/adb/daemon/set_verity_enable_state_service.cpp +@@ -22,7 +22,7 @@ + #include + #include + #include +-#include ++// #include + #include + #include + #include +@@ -65,6 +65,7 @@ static bool make_block_device_writable(const std::string& dev) { + /* Turn verity on/off */ + static bool set_verity_enabled_state(int fd, const char* block_device, const char* mount_point, + bool enable) { ++#if defined(__ANDROID__) + if (!make_block_device_writable(block_device)) { + WriteFdFmt(fd, "Could not make block device %s writable (%s).\n", + block_device, strerror(errno)); +@@ -115,6 +116,7 @@ static bool set_verity_enabled_state(int fd, const char* block_device, const cha + mount_point, strerror(errno)); + } + WriteFdFmt(fd, "Verity %s on %s\n", enable ? "enabled" : "disabled", mount_point); ++#endif + return true; + } + +@@ -126,6 +128,7 @@ static std::string get_ab_suffix() { + return android::base::GetProperty("ro.boot.slot_suffix", ""); + } + ++#if defined(__ANDROID__) + static bool is_avb_device_locked() { + return android::base::GetProperty("ro.boot.vbmeta.device_state", "") == "locked"; + } +@@ -245,3 +248,4 @@ void set_verity_enabled_state_service(unique_fd fd, bool enable) { + WriteFdExactly(fd.get(), "Now reboot your device for settings to take effect\n"); + } + } ++#endif +diff --git a/adb/daemon/shell_service.cpp b/adb/daemon/shell_service.cpp +index 3c8f3939..84f4f54d 100644 +--- a/adb/daemon/shell_service.cpp ++++ b/adb/daemon/shell_service.cpp +@@ -264,6 +264,10 @@ bool Subprocess::ForkAndExec(std::string* error) { + env["TMPDIR"] = "/data/local/tmp"; + env["USER"] = pw->pw_name; + } ++ if (env.find("PS1") == env.end()) { ++ env["PS1"] = "\\h:\\w\\$ "; ++ } ++ + + if (!terminal_type_.empty()) { + env["TERM"] = terminal_type_; +diff --git a/adb/types.h b/adb/types.h +index 6af4a150..9efe223b 100644 +--- a/adb/types.h ++++ b/adb/types.h +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +-- +2.36.1.vfs.0.0 + diff --git a/dynamic-layers/selinux/android-tools/android-tools_10.0.0.r36.bb b/dynamic-layers/selinux/android-tools/android-tools_10.0.0.r36.bb index ca3c9be..f342655 100644 --- a/dynamic-layers/selinux/android-tools/android-tools_10.0.0.r36.bb +++ b/dynamic-layers/selinux/android-tools/android-tools_10.0.0.r36.bb @@ -75,12 +75,14 @@ SRC_URI += " \ file://core/0013-patching-libziparchive.mk-to-build-in-yocto-environm.patch;patchdir=system/core \ file://core/0014-patching-libbacktrace.mk-to-build-in-yocto-environme.patch;patchdir=system/core \ file://core/0015-Use-namespace-std-to-compile-libbacktrace.patch;patchdir=system/core \ + file://core/0016-Adapt-adbd-to-work-with-yocto.patch;patchdir=system/core \ file://0001-libcrypto.mk-modifications-to-make-it-build-in-yocto.patch;patchdir=external/boringssl \ file://0001-patching-libundwind-to-build-in-yocto-environment.patch;patchdir=external/libunwind \ file://0001-libext4_utils.mk-modifications-to-make-it-build-in-y.patch;patchdir=system/extras \ file://0002-libfec-change-out_dir-in-makefile.patch;patchdir=system/extras \ file://rules_yocto.mk;subdir=git \ file://android-tools-adbd.service \ + file://adbd.mk;subdir=git/system/core/debian \ " S = "${WORKDIR}/git" @@ -111,6 +113,7 @@ CC:append:class-nativesdk = " -I${STAGING_INCDIR}" PREREQUISITE_core = "libbase libsparse liblog libcutils" TOOLS_TO_BUILD = "libcrypto_utils libadb libziparchive fastboot adb img2simg simg2img libbacktrace" +TOOLS_TO_BUILD:append:class-target = " adbd" # Adb needs sys/capability.h, which is not available for native* TOOLS:class-native = "boringssl fastboot ext4_utils mkbootimg" -- cgit v1.2.3-54-g00ecf