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 c9d37f1a16dee8442cf8b2c31452988c04759143
Author: wangshaoxin <[email protected]>
AuthorDate: Mon Apr 20 09:51:54 2026 +0800

    drivers/rptun: add the peer's coredump regions to the coredump list
    
    The master side had no way to include the memory of a remote core in
    its own coredump.
    
    After remoteproc_start() succeeds, look for RSC_CARVEOUT entries in the
    resource table whose name starts with "coredump", map them and add them
    with coredump_add_memory_region(); remove them again when the remote
    core is stopped. Only the master side does this, with CONFIG_COREDUMP.
    
    Signed-off-by: wangshaoxin <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/rptun.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index 3db73daf5d9..630e29d29de 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -30,11 +30,13 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <string.h>
 #include <sys/boardctl.h>
 #include <sys/param.h>
 #include <sys/wait.h>
 
 #include <nuttx/clock.h>
+#include <nuttx/coredump.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/kthread.h>
 #include <nuttx/mm/mm.h>
@@ -999,6 +1001,61 @@ static int rptun_callback(FAR void *arg, uint32_t vqid)
   return remoteproc_get_notification(&priv->rproc, vqid);
 }
 
+/****************************************************************************
+ * Name: rptun_update_coredump_regions
+ *
+ * Description:
+ *   Scan RSC_CARVEOUT entries with name prefix "coredump" and register
+ *   or unregister them from the system coredump list.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_COREDUMP
+static void rptun_update_coredump_regions(FAR struct rptun_priv_s *priv,
+                                          bool add)
+{
+  FAR char *rsc = priv->rproc.rsc_table;
+  FAR struct fw_rsc_carveout *carv;
+  size_t off;
+  uint32_t i;
+
+  if (!RPTUN_IS_MASTER(priv->dev) || rsc == NULL)
+    {
+      return;
+    }
+
+  for (i = 0; ; i++)
+    {
+      off = find_rsc(rsc, RSC_CARVEOUT, i);
+      if (off == 0u)
+        {
+          break;
+        }
+
+      carv = (FAR struct fw_rsc_carveout *)(rsc + off);
+      if (strncmp((FAR const char *)carv->name, "coredump", 8) == 0)
+        {
+          metal_phys_addr_t da = carv->da;
+          FAR void *va;
+
+          va = remoteproc_mmap(&priv->rproc, NULL, &da,
+                               carv->len, 0, NULL);
+          if (va != NULL)
+            {
+              if (add)
+                {
+                  coredump_add_memory_region(va, carv->len, carv->flags);
+                }
+              else
+                {
+                  coredump_remove_memory_region(va, carv->len);
+                }
+            }
+        }
+    }
+}
+#endif
+
 static int rptun_do_start(FAR struct remoteproc *rproc)
 {
   FAR struct rptun_priv_s *priv = rproc->priv;
@@ -1067,6 +1124,14 @@ static int rptun_do_start(FAR struct remoteproc *rproc)
                                                    trace->len, 0, NULL);
                 }
 
+#ifdef CONFIG_COREDUMP
+              /* Register dump regions after remote core is started,
+               * at which point the memory layout is determined.
+               */
+
+              rptun_update_coredump_regions(priv, true);
+#endif
+
               /* Register callback to mbox for receiving remote message */
 
               RPTUN_REGISTER_CALLBACK(priv->dev, rptun_callback, priv);
@@ -1168,6 +1233,9 @@ static int rptun_dev_stop(FAR struct remoteproc *rproc)
 
       RPTUN_UNREGISTER_CALLBACK(priv->dev);
       rptun_remove_devices(priv);
+#ifdef CONFIG_COREDUMP
+      rptun_update_coredump_regions(priv, false);
+#endif
       remoteproc_shutdown(rproc);
     }
 

Reply via email to