diff --git a/aosptree/vendor/devices-community/gd_rpi4/device.mk b/aosptree/vendor/devices-community/gd_rpi4/device.mk
index 58b8f4c..eb2bd10 100644
--- a/aosptree/vendor/devices-community/gd_rpi4/device.mk
+++ b/aosptree/vendor/devices-community/gd_rpi4/device.mk
@@ -65,7 +65,7 @@ PRODUCT_VENDOR_PROPERTIES += \
ro.hardware.vulkan=broadcom \
# Enable Vulkan backend for SKIA/HWUI
-TARGET_USES_VULKAN = true
+# TARGET_USES_VULKAN = true
# Bluetooth
PRODUCT_VENDOR_PROPERTIES += \
diff --git a/manifests/glodroid.xml b/manifests/glodroid.xml
index 8fd2dd8..63cf95d 100644
--- a/manifests/glodroid.xml
+++ b/manifests/glodroid.xml
@@ -20,7 +20,7 @@
-
+
diff --git a/patches-aosp/build/soong/0001-GLODROID-Don-t-use-clang-tidy.patch b/patches-aosp/build/soong/0001-GLODROID-Don-t-use-clang-tidy.patch
deleted file mode 100644
index 1ba4cde..0000000
--- a/patches-aosp/build/soong/0001-GLODROID-Don-t-use-clang-tidy.patch
+++ /dev/null
@@ -1,29 +0,0 @@
-From 01daa7236225d6e714bcf2572cd7003345d98d39 Mon Sep 17 00:00:00 2001
-From: Roman Stratiienko
-Date: Sun, 21 May 2023 00:44:46 +0300
-Subject: [PATCH] GLODROID: Don't use clang-tidy
-
-It's pointless, time, and energy inefficient to run it globally.
-
-Change-Id: I12b94488c6f9e273786e099670a0610830ba024a
-Signed-off-by: Roman Stratiienko
----
- cc/tidy.go | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/cc/tidy.go b/cc/tidy.go
-index 750e9de1e..63f525e00 100644
---- a/cc/tidy.go
-+++ b/cc/tidy.go
-@@ -74,7 +74,7 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
- // If not explicitly disabled, set flags.Tidy to generate .tidy rules.
- // Note that libraries and binaries will depend on .tidy files ONLY if
- // the global WITH_TIDY or module 'tidy' property is true.
-- flags.Tidy = true
-+ flags.Tidy = false
-
- // If explicitly enabled, by global default or local tidy property,
- // set flags.NeedTidyFiles to make this module depend on .tidy files.
---
-2.39.2
-
diff --git a/patches-aosp/frameworks/base/0001-HWUI-Fix-deadlock-in-graphics-pipeline.patch b/patches-aosp/frameworks/base/0001-HWUI-Fix-deadlock-in-graphics-pipeline.patch
new file mode 100644
index 0000000..46983a7
--- /dev/null
+++ b/patches-aosp/frameworks/base/0001-HWUI-Fix-deadlock-in-graphics-pipeline.patch
@@ -0,0 +1,39 @@
+From 2be0dae3f8fb3c912edb49dba2f2cd434b8d9401 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Thu, 19 Oct 2023 03:37:01 +0300
+Subject: [PATCH] HWUI: Fix deadlock in graphics pipeline
+
+Mutex lock() causes deadlock when the queue is empty.
+Regression is caused by b013c8dee3b3e897b3557206f2d6c75b8c9f2f84
+For some unknown reason, it is reproduced only on GloDroid :)
+So probably some other part of GD is to blame.
+Or, it is just a coincidence.
+
+TODO: Do one more investigation attempt.
+
+Change-Id: Ic981947babe62b83032e9ba1630cc0458c228f44
+Signed-off-by: Roman Stratiienko
+---
+ libs/hwui/renderthread/CanvasContext.cpp | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
+index 16b35ffcabac..a9dde31e83e7 100644
+--- a/libs/hwui/renderthread/CanvasContext.cpp
++++ b/libs/hwui/renderthread/CanvasContext.cpp
+@@ -586,7 +586,11 @@ void CanvasContext::draw(bool solelyTextureViewUpdates) {
+ // not visible to IRenderPipeline much less FrameInfoVisualizer. And since this is
+ // the thread we're primarily concerned about being responsive, this being too broad
+ // shouldn't pose a performance issue.
+- std::scoped_lock lock(mFrameMetricsReporterMutex);
++
++// Causes deadlock when the queue is empty. Regression is caused by b013c8dee3b3e897b3557206f2d6c75b8c9f2f84
++// For some unknown reason, it is reproduced only on GloDroid :) So probably some other part of GD is to blame. Or, it is just a coincidence.
++// std::scoped_lock lock(mFrameMetricsReporterMutex);
++
+ drawResult = mRenderPipeline->draw(frame, windowDirty, dirty, mLightGeometry,
+ &mLayerUpdateQueue, mContentDrawBounds, mOpaque,
+ mLightInfo, mRenderNodes, &(profiler()), mBufferParams);
+--
+2.39.2
+
diff --git a/patches-aosp/frameworks/base/0001-Revert-Fix-crash-from-asynchronous-GPU-metrics.patch b/patches-aosp/frameworks/base/0001-Revert-Fix-crash-from-asynchronous-GPU-metrics.patch
deleted file mode 100644
index c5cd133..0000000
--- a/patches-aosp/frameworks/base/0001-Revert-Fix-crash-from-asynchronous-GPU-metrics.patch
+++ /dev/null
@@ -1,82 +0,0 @@
-From cadc9a7ccb98d6ec38b605ea7088087541de54fb Mon Sep 17 00:00:00 2001
-From: Roman Stratiienko
-Date: Wed, 29 Mar 2023 20:49:55 +0300
-Subject: [PATCH] Revert "Fix crash from asynchronous GPU metrics"
-
-This reverts commit 5d28aee1b1ac76e73db174535802bd2cc6069909.
-
-This commit causes race-condition in the following case:
-
-1. DrawFrame is out of free buffers and waiting for a new buffer to appear with
- mFrameMetricsReporterMutex locked.
-2. Binder can't finalize transaction staying in onSurfaceStatsAvailable,
- waiting for the mutex to be released, blocking SF transactions, and
- after 4s, the following logcat message appears:
-
-4866 V Surface : dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(0, 0, 1, 0x200) failed: -110
-4866 W OpenGLRenderer: dequeueBuffer failed, error = -110; switching to fallback
-4847 I Choreographer: Skipped 240 frames! The application may be doing too much work on its main thread.
-
-Change-Id: I12fa6824b75f8f108110b9336d5d2ea2da93814e
-Signed-off-by: Roman Stratiienko
----
- libs/hwui/FrameInfoVisualizer.cpp | 2 +-
- libs/hwui/renderthread/CanvasContext.cpp | 18 ++++--------------
- 2 files changed, 5 insertions(+), 15 deletions(-)
-
-diff --git a/libs/hwui/FrameInfoVisualizer.cpp b/libs/hwui/FrameInfoVisualizer.cpp
-index 687e4dd324d3..3a8e559f6d7e 100644
---- a/libs/hwui/FrameInfoVisualizer.cpp
-+++ b/libs/hwui/FrameInfoVisualizer.cpp
-@@ -179,7 +179,7 @@ void FrameInfoVisualizer::initializeRects(const int baseline, const int width) {
- void FrameInfoVisualizer::nextBarSegment(FrameInfoIndex start, FrameInfoIndex end) {
- int fast_i = (mNumFastRects - 1) * 4;
- int janky_i = (mNumJankyRects - 1) * 4;
--
-+ ;
- for (size_t fi = 0; fi < mFrameSource.size(); fi++) {
- if (mFrameSource[fi][FrameInfoIndex::Flags] & FrameInfoFlags::SkippedFrame) {
- continue;
-diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
-index 75d3ff7753cb..976117b9bbd4 100644
---- a/libs/hwui/renderthread/CanvasContext.cpp
-+++ b/libs/hwui/renderthread/CanvasContext.cpp
-@@ -512,19 +512,9 @@ nsecs_t CanvasContext::draw() {
-
- ATRACE_FORMAT("Drawing " RECT_STRING, SK_RECT_ARGS(dirty));
-
-- IRenderPipeline::DrawResult drawResult;
-- {
-- // FrameInfoVisualizer accesses the frame events, which cannot be mutated mid-draw
-- // or it can lead to memory corruption.
-- // This lock is overly broad, but it's the quickest fix since this mutex is otherwise
-- // not visible to IRenderPipeline much less FrameInfoVisualizer. And since this is
-- // the thread we're primarily concerned about being responsive, this being too broad
-- // shouldn't pose a performance issue.
-- std::scoped_lock lock(mFrameMetricsReporterMutex);
-- drawResult = mRenderPipeline->draw(frame, windowDirty, dirty, mLightGeometry,
-- &mLayerUpdateQueue, mContentDrawBounds, mOpaque,
-- mLightInfo, mRenderNodes, &(profiler()));
-- }
-+ const auto drawResult = mRenderPipeline->draw(frame, windowDirty, dirty, mLightGeometry,
-+ &mLayerUpdateQueue, mContentDrawBounds, mOpaque,
-+ mLightInfo, mRenderNodes, &(profiler()));
-
- uint64_t frameCompleteNr = getFrameNumber();
-
-@@ -764,11 +754,11 @@ void CanvasContext::onSurfaceStatsAvailable(void* context, int32_t surfaceContro
- FrameInfo* frameInfo = instance->getFrameInfoFromLast4(frameNumber, surfaceControlId);
-
- if (frameInfo != nullptr) {
-- std::scoped_lock lock(instance->mFrameMetricsReporterMutex);
- frameInfo->set(FrameInfoIndex::FrameCompleted) = std::max(gpuCompleteTime,
- frameInfo->get(FrameInfoIndex::SwapBuffersCompleted));
- frameInfo->set(FrameInfoIndex::GpuCompleted) = std::max(
- gpuCompleteTime, frameInfo->get(FrameInfoIndex::CommandSubmissionCompleted));
-+ std::scoped_lock lock(instance->mFrameMetricsReporterMutex);
- instance->mJankTracker.finishFrame(*frameInfo, instance->mFrameMetricsReporter, frameNumber,
- surfaceControlId);
- }
---
-2.34.1
-
diff --git a/patches-aosp/glodroid/bootloader/u-boot/0004-GLODROID-Speed-up-boot.patch b/patches-aosp/glodroid/bootloader/u-boot/0004-GLODROID-Speed-up-boot.patch
index 852e02f..8fddb03 100644
--- a/patches-aosp/glodroid/bootloader/u-boot/0004-GLODROID-Speed-up-boot.patch
+++ b/patches-aosp/glodroid/bootloader/u-boot/0004-GLODROID-Speed-up-boot.patch
@@ -16,7 +16,7 @@ index f03b56ad6a..4ab246315a 100644
CONFIG_CONSOLE_SCROLL_LINES=10
CONFIG_PHYS_TO_BUS=y
CONFIG_OF_LIBFDT_OVERLAY=y
-+CONFIG_BOOTDELAY=0
++CONFIG_BOOTDELAY=1
--
2.37.2
diff --git a/patches-aosp/glodroid/configuration/0008-base-Remove-deprecated-BOARD_BUILD_SYSTEM_ROOT_IMAGE.patch b/patches-aosp/glodroid/configuration/0008-base-Remove-deprecated-BOARD_BUILD_SYSTEM_ROOT_IMAGE.patch
new file mode 100644
index 0000000..e552d0d
--- /dev/null
+++ b/patches-aosp/glodroid/configuration/0008-base-Remove-deprecated-BOARD_BUILD_SYSTEM_ROOT_IMAGE.patch
@@ -0,0 +1,26 @@
+From 08bf277bb68ef649949a83eb908a35666dc7fccf Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 22:20:52 +0300
+Subject: [PATCH 08/12] base: Remove deprecated BOARD_BUILD_SYSTEM_ROOT_IMAGE
+ definition
+
+Signed-off-by: Roman Stratiienko
+---
+ common/base/board.mk | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/common/base/board.mk b/common/base/board.mk
+index 82c4292..73158c5 100644
+--- a/common/base/board.mk
++++ b/common/base/board.mk
+@@ -97,7 +97,6 @@ TARGET_COPY_OUT_VENDOR_DLKM := vendor_dlkm
+
+ # Root image
+ TARGET_COPY_OUT_ROOT := root
+-BOARD_BUILD_SYSTEM_ROOT_IMAGE := false
+
+ BOARD_EXT4_SHARE_DUP_BLOCKS := true
+
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/configuration/0009-hals-usb-gadget-Use-AOSP-libusbconfigfs-2.patch b/patches-aosp/glodroid/configuration/0009-hals-usb-gadget-Use-AOSP-libusbconfigfs-2.patch
new file mode 100644
index 0000000..0c4d805
--- /dev/null
+++ b/patches-aosp/glodroid/configuration/0009-hals-usb-gadget-Use-AOSP-libusbconfigfs-2.patch
@@ -0,0 +1,754 @@
+From d48d156bb8f5a212f004a5383505220cfba323e9 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 22:21:43 +0300
+Subject: [PATCH 09/12] hals/usb-gadget: Use AOSP libusbconfigfs-2
+
+It already has all the required functionality.
+
+Signed-off-by: Roman Stratiienko
+---
+ hals/usb-gadget/Android.bp | 2 +-
+ hals/usb-gadget/lib/Android.bp | 41 ---
+ hals/usb-gadget/lib/MonitorFfs.cpp | 269 ------------------
+ hals/usb-gadget/lib/UsbGadgetUtils.cpp | 207 --------------
+ hals/usb-gadget/lib/include/UsbGadgetCommon.h | 179 ------------
+ 5 files changed, 1 insertion(+), 697 deletions(-)
+ delete mode 100644 hals/usb-gadget/lib/Android.bp
+ delete mode 100644 hals/usb-gadget/lib/MonitorFfs.cpp
+ delete mode 100644 hals/usb-gadget/lib/UsbGadgetUtils.cpp
+ delete mode 100644 hals/usb-gadget/lib/include/UsbGadgetCommon.h
+
+diff --git a/hals/usb-gadget/Android.bp b/hals/usb-gadget/Android.bp
+index 3c3ea45..64b1250 100644
+--- a/hals/usb-gadget/Android.bp
++++ b/hals/usb-gadget/Android.bp
+@@ -36,5 +36,5 @@ cc_binary {
+ "liblog",
+ "libutils",
+ ],
+- static_libs: ["libusbconfigfs-2-gd"],
++ static_libs: ["libusbconfigfs-2"],
+ }
+diff --git a/hals/usb-gadget/lib/Android.bp b/hals/usb-gadget/lib/Android.bp
+deleted file mode 100644
+index 3c57acb..0000000
+--- a/hals/usb-gadget/lib/Android.bp
++++ /dev/null
+@@ -1,41 +0,0 @@
+-/*
+- * Copyright (C) 2020 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.
+- */
+-
+-cc_library_static {
+- name: "libusbconfigfs-2-gd",
+- vendor_available: true,
+- export_include_dirs: ["include"],
+-
+- srcs: [
+- "UsbGadgetUtils.cpp",
+- "MonitorFfs.cpp",
+- ],
+-
+- cflags: [
+- "-Wall",
+- "-Werror",
+- ],
+-
+- shared_libs: [
+- "android.hardware.usb.gadget@1.0",
+- "android.hardware.usb.gadget@1.1",
+- "android.hardware.usb.gadget@1.2",
+- "libbase",
+- "libcutils",
+- "libhidlbase",
+- "libutils",
+- ],
+-}
+diff --git a/hals/usb-gadget/lib/MonitorFfs.cpp b/hals/usb-gadget/lib/MonitorFfs.cpp
+deleted file mode 100644
+index 0cdf038..0000000
+--- a/hals/usb-gadget/lib/MonitorFfs.cpp
++++ /dev/null
+@@ -1,269 +0,0 @@
+-/*
+- * Copyright (C) 2020 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.
+- */
+-
+-#define LOG_TAG "libusbconfigfs"
+-
+-#include "include/UsbGadgetCommon.h"
+-
+-namespace android {
+-namespace hardware {
+-namespace usb {
+-namespace gadget {
+-
+-static volatile bool gadgetPullup;
+-
+-MonitorFfs::MonitorFfs(const char* const gadget)
+- : mWatchFd(),
+- mEndpointList(),
+- mLock(),
+- mCv(),
+- mLockFd(),
+- mCurrentUsbFunctionsApplied(false),
+- mMonitor(),
+- mCallback(NULL),
+- mPayload(NULL),
+- mGadgetName(gadget),
+- mMonitorRunning(false) {
+- unique_fd eventFd(eventfd(0, 0));
+- if (eventFd == -1) {
+- ALOGE("mEventFd failed to create %d", errno);
+- abort();
+- }
+-
+- unique_fd epollFd(epoll_create(2));
+- if (epollFd == -1) {
+- ALOGE("mEpollFd failed to create %d", errno);
+- abort();
+- }
+-
+- unique_fd inotifyFd(inotify_init());
+- if (inotifyFd < 0) {
+- ALOGE("inotify init failed");
+- abort();
+- }
+-
+- if (addEpollFd(epollFd, inotifyFd) == -1) abort();
+-
+- if (addEpollFd(epollFd, eventFd) == -1) abort();
+-
+- mEpollFd = move(epollFd);
+- mInotifyFd = move(inotifyFd);
+- mEventFd = move(eventFd);
+- gadgetPullup = false;
+-}
+-
+-static void displayInotifyEvent(struct inotify_event* i) {
+- ALOGE(" wd =%2d; ", i->wd);
+- if (i->cookie > 0) ALOGE("cookie =%4d; ", i->cookie);
+-
+- ALOGE("mask = ");
+- if (i->mask & IN_ACCESS) ALOGE("IN_ACCESS ");
+- if (i->mask & IN_ATTRIB) ALOGE("IN_ATTRIB ");
+- if (i->mask & IN_CLOSE_NOWRITE) ALOGE("IN_CLOSE_NOWRITE ");
+- if (i->mask & IN_CLOSE_WRITE) ALOGE("IN_CLOSE_WRITE ");
+- if (i->mask & IN_CREATE) ALOGE("IN_CREATE ");
+- if (i->mask & IN_DELETE) ALOGE("IN_DELETE ");
+- if (i->mask & IN_DELETE_SELF) ALOGE("IN_DELETE_SELF ");
+- if (i->mask & IN_IGNORED) ALOGE("IN_IGNORED ");
+- if (i->mask & IN_ISDIR) ALOGE("IN_ISDIR ");
+- if (i->mask & IN_MODIFY) ALOGE("IN_MODIFY ");
+- if (i->mask & IN_MOVE_SELF) ALOGE("IN_MOVE_SELF ");
+- if (i->mask & IN_MOVED_FROM) ALOGE("IN_MOVED_FROM ");
+- if (i->mask & IN_MOVED_TO) ALOGE("IN_MOVED_TO ");
+- if (i->mask & IN_OPEN) ALOGE("IN_OPEN ");
+- if (i->mask & IN_Q_OVERFLOW) ALOGE("IN_Q_OVERFLOW ");
+- if (i->mask & IN_UNMOUNT) ALOGE("IN_UNMOUNT ");
+- ALOGE("\n");
+-
+- if (i->len > 0) ALOGE(" name = %s\n", i->name);
+-}
+-
+-void* MonitorFfs::startMonitorFd(void* param) {
+- MonitorFfs* monitorFfs = (MonitorFfs*)param;
+- char buf[kBufferSize];
+- bool writeUdc = true, stopMonitor = false;
+- struct epoll_event events[kEpollEvents];
+- steady_clock::time_point disconnect;
+-
+- bool descriptorWritten = true;
+- for (int i = 0; i < static_cast(monitorFfs->mEndpointList.size()); i++) {
+- if (access(monitorFfs->mEndpointList.at(i).c_str(), R_OK)) {
+- descriptorWritten = false;
+- break;
+- }
+- }
+-
+- // notify here if the endpoints are already present.
+- if (descriptorWritten) {
+- usleep(kPullUpDelay);
+- if (!!WriteStringToFile(monitorFfs->mGadgetName, PULLUP_PATH)) {
+- lock_guard lock(monitorFfs->mLock);
+- monitorFfs->mCurrentUsbFunctionsApplied = true;
+- monitorFfs->mCallback(monitorFfs->mCurrentUsbFunctionsApplied, monitorFfs->mPayload);
+- gadgetPullup = true;
+- writeUdc = false;
+- ALOGI("GADGET pulled up");
+- monitorFfs->mCv.notify_all();
+- }
+- }
+-
+- while (!stopMonitor) {
+- int nrEvents = epoll_wait(monitorFfs->mEpollFd, events, kEpollEvents, -1);
+-
+- if (nrEvents <= 0) {
+- ALOGE("epoll wait did not return descriptor number");
+- continue;
+- }
+-
+- for (int i = 0; i < nrEvents; i++) {
+- ALOGI("event=%u on fd=%d\n", events[i].events, events[i].data.fd);
+-
+- if (events[i].data.fd == monitorFfs->mInotifyFd) {
+- // Process all of the events in buffer returned by read().
+- int numRead = read(monitorFfs->mInotifyFd, buf, kBufferSize);
+- for (char* p = buf; p < buf + numRead;) {
+- struct inotify_event* event = (struct inotify_event*)p;
+- if (kDebug) displayInotifyEvent(event);
+-
+- p += sizeof(struct inotify_event) + event->len;
+-
+- bool descriptorPresent = true;
+- for (int j = 0; j < static_cast(monitorFfs->mEndpointList.size()); j++) {
+- if (access(monitorFfs->mEndpointList.at(j).c_str(), R_OK)) {
+- if (kDebug) ALOGI("%s absent", monitorFfs->mEndpointList.at(j).c_str());
+- descriptorPresent = false;
+- break;
+- }
+- }
+-
+- if (!descriptorPresent && !writeUdc) {
+- if (kDebug) ALOGI("endpoints not up");
+- writeUdc = true;
+- disconnect = std::chrono::steady_clock::now();
+- } else if (descriptorPresent && writeUdc) {
+- steady_clock::time_point temp = steady_clock::now();
+-
+- if (std::chrono::duration_cast(temp - disconnect).count() <
+- kPullUpDelay)
+- usleep(kPullUpDelay);
+-
+- if (!!WriteStringToFile(monitorFfs->mGadgetName, PULLUP_PATH)) {
+- lock_guard lock(monitorFfs->mLock);
+- monitorFfs->mCurrentUsbFunctionsApplied = true;
+- monitorFfs->mCallback(monitorFfs->mCurrentUsbFunctionsApplied,
+- monitorFfs->mPayload);
+- ALOGI("GADGET pulled up");
+- writeUdc = false;
+- gadgetPullup = true;
+- // notify the main thread to signal userspace.
+- monitorFfs->mCv.notify_all();
+- }
+- }
+- }
+- } else {
+- uint64_t flag;
+- read(monitorFfs->mEventFd, &flag, sizeof(flag));
+- if (flag == 100) {
+- stopMonitor = true;
+- break;
+- }
+- }
+- }
+- }
+- return NULL;
+-}
+-
+-void MonitorFfs::reset() {
+- lock_guard lock(mLockFd);
+- uint64_t flag = 100;
+- unsigned long ret;
+-
+- if (mMonitorRunning) {
+- // Stop the monitor thread by writing into signal fd.
+- ret = TEMP_FAILURE_RETRY(write(mEventFd, &flag, sizeof(flag)));
+- if (ret < 0) ALOGE("Error writing eventfd errno=%d", errno);
+-
+- ALOGI("mMonitor signalled to exit");
+- mMonitor->join();
+- ALOGI("mMonitor destroyed");
+- mMonitorRunning = false;
+- }
+-
+- for (std::vector::size_type i = 0; i != mWatchFd.size(); i++)
+- inotify_rm_watch(mInotifyFd, mWatchFd[i]);
+-
+- mEndpointList.clear();
+- gadgetPullup = false;
+- mCallback = NULL;
+- mPayload = NULL;
+-}
+-
+-bool MonitorFfs::startMonitor() {
+- mMonitor = unique_ptr(new thread(this->startMonitorFd, this));
+- mMonitorRunning = true;
+- return true;
+-}
+-
+-bool MonitorFfs::isMonitorRunning() {
+- return mMonitorRunning;
+-}
+-
+-bool MonitorFfs::waitForPullUp(int timeout_ms) {
+- std::unique_lock lk(mLock);
+-
+- if (gadgetPullup) return true;
+-
+- if (mCv.wait_for(lk, timeout_ms * 1ms, [] { return gadgetPullup; })) {
+- ALOGI("monitorFfs signalled true");
+- return true;
+- } else {
+- ALOGI("monitorFfs signalled error");
+- // continue monitoring as the descriptors might be written at a later
+- // point.
+- return false;
+- }
+-}
+-
+-bool MonitorFfs::addInotifyFd(string fd) {
+- lock_guard lock(mLockFd);
+- int wfd;
+-
+- wfd = inotify_add_watch(mInotifyFd, fd.c_str(), IN_ALL_EVENTS);
+- if (wfd == -1)
+- return false;
+- else
+- mWatchFd.push_back(wfd);
+-
+- return true;
+-}
+-
+-void MonitorFfs::addEndPoint(string ep) {
+- lock_guard lock(mLockFd);
+-
+- mEndpointList.push_back(ep);
+-}
+-
+-void MonitorFfs::registerFunctionsAppliedCallback(void (*callback)(bool functionsApplied,
+- void* payload),
+- void* payload) {
+- mCallback = callback;
+- mPayload = payload;
+-}
+-
+-} // namespace gadget
+-} // namespace usb
+-} // namespace hardware
+-} // namespace android
+diff --git a/hals/usb-gadget/lib/UsbGadgetUtils.cpp b/hals/usb-gadget/lib/UsbGadgetUtils.cpp
+deleted file mode 100644
+index 0924da7..0000000
+--- a/hals/usb-gadget/lib/UsbGadgetUtils.cpp
++++ /dev/null
+@@ -1,207 +0,0 @@
+-/*
+- * Copyright (C) 2020 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.
+- */
+-
+-#define LOG_TAG "libusbconfigfs"
+-
+-#include "include/UsbGadgetCommon.h"
+-
+-namespace android {
+-namespace hardware {
+-namespace usb {
+-namespace gadget {
+-
+-int unlinkFunctions(const char* path) {
+- DIR* config = opendir(path);
+- struct dirent* function;
+- char filepath[kMaxFilePathLength];
+- int ret = 0;
+-
+- if (config == NULL) return -1;
+-
+- // d_type does not seems to be supported in /config
+- // so filtering by name.
+- while (((function = readdir(config)) != NULL)) {
+- if ((strstr(function->d_name, FUNCTION_NAME) == NULL)) continue;
+- // build the path for each file in the folder.
+- sprintf(filepath, "%s/%s", path, function->d_name);
+- ret = remove(filepath);
+- if (ret) {
+- ALOGE("Unable remove file %s errno:%d", filepath, errno);
+- break;
+- }
+- }
+-
+- closedir(config);
+- return ret;
+-}
+-
+-int addEpollFd(const unique_fd& epfd, const unique_fd& fd) {
+- struct epoll_event event;
+- int ret;
+-
+- event.data.fd = fd;
+- event.events = EPOLLIN;
+-
+- ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event);
+- if (ret) ALOGE("epoll_ctl error %d", errno);
+-
+- return ret;
+-}
+-
+-int linkFunction(const char* function, int index) {
+- char functionPath[kMaxFilePathLength];
+- char link[kMaxFilePathLength];
+-
+- sprintf(functionPath, "%s%s", FUNCTIONS_PATH, function);
+- sprintf(link, "%s%d", FUNCTION_PATH, index);
+- if (symlink(functionPath, link)) {
+- ALOGE("Cannot create symlink %s -> %s errno:%d", link, functionPath, errno);
+- return -1;
+- }
+- return 0;
+-}
+-
+-Status setVidPid(const char* vid, const char* pid) {
+- if (!WriteStringToFile(vid, VENDOR_ID_PATH)) return Status::ERROR;
+-
+- if (!WriteStringToFile(pid, PRODUCT_ID_PATH)) return Status::ERROR;
+-
+- return Status::SUCCESS;
+-}
+-
+-std::string getVendorFunctions() {
+- if (GetProperty(kBuildType, "") == "user") return "user";
+-
+- std::string bootMode = GetProperty(PERSISTENT_BOOT_MODE, "");
+- std::string persistVendorFunctions = GetProperty(kPersistentVendorConfig, "");
+- std::string vendorFunctions = GetProperty(kVendorConfig, "");
+- std::string ret = "";
+-
+- if (vendorFunctions != "") {
+- ret = vendorFunctions;
+- } else if (bootMode == "usbradio" || bootMode == "factory" || bootMode == "ffbm-00" ||
+- bootMode == "ffbm-01") {
+- if (persistVendorFunctions != "")
+- ret = persistVendorFunctions;
+- else
+- ret = "diag";
+- // vendor.usb.config will reflect the current configured functions
+- SetProperty(kVendorConfig, ret);
+- }
+-
+- return ret;
+-}
+-
+-Status resetGadget() {
+- ALOGI("setCurrentUsbFunctions None");
+-
+- if (!WriteStringToFile("none", PULLUP_PATH)) ALOGI("Gadget cannot be pulled down");
+-
+- if (!WriteStringToFile("0", DEVICE_CLASS_PATH)) return Status::ERROR;
+-
+- if (!WriteStringToFile("0", DEVICE_SUB_CLASS_PATH)) return Status::ERROR;
+-
+- if (!WriteStringToFile("0", DEVICE_PROTOCOL_PATH)) return Status::ERROR;
+-
+- if (!WriteStringToFile("0", DESC_USE_PATH)) return Status::ERROR;
+-
+- if (unlinkFunctions(CONFIG_PATH)) return Status::ERROR;
+-
+- return Status::SUCCESS;
+-}
+-
+-Status addGenericAndroidFunctions(MonitorFfs* monitorFfs, uint64_t functions, bool* ffsEnabled,
+- int* functionCount) {
+- if (((functions & GadgetFunction::MTP) != 0)) {
+- *ffsEnabled = true;
+- ALOGI("setCurrentUsbFunctions mtp");
+- if (!WriteStringToFile("1", DESC_USE_PATH)) return Status::ERROR;
+-
+- if (!monitorFfs->addInotifyFd("/dev/usb-ffs/mtp/")) return Status::ERROR;
+-
+- if (linkFunction("ffs.mtp", (*functionCount)++)) return Status::ERROR;
+-
+- // Add endpoints to be monitored.
+- monitorFfs->addEndPoint("/dev/usb-ffs/mtp/ep1");
+- monitorFfs->addEndPoint("/dev/usb-ffs/mtp/ep2");
+- monitorFfs->addEndPoint("/dev/usb-ffs/mtp/ep3");
+- } else if (((functions & GadgetFunction::PTP) != 0)) {
+- *ffsEnabled = true;
+- ALOGI("setCurrentUsbFunctions ptp");
+- if (!WriteStringToFile("1", DESC_USE_PATH)) return Status::ERROR;
+-
+- if (!monitorFfs->addInotifyFd("/dev/usb-ffs/ptp/")) return Status::ERROR;
+-
+- if (linkFunction("ffs.ptp", (*functionCount)++)) return Status::ERROR;
+-
+- // Add endpoints to be monitored.
+- monitorFfs->addEndPoint("/dev/usb-ffs/ptp/ep1");
+- monitorFfs->addEndPoint("/dev/usb-ffs/ptp/ep2");
+- monitorFfs->addEndPoint("/dev/usb-ffs/ptp/ep3");
+- }
+-
+- if ((functions & GadgetFunction::MIDI) != 0) {
+- ALOGI("setCurrentUsbFunctions MIDI");
+- if (linkFunction("midi.gs5", (*functionCount)++)) return Status::ERROR;
+- }
+-
+- if ((functions & GadgetFunction::ACCESSORY) != 0) {
+- ALOGI("setCurrentUsbFunctions Accessory");
+- if (linkFunction("accessory.gs2", (*functionCount)++)) return Status::ERROR;
+- }
+-
+- if ((functions & GadgetFunction::AUDIO_SOURCE) != 0) {
+- ALOGI("setCurrentUsbFunctions Audio Source");
+- if (linkFunction("audio_source.gs3", (*functionCount)++)) return Status::ERROR;
+- }
+-
+- if ((functions & GadgetFunction::RNDIS) != 0) {
+- ALOGI("setCurrentUsbFunctions rndis");
+- std::string rndisFunction = GetProperty(kVendorRndisConfig, "");
+- if (rndisFunction != "") {
+- if (linkFunction(rndisFunction.c_str(), (*functionCount)++)) return Status::ERROR;
+- } else {
+- // link gsi.rndis for older pixel projects
+- if (linkFunction("gsi.rndis", (*functionCount)++)) return Status::ERROR;
+- }
+- }
+-
+- if ((functions & GadgetFunction::NCM) != 0) {
+- ALOGI("setCurrentUsbFunctions ncm");
+- if (linkFunction("ncm.gs6", (*functionCount)++)) return Status::ERROR;
+- }
+-
+- return Status::SUCCESS;
+-}
+-
+-Status addAdb(MonitorFfs* monitorFfs, int* functionCount) {
+- ALOGI("setCurrentUsbFunctions Adb");
+- if (!WriteStringToFile("1", DESC_USE_PATH))
+- return Status::ERROR;
+-
+- if (!monitorFfs->addInotifyFd("/dev/usb-ffs/adb/")) return Status::ERROR;
+-
+- if (linkFunction("ffs.adb", (*functionCount)++)) return Status::ERROR;
+- monitorFfs->addEndPoint("/dev/usb-ffs/adb/ep1");
+- monitorFfs->addEndPoint("/dev/usb-ffs/adb/ep2");
+- ALOGI("Service started");
+- return Status::SUCCESS;
+-}
+-
+-} // namespace gadget
+-} // namespace usb
+-} // namespace hardware
+-} // namespace android
+diff --git a/hals/usb-gadget/lib/include/UsbGadgetCommon.h b/hals/usb-gadget/lib/include/UsbGadgetCommon.h
+deleted file mode 100644
+index 18b8101..0000000
+--- a/hals/usb-gadget/lib/include/UsbGadgetCommon.h
++++ /dev/null
+@@ -1,179 +0,0 @@
+-/*
+- * Copyright (C) 2020 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.
+- */
+-
+-#ifndef HARDWARE_USB_USBGADGETCOMMON_H
+-#define HARDWARE_USB_USBGADGETCOMMON_H
+-
+-#include
+-#include
+-#include
+-
+-#include
+-#include
+-
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-#include
+-
+-namespace android {
+-namespace hardware {
+-namespace usb {
+-namespace gadget {
+-
+-constexpr int kBufferSize = 512;
+-constexpr int kMaxFilePathLength = 256;
+-constexpr int kEpollEvents = 10;
+-constexpr bool kDebug = false;
+-constexpr int kDisconnectWaitUs = 100000;
+-constexpr int kPullUpDelay = 500000;
+-constexpr int kShutdownMonitor = 100;
+-
+-constexpr char kBuildType[] = "ro.build.type";
+-constexpr char kPersistentVendorConfig[] = "persist.vendor.usb.usbradio.config";
+-constexpr char kVendorConfig[] = "vendor.usb.config";
+-constexpr char kVendorRndisConfig[] = "vendor.usb.rndis.config";
+-
+-#define GADGET_PATH "/config/usb_gadget/g1/"
+-#define PULLUP_PATH GADGET_PATH "UDC"
+-#define PERSISTENT_BOOT_MODE "ro.bootmode"
+-#define VENDOR_ID_PATH GADGET_PATH "idVendor"
+-#define PRODUCT_ID_PATH GADGET_PATH "idProduct"
+-#define DEVICE_CLASS_PATH GADGET_PATH "bDeviceClass"
+-#define DEVICE_SUB_CLASS_PATH GADGET_PATH "bDeviceSubClass"
+-#define DEVICE_PROTOCOL_PATH GADGET_PATH "bDeviceProtocol"
+-#define DESC_USE_PATH GADGET_PATH "os_desc/use"
+-#define OS_DESC_PATH GADGET_PATH "os_desc/b.1"
+-#define CONFIG_PATH GADGET_PATH "configs/b.1/"
+-#define FUNCTIONS_PATH GADGET_PATH "functions/"
+-#define FUNCTION_NAME "function"
+-#define FUNCTION_PATH CONFIG_PATH FUNCTION_NAME
+-#define RNDIS_PATH FUNCTIONS_PATH "gsi.rndis"
+-
+-using ::android::base::GetProperty;
+-using ::android::base::SetProperty;
+-using ::android::base::unique_fd;
+-using ::android::base::WriteStringToFile;
+-using ::android::hardware::usb::gadget::V1_0::Status;
+-using ::android::hardware::usb::gadget::V1_2::GadgetFunction;
+-
+-using ::std::lock_guard;
+-using ::std::move;
+-using ::std::mutex;
+-using ::std::string;
+-using ::std::thread;
+-using ::std::unique_ptr;
+-using ::std::vector;
+-using ::std::chrono::microseconds;
+-using ::std::chrono::steady_clock;
+-using ::std::literals::chrono_literals::operator""ms;
+-
+-// MonitorFfs automously manages gadget pullup by monitoring
+-// the ep file status. Restarts the usb gadget when the ep
+-// owner restarts.
+-class MonitorFfs {
+- private:
+- // Monitors the endpoints Inotify events.
+- unique_fd mInotifyFd;
+- // Control pipe for shutting down the mMonitor thread.
+- // mMonitor exits when SHUTDOWN_MONITOR is written into
+- // mEventFd/
+- unique_fd mEventFd;
+- // Pools on mInotifyFd and mEventFd.
+- unique_fd mEpollFd;
+- vector mWatchFd;
+-
+- // Maintains the list of Endpoints.
+- vector mEndpointList;
+- // protects the CV.
+- std::mutex mLock;
+- std::condition_variable mCv;
+- // protects mInotifyFd, mEpollFd.
+- std::mutex mLockFd;
+-
+- // Flag to maintain the current status of gadget pullup.
+- bool mCurrentUsbFunctionsApplied;
+-
+- // Thread object that executes the ep monitoring logic.
+- unique_ptr mMonitor;
+- // Callback to be invoked when gadget is pulled up.
+- void (*mCallback)(bool functionsApplied, void* payload);
+- void* mPayload;
+- // Name of the USB gadget. Used for pullup.
+- const char* const mGadgetName;
+- // Monitor State
+- bool mMonitorRunning;
+-
+- public:
+- MonitorFfs(const char* const gadget);
+- // Inits all the UniqueFds.
+- void reset();
+- // Starts monitoring endpoints and pullup the gadget when
+- // the descriptors are written.
+- bool startMonitor();
+- // Waits for timeout_ms for gadget pull up to happen.
+- // Returns immediately if the gadget is already pulled up.
+- bool waitForPullUp(int timeout_ms);
+- // Adds the given fd to the watch list.
+- bool addInotifyFd(string fd);
+- // Adds the given endpoint to the watch list.
+- void addEndPoint(string ep);
+- // Registers the async callback from the caller to notify the caller
+- // when the gadget pull up happens.
+- void registerFunctionsAppliedCallback(void (*callback)(bool functionsApplied, void*(payload)),
+- void* payload);
+- bool isMonitorRunning();
+- // Ep monitoring and the gadget pull up logic.
+- static void* startMonitorFd(void* param);
+-};
+-
+-//**************** Helper functions ************************//
+-
+-// Adds the given fd to the epollfd(epfd).
+-int addEpollFd(const unique_fd& epfd, const unique_fd& fd);
+-// Removes all the usb functions link in the specified path.
+-int unlinkFunctions(const char* path);
+-// Craetes a configfs link for the function.
+-int linkFunction(const char* function, int index);
+-// Sets the USB VID and PID.
+-Status setVidPid(const char* vid, const char* pid);
+-// Extracts vendor functions from the vendor init properties.
+-std::string getVendorFunctions();
+-// Adds Adb to the usb configuration.
+-Status addAdb(MonitorFfs* monitorFfs, int* functionCount);
+-// Adds all applicable generic android usb functions other than ADB.
+-Status addGenericAndroidFunctions(MonitorFfs* monitorFfs, uint64_t functions, bool* ffsEnabled,
+- int* functionCount);
+-// Pulls down USB gadget.
+-Status resetGadget();
+-
+-} // namespace gadget
+-} // namespace usb
+-} // namespace hardware
+-} // namespace android
+-#endif
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/configuration/0010-platform-kernel-Rename-mkdtboimg.py-to-mkdtboimg.patch b/patches-aosp/glodroid/configuration/0010-platform-kernel-Rename-mkdtboimg.py-to-mkdtboimg.patch
new file mode 100644
index 0000000..1351561
--- /dev/null
+++ b/patches-aosp/glodroid/configuration/0010-platform-kernel-Rename-mkdtboimg.py-to-mkdtboimg.patch
@@ -0,0 +1,28 @@
+From fd603a41fb896f19960d406bbe8bcaa0e1efb5d2 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 22:23:21 +0300
+Subject: [PATCH 10/12] platform/kernel: Rename mkdtboimg.py to mkdtboimg
+
+It was renamed in AOSP. Do the same here.
+
+Signed-off-by: Roman Stratiienko
+---
+ platform/kernel/kernel.mk | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/platform/kernel/kernel.mk b/platform/kernel/kernel.mk
+index b44808c..d49b729 100644
+--- a/platform/kernel/kernel.mk
++++ b/platform/kernel/kernel.mk
+@@ -66,7 +66,7 @@ ANDROID_DTS_OVERLAY ?= $(LOCAL_PATH)/empty.dts
+
+ ANDROID_DTBO := $(PRODUCT_OUT)/obj/GLODROID/DTBO/fstab-android-sdcard.dtbo
+ BOARD_PREBUILT_DTBOIMAGE := $(PRODUCT_OUT)/boot_dtbo.img
+-MKDTBOIMG := $(HOST_OUT_EXECUTABLES)/mkdtboimg.py
++MKDTBOIMG := $(HOST_OUT_EXECUTABLES)/mkdtboimg
+ GEN_DTBCFG := $(PRODUCT_OUT)/gen/DTBO/dtbo.cfg
+
+ $(TARGET_VENDOR_MODULES)/modules.dep: $(KERNEL_TARGET)
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/configuration/0011-base-Set-TARGET_FLATTEN_APEX-to-true.patch b/patches-aosp/glodroid/configuration/0011-base-Set-TARGET_FLATTEN_APEX-to-true.patch
new file mode 100644
index 0000000..fee42c5
--- /dev/null
+++ b/patches-aosp/glodroid/configuration/0011-base-Set-TARGET_FLATTEN_APEX-to-true.patch
@@ -0,0 +1,27 @@
+From 6186d9cec9d353ea537e179c23978c4fe7577017 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Thu, 19 Oct 2023 03:19:47 +0300
+Subject: [PATCH 11/12] base: Set TARGET_FLATTEN_APEX to true
+
+Android-14 requires either TARGET_FLATTEN_APEX to be set to true or
+ro.apex.updatable sysprop set to true. Otherwise, init will enter a
+boot loop.
+
+Signed-off-by: Roman Stratiienko
+---
+ common/base/device.mk | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/common/base/device.mk b/common/base/device.mk
+index d0210bf..c086dfe 100644
+--- a/common/base/device.mk
++++ b/common/base/device.mk
+@@ -74,3 +74,5 @@ PRODUCT_PACKAGES += \
+ update_engine_client \
+ update_verifier \
+ update_engine_sideload \
++
++TARGET_FLATTEN_APEX := true
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/configuration/0012-other-hals-Upgrade-boot-control-HAL-to-AIDL.patch b/patches-aosp/glodroid/configuration/0012-other-hals-Upgrade-boot-control-HAL-to-AIDL.patch
new file mode 100644
index 0000000..94a6aac
--- /dev/null
+++ b/patches-aosp/glodroid/configuration/0012-other-hals-Upgrade-boot-control-HAL-to-AIDL.patch
@@ -0,0 +1,31 @@
+From 3d47f9824871fca0f8faba3b79f74a0e61f4e837 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Thu, 19 Oct 2023 03:23:37 +0300
+Subject: [PATCH 12/12] other-hals: Upgrade boot control HAL to AIDL
+
+Just an upgrade.
+
+Signed-off-by: Roman Stratiienko
+---
+ common/other-hals/device.mk | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/common/other-hals/device.mk b/common/other-hals/device.mk
+index 29ebba7..87c4735 100644
+--- a/common/other-hals/device.mk
++++ b/common/other-hals/device.mk
+@@ -24,9 +24,8 @@ endif
+
+ ifeq ($(GD_NO_DEFAULT_BOOTCTL),)
+ PRODUCT_PACKAGES += \
+- android.hardware.boot@1.2-impl \
+- android.hardware.boot@1.2-impl.recovery \
+- android.hardware.boot@1.2-service \
++ android.hardware.boot-service.default \
++ android.hardware.boot-service.default_recovery \
+
+ endif
+
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/kernel/broadcom/0001-Fix-clang17-errors.patch b/patches-aosp/glodroid/kernel/broadcom/0001-Fix-clang17-errors.patch
new file mode 100644
index 0000000..6410fc8
--- /dev/null
+++ b/patches-aosp/glodroid/kernel/broadcom/0001-Fix-clang17-errors.patch
@@ -0,0 +1,30 @@
+From 211afa3f4e09957540cdc2a837d8acc161d6c7e6 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 22:25:30 +0300
+Subject: [PATCH] Fix clang17 errors
+
+Clang17 does not like signed bitfields
+
+Signed-off-by: Roman Stratiienko
+---
+ drivers/staging/vc04_services/vc-sm-cma/vc_sm.h | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.h b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.h
+index f1c7b95b14ce..56fd8e9ad259 100644
+--- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.h
++++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.h
+@@ -57,8 +57,8 @@ struct vc_sm_buffer {
+
+ char name[VC_SM_MAX_NAME_LEN];
+
+- int in_use:1; /* Kernel is still using this resource */
+- int imported:1; /* Imported dmabuf */
++ unsigned int in_use:1; /* Kernel is still using this resource */
++ unsigned int imported:1; /* Imported dmabuf */
+
+ enum vc_sm_vpu_mapping_state vpu_state;
+ u32 vc_handle; /* VideoCore handle for this buffer */
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/vendor/aospext/0003-buildflags-Filter-out-deprecated-flag.patch b/patches-aosp/glodroid/vendor/aospext/0003-buildflags-Filter-out-deprecated-flag.patch
new file mode 100644
index 0000000..e3d4ebc
--- /dev/null
+++ b/patches-aosp/glodroid/vendor/aospext/0003-buildflags-Filter-out-deprecated-flag.patch
@@ -0,0 +1,30 @@
+From 7d5ac1e566c98b0fa17d7c74f5c6dfdb4a99b019 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 03:03:24 +0300
+Subject: [PATCH 3/4] buildflags: Filter-out deprecated flag
+
+Fixes:
+clang: warning: the flag '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' has been deprecated and will be ignored [-Wunused-command-line-argument]
+
+Signed-off-by: hmtheboy154
+Signed-off-by: Roman Stratiienko
+---
+ aospext_get_buildflags.mk | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/aospext_get_buildflags.mk b/aospext_get_buildflags.mk
+index d522e4c..fcfcae8 100644
+--- a/aospext_get_buildflags.mk
++++ b/aospext_get_buildflags.mk
+@@ -177,7 +177,7 @@ define m-c-flags
+ endef
+
+ define filter-c-flags
+- $(filter-out -fno-rtti,
++ $(filter-out -fno-rtti -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang,
+ $(patsubst -std=%,, \
+ $(patsubst -f%,, \
+ $(patsubst -W%,, $1))))
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/vendor/aospext/0004-mesa3d-Disable-libbacktrace.patch b/patches-aosp/glodroid/vendor/aospext/0004-mesa3d-Disable-libbacktrace.patch
new file mode 100644
index 0000000..beeb315
--- /dev/null
+++ b/patches-aosp/glodroid/vendor/aospext/0004-mesa3d-Disable-libbacktrace.patch
@@ -0,0 +1,38 @@
+From 3035f2cf7c837596d449785b6d91bd6bffc492c4 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 22:27:13 +0300
+Subject: [PATCH 4/4] mesa3d: Disable libbacktrace
+
+libbacktrace was removed from AOSP starting from v14.
+
+Signed-off-by: Roman Stratiienko
+---
+ meson_mesa3d.mk | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/meson_mesa3d.mk b/meson_mesa3d.mk
+index 040763c..dbaf98e 100644
+--- a/meson_mesa3d.mk
++++ b/meson_mesa3d.mk
+@@ -31,6 +31,7 @@ MESON_BUILD_ARGUMENTS := \
+ -Degl=enabled \
+ -Dcpp_rtti=false \
+ -Dlmsensors=disabled \
++ -Dandroid-libbacktrace=disabled \
+ $(BOARD_MESA3D_EXTRA_MESON_ARGS)
+
+ ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 30; echo $$?), 0)
+@@ -60,8 +61,8 @@ include $(CLEAR_VARS)
+
+ LOCAL_SHARED_LIBRARIES := libc libdl libdrm libm liblog libcutils libz libc++ libnativewindow libsync libhardware
+ LOCAL_STATIC_LIBRARIES := libexpat libarect libelf
+-LOCAL_HEADER_LIBRARIES := libnativebase_headers hwvulkan_headers libbacktrace_headers
+-MESON_GEN_PKGCONFIGS := backtrace cutils expat hardware libdrm:$(LIBDRM_VERSION) nativewindow sync zlib:1.2.11 libelf
++LOCAL_HEADER_LIBRARIES := libnativebase_headers hwvulkan_headers
++MESON_GEN_PKGCONFIGS := cutils expat hardware libdrm:$(LIBDRM_VERSION) nativewindow sync zlib:1.2.11 libelf
+ LOCAL_CFLAGS += $(BOARD_MESA3D_CFLAGS)
+
+ ifneq ($(filter swrast,$(BOARD_MESA3D_GALLIUM_DRIVERS) $(BOARD_MESA3D_VULKAN_DRIVERS)),)
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/vendor/mesa3d/0001-dri-Remove-__driDriverExtensions-leftovers.patch b/patches-aosp/glodroid/vendor/mesa3d/0001-dri-Remove-__driDriverExtensions-leftovers.patch
new file mode 100644
index 0000000..6629c03
--- /dev/null
+++ b/patches-aosp/glodroid/vendor/mesa3d/0001-dri-Remove-__driDriverExtensions-leftovers.patch
@@ -0,0 +1,65 @@
+From 07465de19df27aff89d89a2b77ff04597e2ed58c Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 12:31:29 +0300
+Subject: [PATCH 1/2] dri: Remove __driDriverExtensions leftovers
+
+Android-14/clang-17 throws an error with it:
+
+ld.lld: error: version script assignment of 'global' to symbol
+ '__driDriverExtensions' failed: symbol not defined
+
+Fixes: d43e6a9a497f ("dri: Remove the megadriver compat stub")
+Signed-off-by: Roman Stratiienko
+Acked-by: Erik Faye-Lund
+---
+ include/GL/internal/dri_interface.h | 8 --------
+ src/gallium/targets/dri/dri.sym | 1 -
+ src/loader/loader.c | 2 --
+ 3 files changed, 11 deletions(-)
+
+diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
+index a59d598c3bf..1424e24fe27 100644
+--- a/include/GL/internal/dri_interface.h
++++ b/include/GL/internal/dri_interface.h
+@@ -678,14 +678,6 @@ struct __DRIuseInvalidateExtensionRec {
+ __DRIextension base;
+ };
+
+-/**
+- * The remaining extensions describe driver extensions, immediately
+- * available interfaces provided by the driver. To start using the
+- * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for
+- * the extension you need in the array.
+- */
+-#define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
+-
+ /**
+ * This symbol replaces the __DRI_DRIVER_EXTENSIONS symbol, and will be
+ * suffixed by "_drivername", allowing multiple drivers to be built into one
+diff --git a/src/gallium/targets/dri/dri.sym b/src/gallium/targets/dri/dri.sym
+index d4ffb588e05..6f502fa9f92 100644
+--- a/src/gallium/targets/dri/dri.sym
++++ b/src/gallium/targets/dri/dri.sym
+@@ -1,6 +1,5 @@
+ {
+ global:
+- __driDriverExtensions;
+ __driDriverGetExtensions*;
+ nouveau_drm_screen_create;
+ radeon_drm_winsys_create;
+diff --git a/src/loader/loader.c b/src/loader/loader.c
+index a00f16f0e99..f340b61433d 100644
+--- a/src/loader/loader.c
++++ b/src/loader/loader.c
+@@ -836,8 +836,6 @@ loader_open_driver(const char *driver_name,
+ free(get_extensions_name);
+ }
+
+- if (!extensions)
+- extensions = dlsym(driver, __DRI_DRIVER_EXTENSIONS);
+ if (extensions == NULL) {
+ log_(_LOADER_WARNING,
+ "MESA-LOADER: driver exports no extensions (%s)\n", dlerror());
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/vendor/mesa3d/0002-HACK-Use-mask-in-dri.sym.patch b/patches-aosp/glodroid/vendor/mesa3d/0002-HACK-Use-mask-in-dri.sym.patch
new file mode 100644
index 0000000..63701fc
--- /dev/null
+++ b/patches-aosp/glodroid/vendor/mesa3d/0002-HACK-Use-mask-in-dri.sym.patch
@@ -0,0 +1,36 @@
+From 6853cd7d7fedc665fcce95c01a939408ced9b708 Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 23:15:17 +0300
+Subject: [PATCH 2/2] HACK: Use mask in dri.sym
+
+... otherwise LLD-17 will fail to link be because of missing symbols.
+
+Signed-off-by: Roman Stratiienko
+---
+ src/gallium/targets/dri/dri.sym | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/src/gallium/targets/dri/dri.sym b/src/gallium/targets/dri/dri.sym
+index 6f502fa9f92..3080b0c979b 100644
+--- a/src/gallium/targets/dri/dri.sym
++++ b/src/gallium/targets/dri/dri.sym
+@@ -1,11 +1,11 @@
+ {
+ global:
+ __driDriverGetExtensions*;
+- nouveau_drm_screen_create;
+- radeon_drm_winsys_create;
+- amdgpu_winsys_create;
+- fd_drm_screen_create_renderonly;
+- ac_init_shared_llvm_once;
++ nouveau_drm_screen_create*;
++ radeon_drm_winsys_create*;
++ amdgpu_winsys_create*;
++ fd_drm_screen_create_renderonly*;
++ ac_init_shared_llvm_once*;
+ local:
+ *;
+ };
+--
+2.39.2
+
diff --git a/patches-aosp/glodroid/vendor/mesa3d/0003-isaspec-Remove-symlink-that-points-to-missing-file.patch b/patches-aosp/glodroid/vendor/mesa3d/0003-isaspec-Remove-symlink-that-points-to-missing-file.patch
new file mode 100644
index 0000000..65126e9
--- /dev/null
+++ b/patches-aosp/glodroid/vendor/mesa3d/0003-isaspec-Remove-symlink-that-points-to-missing-file.patch
@@ -0,0 +1,25 @@
+From e0f951f79edd93d0c4fb27686970fe322fa3d50a Mon Sep 17 00:00:00 2001
+From: Roman Stratiienko
+Date: Fri, 6 Oct 2023 23:36:21 +0300
+Subject: [PATCH 3/3] isaspec: Remove symlink that points to missing file
+
+AOSP does not like such symlinks.
+
+Change-Id: I737f16fd64c79ff2bde4eb1f8d592fb66bca66dc
+Signed-off-by: Roman Stratiienko
+---
+ src/compiler/isaspec/README.rst | 1 -
+ 1 file changed, 1 deletion(-)
+ delete mode 120000 src/compiler/isaspec/README.rst
+
+diff --git a/src/compiler/isaspec/README.rst b/src/compiler/isaspec/README.rst
+deleted file mode 120000
+index 27379790c02..00000000000
+--- a/src/compiler/isaspec/README.rst
++++ /dev/null
+@@ -1 +0,0 @@
+-../../../docs/drivers/freedreno/isaspec.rst
+\ No newline at end of file
+--
+2.39.2
+
diff --git a/unfold_aosp.sh b/unfold_aosp.sh
index 8eedce3..cb088a1 100755
--- a/unfold_aosp.sh
+++ b/unfold_aosp.sh
@@ -4,7 +4,7 @@ LOCAL_PATH=$(pwd)
echo Init repo tree using AOSP manifest
pushd aosptree
-repo init -u https://android.googlesource.com/platform/manifest -b refs/tags/android-platform-13.0.0_r12
+repo init -u https://android.googlesource.com/platform/manifest -b refs/tags/android-14.0.0_r11
cd .repo/manifests
mv default.xml aosp.xml
cp ${LOCAL_PATH}/manifests/glodroid.xml glodroid.xml
diff --git a/unfold_lineageos.sh b/unfold_lineageos.sh
index 28f6d16..d6048f6 100755
--- a/unfold_lineageos.sh
+++ b/unfold_lineageos.sh
@@ -1,5 +1,9 @@
#!/bin/bash -ex
+echo "LineageOS-21 is not supported yet"
+
+exit 1
+
LOCAL_PATH=$(pwd)
echo Init repo tree using AOSP manifest