diff --git a/doc/build/dts/api/api.rst b/doc/build/dts/api/api.rst index b5f04fe99c3f1..653bc0835844d 100644 --- a/doc/build/dts/api/api.rst +++ b/doc/build/dts/api/api.rst @@ -421,6 +421,9 @@ device. - Used by the OpenThread to specify UART device for Spinel protocol * - zephyr,pcie-controller - The node corresponding to the PCIe Controller + * - zephyr,rsc_table + - The resource table is copied to the "reserved memory" area specified + by the ``zephyr,rsc_table`` node * - zephyr,settings-partition - Fixed partition node. If defined this selects the partition used by the NVS and FCB settings backends. diff --git a/lib/open-amp/resource_table.c b/lib/open-amp/resource_table.c index 2942fe6ccfe73..1714e31a95166 100644 --- a/lib/open-amp/resource_table.c +++ b/lib/open-amp/resource_table.c @@ -72,8 +72,33 @@ static struct fw_resource_table __resource resource_table = { #endif }; +#if DT_HAS_CHOSEN(zephyr_rsc_table) + +#define RSC_TABLE_RELOC DT_CHOSEN(zephyr_rsc_table) +#define RSC_TABLE_RELOC_START DT_REG_ADDR(RSC_TABLE_RELOC) +#define RSC_TABLE_RELOC_SIZE DT_REG_SIZE(RSC_TABLE_RELOC) + +BUILD_ASSERT(sizeof(resource_table) <= RSC_TABLE_RELOC_SIZE, + "Resource table does not fit in the relocation area"); + +#endif + void rsc_table_get(void **table_ptr, int *length) { +#if defined(RSC_TABLE_RELOC) + const size_t cmp_size = offsetof(struct fw_resource_table, offset) + sizeof(((struct fw_resource_table *)0)->offset); + + *table_ptr = (void *)RSC_TABLE_RELOC_START; + *length = sizeof(resource_table); + + /* + * Do not copy the resource table if it has already been installed from the remote host. + * Because the remote host may have already initialized some fields, only the guaranteed constant bytes can be compared. + */ + if(memcmp(&resource_table, *table_ptr, cmp_size)) + memcpy(*table_ptr, (void *)&resource_table, *length); +#else *table_ptr = (void *)&resource_table; *length = sizeof(resource_table); +#endif }