This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 081b7f40910b29228012ab366427bc6d61f1375c
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Nov 24 13:43:43 2026 +0800

    openamp: let a service attach extra data to its ns announcement
    
    Add a patch with ns_get_extra_cb on the endpoint: a service can append
    up to RPMSG_NS_EXTRA_SIZE (88) bytes to its name service announcement,
    so that it does not need a separate sync message after the binding. An
    announcement without extra data is unchanged. The patch includes
    metal/sys.h in rpmsg.c for RPMSG_ASSERT() with CONFIG_OPENAMP_DEBUG.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 ...-service-attach-extra-data-to-its-ns-anno.patch | 171 +++++++++++++++++++++
 openamp/open-amp.cmake                             |   2 +
 openamp/open-amp.defs                              |   1 +
 3 files changed, 174 insertions(+)

diff --git 
a/openamp/0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch 
b/openamp/0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch
new file mode 100644
index 00000000000..7d92fa81584
--- /dev/null
+++ b/openamp/0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch
@@ -0,0 +1,171 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Bowen Wang <[email protected]>
+Date: Fri, 4 Sep 2026 22:21:17 +0800
+Subject: [PATCH] rpmsg: let a service attach extra data to its ns announcement
+
+A name service announcement only carries the service name and address,
+so a service that needs more to set up a connection has to send its own
+sync message after the binding, and handle the half set up connection
+in between.
+
+Let the announcement carry the data instead. A service sets
+ns_get_extra_cb on its endpoint and fills in up to RPMSG_NS_EXTRA_SIZE
+bytes; the announcement is then sent with exactly those bytes after it:
+
+    0            32       36       40         40 + extra_len
+    +------------+--------+--------+----------+
+    | name[32]   | addr   | flags  | extra    |
+    +------------+--------+--------+----------+
+
+struct rpmsg_ns_msg keeps its size, so an announcement without extra
+data is the same as before. A destroy announcement never carries extra
+data.
+
+rpmsg.c now uses RPMSG_ASSERT(), which with RPMSG_DEBUG calls
+metal_log() and needs _metal from metal/sys.h, so include it.
+
+Signed-off-by: Bowen Wang <[email protected]>
+---
+ lib/include/openamp/rpmsg.h | 16 ++++++++++++++++
+ lib/rpmsg/rpmsg.c           | 21 +++++++++++++++++---
+ lib/rpmsg/rpmsg_internal.h  | 38 +++++++++++++++++++++++++++++++++++++
+ 3 files changed, 72 insertions(+), 3 deletions(-)
+
+diff --git a/lib/include/openamp/rpmsg.h open-amp/lib/include/openamp/rpmsg.h
+index 7fc72a2..654185b 100644
+--- a/lib/include/openamp/rpmsg.h
++++ open-amp/lib/include/openamp/rpmsg.h
+@@ -72,6 +72,16 @@ typedef void (*rpmsg_ns_unbind_cb)(struct rpmsg_endpoint 
*ept);
+ typedef void (*rpmsg_ns_bind_cb)(struct rpmsg_device *rdev,
+                                const char *name, uint32_t dest);
+ 
++/*
++ * Called when building a name service announcement, to let the service
++ * provide the extra data carried along with it.
++ *
++ * The service writes at most RPMSG_NS_EXTRA_SIZE bytes into extra and
++ * returns how many it wrote.
++ */
++typedef size_t (*rpmsg_ns_get_extra_cb)(struct rpmsg_endpoint *ept,
++                                      void *extra);
++
+ /**
+  * @brief Structure that binds a local RPMsg address to its user
+  *
+@@ -106,6 +116,12 @@ struct rpmsg_endpoint {
+       /** Endpoint service bound callback, called when remote ept address is 
received */
+       rpmsg_ns_bound_cb ns_bound_cb;
+ 
++      /**
++       * Called when building a name service announcement for this endpoint,
++       * to let the service provide its extra data
++       */
++      rpmsg_ns_get_extra_cb ns_get_extra_cb;
++
+       /** Endpoint service unbind callback, called when remote ept is 
destroyed */
+       rpmsg_ns_unbind_cb ns_unbind_cb;
+ 
+diff --git a/lib/rpmsg/rpmsg.c open-amp/lib/rpmsg/rpmsg.c
+index 76521fd..a302191 100644
+--- a/lib/rpmsg/rpmsg.c
++++ open-amp/lib/rpmsg/rpmsg.c
+@@ -11,6 +11,7 @@
+ #include <openamp/rpmsg.h>
+ #include <metal/alloc.h>
+ #include <metal/atomic.h>
++#include <metal/sys.h>
+ 
+ #include "rpmsg_internal.h"
+ 
+@@ -133,15 +134,29 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint 
*ept, uint32_t src,
+ 
+ int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags)
+ {
+-      struct rpmsg_ns_msg ns_msg;
++      struct rpmsg_ns_msg_max ns_msg;
++      size_t len = sizeof(struct rpmsg_ns_msg);
++      size_t extra_len;
+       int ret;
+ 
+       ns_msg.flags = flags;
+       ns_msg.addr = ept->addr;
+       (void)safe_strcpy(ns_msg.name, sizeof(ns_msg.name), ept->name, 
sizeof(ept->name));
++
++      /*
++       * A destroy announcement carries no extra data: the service is going
++       * away, and this path may run with no endpoint left to ask.
++       */
++      if (ept->ns_get_extra_cb && flags != RPMSG_NS_DESTROY) {
++              extra_len = ept->ns_get_extra_cb(ept, ns_msg.extra);
++              RPMSG_ASSERT(extra_len <= RPMSG_NS_EXTRA_SIZE,
++                           "extra data exceeds the announcement\r\n");
++
++              len += extra_len;
++      }
++
+       ret = rpmsg_send_offchannel_raw(ept, ept->addr,
+-                                      RPMSG_NS_EPT_ADDR,
+-                                      &ns_msg, sizeof(ns_msg), true);
++                                      RPMSG_NS_EPT_ADDR, &ns_msg, len, true);
+       if (ret < 0)
+               return ret;
+       else
+diff --git a/lib/rpmsg/rpmsg_internal.h open-amp/lib/rpmsg/rpmsg_internal.h
+index 854e8a3..173c44e 100644
+--- a/lib/rpmsg/rpmsg_internal.h
++++ open-amp/lib/rpmsg/rpmsg_internal.h
+@@ -67,6 +67,12 @@ enum rpmsg_ns_flags {
+       RPMSG_NS_CREATE_ACK = 2,
+ };
+ 
++/*
++ * Maximum size of the service defined extra data in an announcement, chosen
++ * so that a full announcement is exactly 128 bytes.
++ */
++#define RPMSG_NS_EXTRA_SIZE (88)
++
+ /**
+  * @brief Common header for all RPMsg messages
+  *
+@@ -109,6 +115,38 @@ struct rpmsg_ns_msg {
+ 
+       /** Indicates whether service is created or destroyed */
+       uint32_t flags;
++
++      /**
++       * Service defined data, running to the end of the message
++       *
++       * Its length is what the message carries beyond
++       * sizeof(struct rpmsg_ns_msg), so a message without extra data is
++       * exactly that long. The data is opaque here, the two sides of a
++       * service agree on it between themselves.
++       */
++      uint8_t extra[];
++} METAL_PACKED_END;
++
++/**
++ * @brief Announcement sized to hold the largest extra data accepted
++ *
++ * Same layout as struct rpmsg_ns_msg, with the extra data spelled out so that
++ * an announcement can be built and received without allocating. Only the
++ * bytes actually in use are sent.
++ */
++METAL_PACKED_BEGIN
++struct rpmsg_ns_msg_max {
++      /** Name of the remote service that is being published */
++      char name[RPMSG_NAME_SIZE];
++
++      /** Endpoint address of the remote service that is being published */
++      uint32_t addr;
++
++      /** Indicates whether service is created or destroyed */
++      uint32_t flags;
++
++      /** Service defined data */
++      uint8_t extra[RPMSG_NS_EXTRA_SIZE];
+ } METAL_PACKED_END;
+ 
+ int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags);
+-- 
+2.34.1
+
diff --git a/openamp/open-amp.cmake b/openamp/open-amp.cmake
index 388ae2b57bf..512af5956c5 100644
--- a/openamp/open-amp.cmake
+++ b/openamp/open-amp.cmake
@@ -98,6 +98,8 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/open-amp)
       
