-
Notifications
You must be signed in to change notification settings - Fork 8.2k
OpenAMP rsc table sample #16985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
galak
merged 4 commits into
zephyrproject-rtos:master
from
arnopo:OpenAMP_rsc_table_sample
Apr 1, 2020
Merged
OpenAMP rsc table sample #16985
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
531cd57
lib: open-amp: add helper to add resource table in project
arnopo cb41aa7
stm32mp1: update resource table management
arnopo 09bac32
dts: extend stm32mp1 sram declaration to 300 kB by default
arnopo 6d2865e
samples: add openamp sample relying on resource table
arnopo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,6 @@ source "lib/posix/Kconfig" | |
|
|
||
| source "lib/updatehub/Kconfig" | ||
|
|
||
| source "lib/open-amp/Kconfig" | ||
|
|
||
| endmenu | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # | ||
| # Copyright (c) 2020, STMicroelectronics | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| zephyr_include_directories_ifdef(CONFIG_OPENAMP_RSC_TABLE .) | ||
| zephyr_sources_ifdef(CONFIG_OPENAMP_RSC_TABLE resource_table.c) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # | ||
| # Copyright (c) 2020, STMicroelectronics | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| config OPENAMP_RSC_TABLE | ||
| bool "coprocessor resource table" | ||
| imply OPENAMP | ||
| help | ||
| add the resource table in the generated binary. This table is | ||
| compatible with linux remote proc framework and OpenAMP library. | ||
|
|
||
| config OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF | ||
| int "Resource table number of rpmsg buffers" | ||
| default 0 | ||
| depends on OPENAMP_RSC_TABLE | ||
| help | ||
| This option specifies the number of buffer used in a Vring for | ||
| interprocessor communication |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright (c) 2020 STMicroelectronics | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /* | ||
| * In addition to the standard ELF segments, most remote processors would | ||
| * also include a special section which we call "the resource table". | ||
| * | ||
| * The resource table contains system resources that the remote processor | ||
| * requires before it should be powered on, such as allocation of physically | ||
| * contiguous memory, or iommu mapping of certain on-chip peripherals. | ||
|
|
||
| * In addition to system resources, the resource table may also contain | ||
| * resource entries that publish the existence of supported features | ||
| * or configurations by the remote processor, such as trace buffers and | ||
| * supported virtio devices (and their configurations). | ||
|
|
||
| * Dependencies: | ||
| * to be compliant with Linux kernel OS the resource table must be linked in a | ||
| * specific section named ".resource_table". | ||
|
|
||
| * Related documentation: | ||
| * https://www.kernel.org/doc/Documentation/remoteproc.txt | ||
| * https://github.com/OpenAMP/open-amp/wiki/OpenAMP-Life-Cycle-Management | ||
| */ | ||
|
|
||
| #include <zephyr.h> | ||
| #include <resource_table.h> | ||
|
|
||
| extern char ram_console[]; | ||
|
|
||
| #define __resource Z_GENERIC_SECTION(.resource_table) | ||
|
|
||
| #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) || defined(CONFIG_RAM_CONSOLE) | ||
|
|
||
| static struct fw_resource_table __resource resource_table = { | ||
| .ver = 1, | ||
| .num = RSC_TABLE_NUM_ENTRY, | ||
| .offset = { | ||
|
|
||
| #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) | ||
| offsetof(struct fw_resource_table, vdev), | ||
| #endif | ||
|
|
||
| #if defined(CONFIG_RAM_CONSOLE) | ||
| offsetof(struct fw_resource_table, cm_trace), | ||
| #endif | ||
| }, | ||
|
|
||
| #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) | ||
| /* Virtio device entry */ | ||
| .vdev = { | ||
| RSC_VDEV, VIRTIO_ID_RPMSG, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0, | ||
| VRING_COUNT, {0, 0}, | ||
| }, | ||
|
|
||
| /* Vring rsc entry - part of vdev rsc entry */ | ||
| .vring0 = {VRING_TX_ADDRESS, VRING_ALIGNMENT, | ||
| CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF, | ||
| VRING0_ID, 0}, | ||
| .vring1 = {VRING_RX_ADDRESS, VRING_ALIGNMENT, | ||
| CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF, | ||
| VRING1_ID, 0}, | ||
| #endif | ||
|
|
||
| #if defined(CONFIG_RAM_CONSOLE) | ||
| .cm_trace = { | ||
| RSC_TRACE, | ||
| (uint32_t)ram_console, CONFIG_RAM_CONSOLE_BUFFER_SIZE + 1, 0, | ||
| "Zephyr_log", | ||
| }, | ||
| #endif | ||
| }; | ||
|
|
||
| void rsc_table_get(void **table_ptr, int *length) | ||
| { | ||
| *table_ptr = (void *)&resource_table; | ||
| *length = sizeof(resource_table); | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright (c) 2020 STMicroelectronics | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef RESOURCE_TABLE_H__ | ||
| #define RESOURCE_TABLE_H__ | ||
|
|
||
| #include <openamp/remoteproc.h> | ||
| #include <openamp/virtio.h> | ||
|
|
||
| #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) | ||
|
|
||
| #define VDEV_ID 0xFF | ||
| #define VRING0_ID 0 /* (master to remote) fixed to 0 for Linux compatibility */ | ||
| #define VRING1_ID 1 /* (remote to master) fixed to 1 for Linux compatibility */ | ||
|
|
||
| #define VRING_COUNT 2 | ||
| #define RPMSG_IPU_C0_FEATURES 1 | ||
|
|
||
| #define VRING_RX_ADDRESS -1 /* allocated by Master processor */ | ||
| #define VRING_TX_ADDRESS -1 /* allocated by Master processor */ | ||
| #define VRING_BUFF_ADDRESS -1 /* allocated by Master processor */ | ||
| #define VRING_ALIGNMENT 16 /* fixed to match with Linux constraint */ | ||
|
|
||
| #endif | ||
|
|
||
| enum rsc_table_entries { | ||
| #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) | ||
| RSC_TABLE_VDEV_ENTRY, | ||
| #endif | ||
| #if defined(CONFIG_RAM_CONSOLE) | ||
| RSC_TABLE_TRACE_ENTRY, | ||
| #endif | ||
| RSC_TABLE_NUM_ENTRY | ||
| }; | ||
|
|
||
| struct fw_resource_table { | ||
| unsigned int ver; | ||
| unsigned int num; | ||
| unsigned int reserved[2]; | ||
| unsigned int offset[RSC_TABLE_NUM_ENTRY]; | ||
|
|
||
| struct fw_rsc_vdev vdev; | ||
| struct fw_rsc_vdev_vring vring0; | ||
| struct fw_rsc_vdev_vring vring1; | ||
|
|
||
| #if defined(CONFIG_RAM_CONSOLE) | ||
| /* rpmsg trace entry */ | ||
| struct fw_rsc_trace cm_trace; | ||
| #endif | ||
| } METAL_PACKED_END; | ||
|
|
||
| void rsc_table_get(void **table_ptr, int *length); | ||
|
|
||
| inline struct fw_rsc_vdev *rsc_table_to_vdev(void *rsc_table) | ||
| { | ||
| return &((struct fw_resource_table *)rsc_table)->vdev; | ||
| } | ||
|
|
||
| inline struct fw_rsc_vdev_vring *rsc_table_get_vring0(void *rsc_table) | ||
| { | ||
| return &((struct fw_resource_table *)rsc_table)->vring0; | ||
| } | ||
|
|
||
| inline struct fw_rsc_vdev_vring *rsc_table_get_vring1(void *rsc_table) | ||
| { | ||
| return &((struct fw_resource_table *)rsc_table)->vring1; | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| cmake_minimum_required(VERSION 3.13.1) | ||
| # Copyright (c) 2020 STMicroelectronics | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) | ||
|
|
||
| project(openamp_rsc_table_remote) | ||
|
|
||
| # METAL_MAX_DEVICE_REGIONS is used to give the number of memory regions shared | ||
| # between processors. By default only one region is defined for the vrings | ||
| # and rpmsg buffers. The METAL_MAX_DEVICE_REGIONS has to be redifined to add a | ||
| # second region for the resource table. | ||
| zephyr_compile_definitions(METAL_MAX_DEVICE_REGIONS=2) | ||
|
|
||
| target_include_directories(app PRIVATE ${LIBMETAL_INCLUDE_DIR} ${OPENAMP_INCLUDE_DIR} ${PLATFORM_DIR}) | ||
|
|
||
| target_sources(app PRIVATE src/main_remote.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Private config options for openamp sample app | ||
|
|
||
| # Copyright (c) 2020 STMicroelectronics | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Workaround for not being able to have commas in macro arguments | ||
| DT_CHOSEN_Z_IPC := zephyr,ipc | ||
|
|
||
| config OPENAMP_IPC_DEV_NAME | ||
| string | ||
| default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))" | ||
| help | ||
| This option specifies the device name for the IPC device to be used | ||
|
|
||
| source "Kconfig.zephyr" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| .. _openAMP_rsc_table_sample: | ||
|
|
||
| OpenAMP Sample Application using resource table | ||
| ############################################### | ||
|
|
||
| Overview | ||
| ******** | ||
|
|
||
| This application demonstrates how to use OpenAMP with Zephyr based on a resource | ||
| table. It is designed to respond to the `Linux rpmsg client sample <https://elixir.bootlin.com/linux/latest/source/samples/rpmsg/rpmsg_client_sample.c>`_. | ||
| This sample implementation is compatible with platforms that embed | ||
| a Linux kernel OS on the main processor and a Zephyr application on | ||
| the co-processor. | ||
|
|
||
| Building the application | ||
| ************************* | ||
|
|
||
| Zephyr | ||
| ------- | ||
|
|
||
| .. zephyr-app-commands:: | ||
| :zephyr-app: samples/subsys/ipc/openamp_rsc_table | ||
| :goals: test | ||
|
|
||
| Linux | ||
| ------ | ||
|
|
||
| Enable SAMPLE_RPMSG_CLIENT configuration to build and install | ||
| the rpmsg_client_sample.ko module on the target. | ||
|
|
||
| Running the sample | ||
| ******************* | ||
|
|
||
| Zephyr console | ||
| --------------- | ||
|
|
||
| Open a serial terminal (minicom, putty, etc.) and connect the board with the | ||
| following settings: | ||
|
|
||
| - Speed: 115200 | ||
| - Data: 8 bits | ||
| - Parity: None | ||
| - Stop bits: 1 | ||
|
|
||
| Reset the board. | ||
|
|
||
| Linux console | ||
| --------------- | ||
|
|
||
| Open a Linux shell (minicom, ssh, etc.) and insert a module into the Linux Kernel | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| root@linuxshell: insmod rpmsg_client_sample.ko | ||
|
|
||
| Result on Zephyr console | ||
| ------------------------- | ||
|
|
||
| The following message will appear on the corresponding Zephyr console: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| ***** Booting Zephyr OS v#.##.#-####-g########## ***** | ||
| Starting application thread! | ||
|
|
||
| OpenAMP demo started | ||
| Remote core received message 1: hello world! | ||
| Remote core received message 2: hello world! | ||
| Remote core received message 3: hello world! | ||
| ... | ||
| Remote core received message 100: hello world! | ||
| OpenAMP demo ended. |
24 changes: 24 additions & 0 deletions
24
samples/subsys/ipc/openamp_rsc_table/boards/stm32mp157c_dk2.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2020, STMICROLECTRONICS | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| / { | ||
| chosen { | ||
| /* | ||
| * shared memory reserved for the inter-processor communication | ||
| */ | ||
| zephyr,ipc_shm = &mcusram3; | ||
| zephyr,ipc = &mailbox; | ||
| }; | ||
|
|
||
| mcusram3: memory1@10040000 { | ||
| compatible = "mmio-sram"; | ||
| reg = <0x10040000 DT_SIZE_K(64)>; | ||
| }; | ||
| }; | ||
|
|
||
| &mcusram { | ||
| reg = <0x10000000 DT_SIZE_K(256)>; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| CONFIG_KERNEL_BIN_NAME="zephyr_openamp_rsc_table" | ||
| CONFIG_PRINTK=n | ||
| CONFIG_IPM=y | ||
| CONFIG_IPM_MCUX=y | ||
| CONFIG_PLATFORM_SPECIFIC_INIT=n | ||
| CONFIG_MAIN_STACK_SIZE=1024 | ||
| CONFIG_HEAP_MEM_POOL_SIZE=1024 | ||
| CONFIG_OPENAMP=y | ||
| CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=8 | ||
| CONFIG_OPENAMP_RSC_TABLE=y | ||
| CONFIG_OPENAMP_MASTER=n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| sample: | ||
| description: This app provides an example of how to integrate OpenAMP | ||
| with Zephyr in cluding a esource table. | ||
| name: OpenAMP with resource table example integration | ||
| tests: | ||
| sample.subsys.ipc.openamp_rs_table: | ||
| build_only: true | ||
| platform_whitelist: stm32mp157c_dk2 | ||
| tags: ipm |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.