From 09211991dc06b24ef17a9a81b521c5d8182b5a70 Mon Sep 17 00:00:00 2001
From: Ayush Singh <ayushdevel1325@gmail.com>
Date: Mon, 19 Feb 2024 00:39:12 +0530
Subject: [PATCH 1/3] Allow building using upstream Zephyr

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
---
 include/greybus/greybus.h                     |  1 -
 .../greybus/net/overlay-802154-subg.conf      |  2 +-
 samples/subsys/greybus/net/prj.conf           | 18 +++++++----
 subsys/greybus/CMakeLists.txt                 |  2 +-
 subsys/greybus/Kconfig                        |  2 --
 subsys/greybus/greybus-core.c                 | 30 +------------------
 6 files changed, 15 insertions(+), 40 deletions(-)

diff --git a/include/greybus/greybus.h b/include/greybus/greybus.h
index 8f43ee5..0e26b2f 100644
--- a/include/greybus/greybus.h
+++ b/include/greybus/greybus.h
@@ -152,7 +152,6 @@ struct gb_driver {
 
 	struct gb_operation_handler *op_handlers;
 
-	size_t stack_size;
 	size_t op_handlers_count;
 	const char *name;
 
diff --git a/samples/subsys/greybus/net/overlay-802154-subg.conf b/samples/subsys/greybus/net/overlay-802154-subg.conf
index 704016c..2aa220b 100644
--- a/samples/subsys/greybus/net/overlay-802154-subg.conf
+++ b/samples/subsys/greybus/net/overlay-802154-subg.conf
@@ -16,4 +16,4 @@ CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y
 CONFIG_IEEE802154_CC13XX_CC26XX=n
 CONFIG_NET_CONFIG_IEEE802154_CHANNEL=1
 CONFIG_IEEE802154_CC13XX_CC26XX_SUB_GHZ=y
-CONFIG_IEEE802154_CC13XX_CC26XX_SUB_GHZ_NUM_RX_BUF=6
+CONFIG_IEEE802154_CC13XX_CC26XX_SUB_GHZ_NUM_RX_BUF=8
diff --git a/samples/subsys/greybus/net/prj.conf b/samples/subsys/greybus/net/prj.conf
index df5f08f..e301386 100644
--- a/samples/subsys/greybus/net/prj.conf
+++ b/samples/subsys/greybus/net/prj.conf
@@ -6,8 +6,9 @@ CONFIG_GREYBUS=y
 CONFIG_GREYBUS_CONTROL=y
 CONFIG_POSIX_CLOCK=y
 CONFIG_PTHREAD_IPC=y
-CONFIG_PTHREAD_DYNAMIC_STACK=y
-CONFIG_PTHREAD_DYNAMIC_STACK_DEFAULT_SIZE=2048
+CONFIG_DYNAMIC_THREAD=y
+CONFIG_DYNAMIC_THREAD_STACK_SIZE=1536
+CONFIG_DYNAMIC_THREAD_ALLOC=y
 CONFIG_THREAD_NAME=y
 
 # Console options
@@ -44,10 +45,10 @@ CONFIG_NET_STATISTICS=y
 CONFIG_PRINTK=y
 
 # Network buffers
-CONFIG_NET_PKT_RX_COUNT=16
-CONFIG_NET_PKT_TX_COUNT=16
-CONFIG_NET_BUF_RX_COUNT=16
-CONFIG_NET_BUF_TX_COUNT=16
+CONFIG_NET_PKT_RX_COUNT=64
+CONFIG_NET_PKT_TX_COUNT=32
+CONFIG_NET_BUF_RX_COUNT=64
+CONFIG_NET_BUF_TX_COUNT=32
 CONFIG_NET_CONTEXT_NET_PKT_POOL=y
 
 # IP address options
@@ -68,3 +69,8 @@ CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
 
 # Pthread options
 CONFIG_MAX_PTHREAD_COUNT=16
+
+CONFIG_GREYBUS_LOG_LEVEL_DBG=y
+CONFIG_POSIX_SEMAPHORES=y
+
+CONFIG_NET_L2_IEEE802154_RADIO_ALOHA=y
diff --git a/subsys/greybus/CMakeLists.txt b/subsys/greybus/CMakeLists.txt
index ad01d4f..8d78cbd 100644
--- a/subsys/greybus/CMakeLists.txt
+++ b/subsys/greybus/CMakeLists.txt
@@ -23,7 +23,7 @@ zephyr_library_sources(
 if(CONFIG_GREYBUS_MANIFEST_BUILTIN)
 
   devicetree_unfixed_h_to_mnfs(
-    ${PROJECT_BINARY_DIR}/include/generated/devicetree_generated.h
+    ${PROJECT_BINARY_DIR}/include/generated/zephyr/devicetree_generated.h
     ${PROJECT_BINARY_DIR}/include/generated/greybus.mnfs)
 
   mnfs_to_mnfb(${PROJECT_BINARY_DIR}/include/generated/greybus.mnfs
diff --git a/subsys/greybus/Kconfig b/subsys/greybus/Kconfig
index e1471c8..650fe11 100644
--- a/subsys/greybus/Kconfig
+++ b/subsys/greybus/Kconfig
@@ -6,8 +6,6 @@
 
 menuconfig GREYBUS
 	bool "Greybus"
-	depends on PTHREAD_DYNAMIC_STACK
-	depends on PTHREAD_IPC
 	help
 	  This option enables Greybus support.
 
diff --git a/subsys/greybus/greybus-core.c b/subsys/greybus/greybus-core.c
index 08ecbc8..e048fdd 100644
--- a/subsys/greybus/greybus-core.c
+++ b/subsys/greybus/greybus-core.c
@@ -55,8 +55,6 @@ extern int pthread_setname_np(pthread_t thread, const char *name);
 #include <zephyr/posix/pthread.h>
 #include <zephyr/posix/semaphore.h>
 
-#define DEFAULT_STACK_SIZE CONFIG_PTHREAD_DYNAMIC_STACK_DEFAULT_SIZE
-
 #endif
 
 #include <stdio.h>
@@ -553,8 +551,6 @@ int gb_unregister_driver(unsigned int cport)
 
 int _gb_register_driver(unsigned int cport, int bundle_id, struct gb_driver *driver)
 {
-	pthread_attr_t thread_attr;
-	pthread_attr_t *thread_attr_ptr = &thread_attr;
 	struct gb_bundle *bundle;
 	char thread_name[CONFIG_THREAD_MAX_NAME_LEN];
 	int retval;
@@ -629,23 +625,7 @@ int _gb_register_driver(unsigned int cport, int bundle_id, struct gb_driver *dri
 
 	g_cport[cport].exit_worker = false;
 
-	if (!driver->stack_size) {
-		driver->stack_size = DEFAULT_STACK_SIZE;
-	}
-
-	retval = pthread_attr_init(&thread_attr);
-	if (retval) {
-		LOG_ERR("pthread_attr_init() failed (%d)", retval);
-		goto pthread_attr_init_error;
-	}
-
-	retval = pthread_attr_setstacksize(&thread_attr, driver->stack_size);
-	if (retval) {
-		LOG_ERR("pthread_attr_setstacksize() failed (%d)", retval);
-		goto pthread_attr_setstacksize_error;
-	}
-
-	retval = pthread_create(&g_cport[cport].thread, &thread_attr, gb_pending_message_worker,
+	retval = pthread_create(&g_cport[cport].thread, NULL, gb_pending_message_worker,
 				(void *)((intptr_t)cport));
 	if (retval) {
 		LOG_ERR("pthread_create() failed (%d)", retval);
@@ -655,19 +635,11 @@ int _gb_register_driver(unsigned int cport, int bundle_id, struct gb_driver *dri
 	snprintf(thread_name, sizeof(thread_name), "greybus[%u]", cport);
 	pthread_setname_np(g_cport[cport].thread, thread_name);
 
-	pthread_attr_destroy(&thread_attr);
-	thread_attr_ptr = NULL;
-
 	g_cport[cport].driver = driver;
 
 	return 0;
 
 pthread_create_error:
-pthread_attr_setstacksize_error:
-	if (thread_attr_ptr != NULL) {
-		pthread_attr_destroy(&thread_attr);
-	}
-pthread_attr_init_error:
 	LOG_ERR("Can not create thread for %s", gb_driver_name(driver));
 	if (driver->exit) {
 		driver->exit(cport, bundle);
-- 
GitLab


From ee0990f28cd06eea1155d2e9fb4a81d64329bd85 Mon Sep 17 00:00:00 2001
From: Ayush Singh <ayush@beagleboard.org>
Date: Fri, 5 Jul 2024 21:44:36 +0530
Subject: [PATCH 2/3] Add west manifest

- Allows building as a freestanding Zephyr application

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
 west.yml | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/west.yml b/west.yml
index 120de2c..df1b084 100644
--- a/west.yml
+++ b/west.yml
@@ -1,13 +1,19 @@
+# Copyright (c) 2024 Ayush Singh <ayush@beagleboard.org>
+# SPDX-License-Identifier: Apache-2.0
+
 manifest:
   self:
-    path: greybus
+    west-commands: scripts/west-commands.yml
+
   remotes:
-    - name: zephyrproject-rtos
-      url-base: https://github.com/zephyrproject-rtos
-    - name: beagle-sdk
-      url-base: https://openbeagle.org/beagleconnect/zephyr
+    - name: ayush
+      url-base: https://openbeagle.org/ayush1325
+
   projects:
     - name: zephyr
-      remote: beagle-sdk
-      revision: demo
-      import: true
+      remote: ayush
+      revision: bct-2
+      import:
+        name-allowlist:
+          - hal_ti
+          - cmsis
-- 
GitLab


From f48472e9989b9f448a71da155bc51fb10c260e51 Mon Sep 17 00:00:00 2001
From: Ayush Singh <ayushdevel1325@gmail.com>
Date: Mon, 19 Feb 2024 00:47:49 +0530
Subject: [PATCH 3/3] Switch CI to use upstream Zephyr

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
 .gitlab-ci.yml | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b35fea7..5000351 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,21 +1,18 @@
-image: zephyrprojectrtos/zephyr-build:v0.24.7
-
-variables:
-  ZEPHYR_BASE: /builds/beagleconnect/zephyr/greybus-for-zephyr/zephyr
-  PROJECT: greybus
-  APP: samples/subsys/greybus/net
+image: zephyrprojectrtos/zephyr-build:v0.26.13
 
 build:
   stage: build
+  variables:
+    GIT_SUBMODULE_STRATEGY: recursive
   before_script:
+    - rm -rf ../.west
     - west init -l .
     - west update
     - west zephyr-export
-    - pip3 install -r $ZEPHYR_BASE/scripts/requirements-base.txt
+    - pip3 install -r ../zephyr/scripts/requirements-base.txt
   script:
-    - west build -d buildx/freedom/$PROJECT -b beagleconnect_freedom $APP -- -DOVERLAY_CONFIG="overlay-802154-subg.conf"
-    - mkdir -p build/freedom/$PROJECT/zephyr
-    - cp buildx/freedom/$PROJECT/zephyr/zephyr.bin build/freedom/$PROJECT/zephyr/zephyr.bin
+    - source ../zephyr/zephyr-env.sh
+    - west build -b beagleconnect_freedom samples/subsys/greybus/net/ -p -- -DEXTRA_CONF_FILE=overlay-802154-subg.conf
   artifacts:
     paths:
-      - build
+      - build/zephyr/zephyr.bin
-- 
GitLab