${CMAKE_CURRENT_LIST_DIR}/0029-rpmsg-let-a-reference-outlive-the-endpoint-s-registr.patch
       && patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
       
${CMAKE_CURRENT_LIST_DIR}/0030-rpmsg-export-rpmsg_unregister_endpoint.patch
+      && patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
+      
${CMAKE_CURRENT_LIST_DIR}/0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch
     DOWNLOAD_NO_PROGRESS true
     TIMEOUT 30)
 
diff --git a/openamp/open-amp.defs b/openamp/open-amp.defs
index 0a184a409a7..64b566f0496 100644
--- a/openamp/open-amp.defs
+++ b/openamp/open-amp.defs
@@ -97,6 +97,7 @@ open-amp.zip:
        $(Q) patch -p0 < 
0028-rpmsg-take-the-ns-endpoint-reference-just-once.patch
        $(Q) patch -p0 < 
0029-rpmsg-let-a-reference-outlive-the-endpoint-s-registr.patch
        $(Q) patch -p0 < 0030-rpmsg-export-rpmsg_unregister_endpoint.patch
+       $(Q) patch -p0 < 
0031-rpmsg-let-a-service-attach-extra-data-to-its-ns-anno.patch
 
 .openamp_headers: open-amp.zip
 else

Reply via email to