From b0fa72f4953ecdd75f07d8fbf50a417fe1ce9d7d Mon Sep 17 00:00:00 2001
From: Nick Saulnier <nsaulnier@ti.com>
Date: Tue, 14 Feb 2023 18:33:36 -0600
Subject: [PATCH 2/3] Add an empty resource table

The resource table is not actually empty. However, we call it "empty"
because the resource table is not actually used for anything by the
remote core firmware.

Define a resource table based on the resource table generated in the Linux
RPMsg examples, in the generated files ti_drivers_config.c and ti_dlp_config.c.

Include the resource table file in main.c

Other notes:

The resource table is unused by modules within the example, so the compiler
would normally delete the resource table during code optimization. Thus, the
resource table must be marked with __attribute__((used)) to force the compiler
to keep the resource table in the generated binary file.

This resource table is a work in progress, and may be modified before being
added to official TI documentation.

Signed-off-by: Nick Saulnier <nsaulnier@ti.com>
---
 .../am64x-sk/r5fss0-0_freertos/main.c         |   3 +
 .../r5fss0-0_freertos/resource_table_no_ipc.h | 101 ++++++++++++++++++
 2 files changed, 104 insertions(+)
 create mode 100644 examples/hello_world/am64x-sk/r5fss0-0_freertos/resource_table_no_ipc.h

diff --git a/examples/hello_world/am64x-sk/r5fss0-0_freertos/main.c b/examples/hello_world/am64x-sk/r5fss0-0_freertos/main.c
index 62536675a712..158f398f8782 100644
--- a/examples/hello_world/am64x-sk/r5fss0-0_freertos/main.c
+++ b/examples/hello_world/am64x-sk/r5fss0-0_freertos/main.c
@@ -37,6 +37,9 @@
 #include "FreeRTOS.h"
 #include "task.h"
 
+/* add a resource table to the project so it can be loaded by Linux RemoteProc driver*/
+#include "resource_table_no_ipc.h"
+
 #define MAIN_TASK_PRI  (configMAX_PRIORITIES-1)
 
 #define MAIN_TASK_SIZE (16384U/sizeof(configSTACK_DEPTH_TYPE))
diff --git a/examples/hello_world/am64x-sk/r5fss0-0_freertos/resource_table_no_ipc.h b/examples/hello_world/am64x-sk/r5fss0-0_freertos/resource_table_no_ipc.h
new file mode 100644
index 000000000000..2ef85f0c8a14
--- /dev/null
+++ b/examples/hello_world/am64x-sk/r5fss0-0_freertos/resource_table_no_ipc.h
@@ -0,0 +1,101 @@
+/*
+ *  Copyright (C) 2022-2023 Texas Instruments Incorporated
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RESOURCE_TABLE_NO_IPC_H_
+#define RESOURCE_TABLE_NO_IPC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <drivers/ipc_rpmsg/include/ipc_rpmsg_linux_resource_table.h>
+#include <stdint.h>
+#include <kernel/dpl/SystemP.h>
+#include <drivers/hw_include/cslr_soc.h>
+
+/*
+ * NOTES
+ *
+ * - RPMessage_ResourceTable copied from Linux IPC example generated file
+ *   ti_drivers_config.c
+ *
+ * - gDebugMemLog is defined in the generated file ti_dlp_config.c, so mark as
+ *   "extern" in this file
+ *
+ * - The trace log takes 0x1000 (4096 bytes) of space in .bss by default. The
+ *   log is viewable from the Linux terminal with the command
+ *   # cat /sys/kernel/debug/remoteproc/remoteproc#/trace0
+ */
+
+
+/* DebugP log buffer memory and size
+ * - This log can be viewed via ROV in CCS
+ * - When linux is enabled, this log can also be viewed via linux debugfs
+ */
+extern char gDebugMemLog[DebugP_MEM_LOG_SIZE];
+
+/* __attribute__((used)) keeps the resource table from getting optimized out
+ * by the compiler
+ */
+const RPMessage_ResourceTable gRPMessage_linuxResourceTable __attribute__((used)) __attribute__ ((section (".resource_table"), aligned (4096))) =
+{
+    {
+        1U,         /* we're the first version that implements this */
+        2U,         /* number of entries, MUST be 2 */
+        { 0U, 0U, } /* reserved, must be zero */
+    },
+    /* offsets to the entries */
+    {
+        offsetof(RPMessage_ResourceTable, vdev),
+        offsetof(RPMessage_ResourceTable, trace),
+    },
+    /* vdev entry */
+    {
+        RPMESSAGE_RSC_TYPE_VDEV, RPMESSAGE_RSC_VIRTIO_ID_RPMSG,
+        0U, 1U, 0U, 0U, 0U, 2U, { 0U, 0U },
+    },
+    /* the two vrings */
+    { RPMESSAGE_RSC_VRING_ADDR_ANY, 4096U, 256U, 1U, 0U },
+    { RPMESSAGE_RSC_VRING_ADDR_ANY, 4096U, 256U, 2U, 0U },
+    {
+        (RPMESSAGE_RSC_TRACE_INTS_VER0 | RPMESSAGE_RSC_TYPE_TRACE),
+        (uint32_t)gDebugMemLog, DebugP_MEM_LOG_SIZE,
+        0, "trace:r5fss0_0",
+    },
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RESOURCE_TABLE_NO_IPC_H_ */
-- 
2.17.1

