android-tools 10: various fixes

- fix img2simg which was broken in the original recipe (wrong rpath and missing linking to libbase)
- remove clang dependency and make it compile with gcc
- fix installation of img2simg and simg2img which was broken in the original recipe
- backport patch https://github.com/nmeum/android-tools/blob/master/patches/adb/0023-Update-usage-of-usbdevfs_urb-to-match-new-kernel-UAP.patch
  The license is MIT, so it can be used.

Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
This commit is contained in:
Etienne Cordonnier
2023-03-10 16:49:28 +01:00
committed by Khem Raj
parent b85ae59968
commit b65453d5bc
6 changed files with 325 additions and 21 deletions
@@ -40,7 +40,7 @@ index 738b205..ada4ef9 100644
LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 \
-Wl,-rpath=/usr/lib/$(DEB_HOST_MULTIARCH)/android \
- -lpthread -nostdlib -lc -lgcc -Ldebian/out -l7z
+ -lpthread -nostdlib -lc -lgcc -l7z -Wno-error=unused-command-line-argument
+ -lpthread -nostdlib -lc -lgcc -l7z
build: $(SOURCES)
- mkdir --parents debian/out
@@ -52,12 +52,12 @@ index d1aba626..e75fa87c 100644
build: $(SOURCES)
- $(CXX) $^ -o fastboot/$(NAME) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
+ mkdir --parents $(OUT_DIR)/usr/bin/fastboot
+ $(CXX) $^ -o $(OUT_DIR)/usr/bin/fastboot/$(NAME) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
+ mkdir --parents $(OUT_DIR)/usr/bin/
+ $(CXX) $^ -o $(OUT_DIR)/usr/bin/$(NAME) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
clean:
- $(RM) fastboot/$(NAME)
+ $(RM) $(OUT_DIR)/usr/bin/fastboot/$(NAME)
+ $(RM) $(OUT_DIR)/usr/bin/$(NAME)
--
2.36.1.vfs.0.0
@@ -0,0 +1,128 @@
From 0dac14385d9c79089f8026e2764b75fa111adb8a Mon Sep 17 00:00:00 2001
From: Etienne Cordonnier <ecordonnier@snap.com>
Date: Tue, 14 Mar 2023 11:33:50 +0100
Subject: [PATCH] Update usage of usbdevfs_urb to match new kernel UAPI
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Linux kernel API has been changed by commit 94dfc73e7cf4 ("treewide: uapi: Replace zero-length arrays with flexible-array members")
where zero-length array iso_frame_desc in struct usbdevfs_urb was replaced with a proper flexible-array member.
Current USB API usage causes a compilation error at Linux 6.0:
In file included from /home/mae/.cache/kiss/proc/121205/build/android-tools/vendor/adb/client/usb_linux.cpp:28:
/usr/include/linux/usbdevice_fs.h:134:41: error: flexible array member usbdevfs_urb::iso_frame_desc not at end of struct usb_handle
134 | struct usbdevfs_iso_packet_desc iso_frame_desc[];
| ^~~~~~~~~~~~~~
/home/mae/.cache/kiss/proc/121205/build/android-tools/vendor/adb/client/usb_linux.cpp:76:18: note: next member usbdevfs_urb usb_handle::urb_out declared here
76 | usbdevfs_urb urb_out;
| ^~~~~~~
/home/mae/.cache/kiss/proc/121205/build/android-tools/vendor/adb/client/usb_linux.cpp:61:8: note: in the definition of struct usb_handle
61 | struct usb_handle {
| ^~~~~~~~~~
Fix it by using pointers to a struct with flexible-array members.
Current fix works both with the old and the new API.
See https://github.com/nmeum/android-tools/issues/74 for more context.
Tested: built on Linux against kernel 5.19 and 6.0; 'adb shell' over USB
cable
Acked-by: Gustavo A. R. Silva gustavoars@kernel.org
Change-Id: I7f0f7b35d9a3ab980d3520b541b60c7857a6b101
Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
[Backported on version 10]
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
adb/client/usb_linux.cpp | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/adb/client/usb_linux.cpp b/adb/client/usb_linux.cpp
index 81b83064..7d55ec5b 100644
--- a/adb/client/usb_linux.cpp
+++ b/adb/client/usb_linux.cpp
@@ -71,8 +71,8 @@ struct usb_handle : public ::usb_handle {
unsigned zero_mask;
unsigned writeable = 1;
- usbdevfs_urb urb_in;
- usbdevfs_urb urb_out;
+ usbdevfs_urb *urb_in;
+ usbdevfs_urb *urb_out;
bool urb_in_busy = false;
bool urb_out_busy = false;
@@ -305,7 +305,7 @@ static int usb_bulk_write(usb_handle* h, const void* data, int len) {
std::unique_lock<std::mutex> lock(h->mutex);
D("++ usb_bulk_write ++");
- usbdevfs_urb* urb = &h->urb_out;
+ usbdevfs_urb* urb = h->urb_out;
memset(urb, 0, sizeof(*urb));
urb->type = USBDEVFS_URB_TYPE_BULK;
urb->endpoint = h->ep_out;
@@ -344,7 +344,7 @@ static int usb_bulk_read(usb_handle* h, void* data, int len) {
std::unique_lock<std::mutex> lock(h->mutex);
D("++ usb_bulk_read ++");
- usbdevfs_urb* urb = &h->urb_in;
+ usbdevfs_urb* urb = h->urb_in;
memset(urb, 0, sizeof(*urb));
urb->type = USBDEVFS_URB_TYPE_BULK;
urb->endpoint = h->ep_in;
@@ -389,7 +389,7 @@ static int usb_bulk_read(usb_handle* h, void* data, int len) {
}
D("[ urb @%p status = %d, actual = %d ]", out, out->status, out->actual_length);
- if (out == &h->urb_in) {
+ if (out == h->urb_in) {
D("[ reap urb - IN complete ]");
h->urb_in_busy = false;
if (urb->status != 0) {
@@ -398,7 +398,7 @@ static int usb_bulk_read(usb_handle* h, void* data, int len) {
}
return urb->actual_length;
}
- if (out == &h->urb_out) {
+ if (out == h->urb_out) {
D("[ reap urb - OUT compelete ]");
h->urb_out_busy = false;
h->cv.notify_all();
@@ -483,10 +483,10 @@ void usb_kick(usb_handle* h) {
** but this ensures that a reader blocked on REAPURB
** will get unblocked
*/
- ioctl(h->fd, USBDEVFS_DISCARDURB, &h->urb_in);
- ioctl(h->fd, USBDEVFS_DISCARDURB, &h->urb_out);
- h->urb_in.status = -ENODEV;
- h->urb_out.status = -ENODEV;
+ ioctl(h->fd, USBDEVFS_DISCARDURB, h->urb_in);
+ ioctl(h->fd, USBDEVFS_DISCARDURB, h->urb_out);
+ h->urb_in->status = -ENODEV;
+ h->urb_out->status = -ENODEV;
h->urb_in_busy = false;
h->urb_out_busy = false;
h->cv.notify_all();
@@ -502,6 +502,8 @@ int usb_close(usb_handle* h) {
D("-- usb close %p (fd = %d) --", h, h->fd);
+ delete h->urb_in;
+ delete h->urb_out;
delete h;
return 0;
@@ -537,6 +539,8 @@ static void register_device(const char* dev_name, const char* dev_path, unsigned
usb->ep_out = ep_out;
usb->zero_mask = zero_mask;
usb->max_packet_size = max_packet_size;
+ usb->urb_in = new usbdevfs_urb;
+ usb->urb_out = new usbdevfs_urb;
// Initialize mark so we don't get garbage collected after the device scan.
usb->mark = true;
--
2.36.1.vfs.0.0
@@ -0,0 +1,26 @@
From 25bd3456dcd539b89648273152e405314287f4f8 Mon Sep 17 00:00:00 2001
From: Etienne Cordonnier <ecordonnier@snap.com>
Date: Mon, 13 Mar 2023 13:46:14 +0100
Subject: [PATCH 2/2] img2simg: Fix wrong rpath and re-add libbase
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
debian/img2simg.mk | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/debian/img2simg.mk b/debian/img2simg.mk
index d1b9b927..459af454 100644
--- a/debian/img2simg.mk
+++ b/debian/img2simg.mk
@@ -3,7 +3,7 @@ NAME = img2simg
SOURCES = img2simg.cpp
SOURCES := $(foreach source, $(SOURCES), libsparse/$(source))
CPPFLAGS += -Ilibsparse/include -Iinclude -std=gnu++17
-LDFLAGS += -Wl,-rpath=$(OUT_DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/android \
+LDFLAGS += -Wl,-rpath='$$ORIGIN/../lib/android' -lbase \
-Wl,-rpath-link=$(OUT_DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/android/ \
-L$(OUT_DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/android/ -lsparse
--
2.36.1.vfs.0.0
@@ -0,0 +1,157 @@
From d198ecb4c36b645e5428aa5117f7673bf2f7a3e6 Mon Sep 17 00:00:00 2001
From: Etienne Cordonnier <ecordonnier@snap.com>
Date: Tue, 14 Mar 2023 11:42:08 +0100
Subject: [PATCH] Fix compilation with gcc
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
adb/adb_listeners.cpp | 18 ++++++++++++------
adb/daemon/auth.cpp | 3 ++-
adb/daemon/usb.cpp | 3 ++-
adb/fdevent.cpp | 3 ++-
adb/transport_fd.cpp | 3 ++-
adb/transport_local.cpp | 3 ++-
6 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/adb/adb_listeners.cpp b/adb/adb_listeners.cpp
index 29909a55..fbdf4487 100644
--- a/adb/adb_listeners.cpp
+++ b/adb/adb_listeners.cpp
@@ -109,7 +109,8 @@ static void listener_event_func(int _fd, unsigned ev, void* _l)
}
// Called as a transport disconnect function. |arg| is the raw alistener*.
-static void listener_disconnect(void* arg, atransport*) EXCLUDES(listener_list_mutex) {
+ EXCLUDES(listener_list_mutex)
+static void listener_disconnect(void* arg, atransport*) {
std::lock_guard<std::mutex> lock(listener_list_mutex);
for (auto iter = listener_list.begin(); iter != listener_list.end(); ++iter) {
if (iter->get() == arg) {
@@ -121,7 +122,8 @@ static void listener_disconnect(void* arg, atransport*) EXCLUDES(listener_list_m
}
// Write the list of current listeners (network redirections) into a string.
-std::string format_listeners() EXCLUDES(listener_list_mutex) {
+EXCLUDES(listener_list_mutex)
+std::string format_listeners() {
std::lock_guard<std::mutex> lock(listener_list_mutex);
std::string result;
for (auto& l : listener_list) {
@@ -139,8 +141,9 @@ std::string format_listeners() EXCLUDES(listener_list_mutex) {
return result;
}
+EXCLUDES(listener_list_mutex)
InstallStatus remove_listener(const char* local_name, atransport* transport)
- EXCLUDES(listener_list_mutex) {
+{
std::lock_guard<std::mutex> lock(listener_list_mutex);
for (auto iter = listener_list.begin(); iter != listener_list.end(); ++iter) {
if (local_name == (*iter)->local_name) {
@@ -151,7 +154,8 @@ InstallStatus remove_listener(const char* local_name, atransport* transport)
return INSTALL_STATUS_LISTENER_NOT_FOUND;
}
-void remove_all_listeners() EXCLUDES(listener_list_mutex) {
+EXCLUDES(listener_list_mutex)
+void remove_all_listeners() {
std::lock_guard<std::mutex> lock(listener_list_mutex);
auto iter = listener_list.begin();
while (iter != listener_list.end()) {
@@ -164,7 +168,8 @@ void remove_all_listeners() EXCLUDES(listener_list_mutex) {
}
}
-void close_smartsockets() EXCLUDES(listener_list_mutex) {
+EXCLUDES(listener_list_mutex)
+void close_smartsockets() {
std::lock_guard<std::mutex> lock(listener_list_mutex);
auto pred = [](const std::unique_ptr<alistener>& listener) {
return listener->local_name == "*smartsocket*";
@@ -172,9 +177,10 @@ void close_smartsockets() EXCLUDES(listener_list_mutex) {
listener_list.remove_if(pred);
}
+EXCLUDES(listener_list_mutex)
InstallStatus install_listener(const std::string& local_name, const char* connect_to,
atransport* transport, int no_rebind, int* resolved_tcp_port,
- std::string* error) EXCLUDES(listener_list_mutex) {
+ std::string* error) {
std::lock_guard<std::mutex> lock(listener_list_mutex);
for (auto& l : listener_list) {
if (local_name == l->local_name) {
diff --git a/adb/daemon/auth.cpp b/adb/daemon/auth.cpp
index a18afa4e..0fd60a1f 100644
--- a/adb/daemon/auth.cpp
+++ b/adb/daemon/auth.cpp
@@ -98,8 +98,9 @@ bool adbd_auth_verify(const char* token, size_t token_size, const std::string& s
return false;
}
+REQUIRES(framework_mutex)
static bool adbd_send_key_message_locked(std::string_view msg_type, std::string_view key)
- REQUIRES(framework_mutex) {
+{
if (framework_fd < 0) {
LOG(ERROR) << "Client not connected to send msg_type " << msg_type;
return false;
diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp
index 1abae87c..3a466782 100644
--- a/adb/daemon/usb.cpp
+++ b/adb/daemon/usb.cpp
@@ -628,7 +628,8 @@ struct UsbFfsConnection : public Connection {
return CreateWriteBlock(std::move(block), 0, len, id);
}
- void SubmitWrites() REQUIRES(write_mutex_) {
+ REQUIRES(write_mutex_)
+ void SubmitWrites() {
if (writes_submitted_ == kUsbWriteQueueDepth) {
return;
}
diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp
index 32f90863..bff24544 100644
--- a/adb/fdevent.cpp
+++ b/adb/fdevent.cpp
@@ -376,7 +376,8 @@ static void fdevent_call_fdfunc(fdevent* fde) {
fde->func);
}
-static void fdevent_run_flush() EXCLUDES(run_queue_mutex) {
+EXCLUDES(run_queue_mutex)
+static void fdevent_run_flush() {
// We need to be careful around reentrancy here, since a function we call can queue up another
// function.
while (true) {
diff --git a/adb/transport_fd.cpp b/adb/transport_fd.cpp
index a93e68a0..c5af09ff 100644
--- a/adb/transport_fd.cpp
+++ b/adb/transport_fd.cpp
@@ -168,7 +168,8 @@ struct NonblockingFdConnection : public Connection {
TryAgain,
};
- WriteResult DispatchWrites() REQUIRES(write_mutex_) {
+ REQUIRES(write_mutex_)
+ WriteResult DispatchWrites() {
CHECK(!write_buffer_.empty());
auto iovs = write_buffer_.iovecs();
ssize_t rc = adb_writev(fd_.get(), iovs.data(), iovs.size());
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index b9f738df..a273e8f7 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -345,8 +345,9 @@ struct EmulatorConnection : public FdConnection {
};
/* Only call this function if you already hold local_transports_lock. */
+REQUIRES(local_transports_lock)
static atransport* find_emulator_transport_by_adb_port_locked(int adb_port)
- REQUIRES(local_transports_lock) {
+{
auto it = local_transports.find(adb_port);
if (it == local_transports.end()) {
return nullptr;
--
2.36.1.vfs.0.0
@@ -58,7 +58,7 @@ SRC_URI += " \
file://libunwind-debian/20150704-CVE-2015-3239_dwarf_i.h.patch;patchdir=external/libunwind \
"
# meta-clang specific patches + files:
# meta-openembedded specific patches + files:
SRC_URI += " \
file://core/0001-patching-adb.mk-to-build-in-yocto-environment.patch;patchdir=system/core \
file://core/0002-libadb.mk-modifications-to-make-it-build-in-yocto-en.patch;patchdir=system/core \
@@ -76,6 +76,9 @@ SRC_URI += " \
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://core/0017-Update-usage-of-usbdevfs_urb-to-match-new-kernel-UAP.patch;patchdir=system/core \
file://core/0018-img2simg-Fix-wrong-rpath.patch;patchdir=system/core \
file://core/0019-Fix-compilation-with-gcc.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 \
@@ -96,14 +99,7 @@ COMPATIBLE_HOST:powerpc = "(null)"
COMPATIBLE_HOST:powerpc64 = "(null)"
COMPATIBLE_HOST:powerpc64le = "(null)"
inherit systemd clang
TOOLCHAIN = "clang"
TOOLCHAIN:class-native = "clang"
DEPENDS:append:class-target = "\
clang-cross-${TARGET_ARCH} \
"
DEPENDS:append:class-native = " clang-native"
inherit systemd
SYSTEMD_SERVICE:${PN} = "android-tools-adbd.service"
@@ -175,9 +171,11 @@ do_compile() {
}
do_install() {
if echo ${TOOLS_TO_BUILD} | grep -q "ext4_utils" ; then
install -D -p -m0755 ${S}/system/core/libsparse/simg_dump.py ${D}${bindir}/simg_dump
fi
for tool in img2simg simg2img fastboot; do
if echo ${TOOLS_TO_BUILD} | grep -q "$tool" ; then
install -D -p -m0755 ${S}/debian/out/usr/bin/$tool ${D}${bindir}/$tool
fi
done
if echo ${TOOLS_TO_BUILD} | grep -q "adb " ; then
install -d ${D}${bindir}
@@ -193,11 +191,6 @@ do_install() {
install -D -p -m0644 ${WORKDIR}/android-tools-adbd.service \
${D}${systemd_unitdir}/system/android-tools-adbd.service
if echo ${TOOLS_TO_BUILD} | grep -q "fastboot" ; then
install -d ${D}${bindir}
install -m0755 ${S}/debian/out/usr/bin/fastboot/fastboot ${D}${bindir}
fi
install -d ${D}${libdir}/android/
install -m0755 ${S}/debian/out/usr/lib/android/*.so.* ${D}${libdir}/android/
if echo ${TOOLS_TO_BUILD} | grep -q "mkbootimg" ; then