From 742f55a9989461b3503ebcf8094c9c1a0ebf77eb Mon Sep 17 00:00:00 2001 From: Karl Zhang Date: Thu, 11 Jul 2019 21:49:30 +0800 Subject: [PATCH] samples: openamp: Remove exclusive compile of openAMP Add configuable shared memory address for openAMP samples. There is a plan to add more platforms supported for openAMP in zephyr. Each platform can specify the shared memory address and device by device tree and add it's support in openAMP samples. Signed-off-by: Karl Zhang Signed-off-by: Kumar Gala --- samples/subsys/ipc/openamp/CMakeLists.txt | 21 +++++++++---- samples/subsys/ipc/openamp/Kconfig | 30 +++++++++++++++++++ samples/subsys/ipc/openamp/common.h | 17 +++++++---- .../ipc/openamp/lpcxpresso54114_m4.overlay | 20 +++++++++++++ .../subsys/ipc/openamp/remote/CMakeLists.txt | 11 +++---- samples/subsys/ipc/openamp/remote/Kconfig | 30 +++++++++++++++++++ samples/subsys/ipc/openamp/remote/src/main.c | 4 +-- samples/subsys/ipc/openamp/src/main.c | 4 +-- 8 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 samples/subsys/ipc/openamp/Kconfig create mode 100644 samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay create mode 100644 samples/subsys/ipc/openamp/remote/Kconfig diff --git a/samples/subsys/ipc/openamp/CMakeLists.txt b/samples/subsys/ipc/openamp/CMakeLists.txt index 95e866dfb27..804fd423001 100644 --- a/samples/subsys/ipc/openamp/CMakeLists.txt +++ b/samples/subsys/ipc/openamp/CMakeLists.txt @@ -1,17 +1,21 @@ cmake_minimum_required(VERSION 3.13.1) # Copyright (c) 2018 Nordic Semiconductor ASA +# Copyright (c) 2019 Linaro Limited # # SPDX-License-Identifier: Apache-2.0 # -set(BOARD lpcxpresso54114_m4) + +if("${BOARD}" STREQUAL "lpcxpresso54114_m4") + set(BOARD_REMOTE "lpcxpresso54114_m0") +else() + message(FATAL_ERROR "${BOARD} was not supported for this sample") +endif() + +message(INFO " ${BOARD} compile as Master in this sample") include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(openamp) -if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m4")) - message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m4") -endif() - enable_language(C ASM) target_sources(app PRIVATE src/main.c) @@ -22,10 +26,15 @@ ExternalProject_Add( openamp_remote SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote INSTALL_COMMAND "" # This particular build system has no install command + CMAKE_CACHE_ARGS -DBOARD:string=${BOARD_REMOTE} + CMAKE_CACHE_ARGS -DDTC_OVERLAY_FILE:string=${DTC_OVERLAY_FILE} BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin" # NB: Do we need to pass on more CMake variables? BUILD_ALWAYS True ) -add_dependencies(core_m0_inc_target openamp_remote) + +if(("${BOARD}" STREQUAL "lpcxpresso54114_m4")) + add_dependencies(core_m0_inc_target openamp_remote) +endif() target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/samples/subsys/ipc/openamp/Kconfig b/samples/subsys/ipc/openamp/Kconfig new file mode 100644 index 00000000000..39bbc199d0b --- /dev/null +++ b/samples/subsys/ipc/openamp/Kconfig @@ -0,0 +1,30 @@ +# Private config options for openamp sample app + +# Copyright (c) 2020 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +# Workaround for not being able to have commas in macro arguments +DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm +DT_CHOSEN_Z_IPC := zephyr,ipc + +config OPENAMP_IPC_SHM_BASE_ADDRESS + hex + default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies base address of the memory region to + be used for the OpenAMP IPC shared memory + +config OPENAMP_IPC_SHM_SIZE + hex + default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies size of the memory region to be used + for the OpenAMP IPC shared memory + +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" diff --git a/samples/subsys/ipc/openamp/common.h b/samples/subsys/ipc/openamp/common.h index 27ceaf094d0..2386eb8715d 100644 --- a/samples/subsys/ipc/openamp/common.h +++ b/samples/subsys/ipc/openamp/common.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2018 Linaro Limited + * Copyright (c) 2018-2019 Linaro Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,16 +8,21 @@ #ifndef COMMON_H__ #define COMMON_H__ -#define SHM_START_ADDR 0x04000400 -#define SHM_SIZE 0x7c00 +#define VDEV_START_ADDR CONFIG_OPENAMP_IPC_SHM_BASE_ADDRESS +#define VDEV_SIZE CONFIG_OPENAMP_IPC_SHM_SIZE + +#define VDEV_STATUS_ADDR VDEV_START_ADDR +#define VDEV_STATUS_SIZE 0x400 + +#define SHM_START_ADDR (VDEV_START_ADDR + VDEV_STATUS_SIZE) +#define SHM_SIZE (VDEV_SIZE - VDEV_STATUS_SIZE) #define SHM_DEVICE_NAME "sramx.shm" #define VRING_COUNT 2 -#define VRING_RX_ADDRESS 0x04007800 -#define VRING_TX_ADDRESS 0x04007C00 +#define VRING_RX_ADDRESS (VDEV_START_ADDR + SHM_SIZE - VDEV_STATUS_SIZE) +#define VRING_TX_ADDRESS (VDEV_START_ADDR + SHM_SIZE) #define VRING_ALIGNMENT 4 #define VRING_SIZE 16 -#define VDEV_STATUS_ADDR 0x04000000 #endif diff --git a/samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay b/samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay new file mode 100644 index 00000000000..61e3476ecb4 --- /dev/null +++ b/samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &sramx1; + zephyr,ipc = &mailbox0; + }; + + sramx1:memory@4000000{ + compatible = "mmio-sram"; + reg = <0x4000000 0x8000>; + }; +}; diff --git a/samples/subsys/ipc/openamp/remote/CMakeLists.txt b/samples/subsys/ipc/openamp/remote/CMakeLists.txt index a6cc307808d..884de45722a 100644 --- a/samples/subsys/ipc/openamp/remote/CMakeLists.txt +++ b/samples/subsys/ipc/openamp/remote/CMakeLists.txt @@ -1,16 +1,17 @@ cmake_minimum_required(VERSION 3.13.1) # Copyright (c) 2018 Nordic Semiconductor ASA +# Copyright (c) 2019 Linaro Limited # # SPDX-License-Identifier: Apache-2.0 # -set(BOARD lpcxpresso54114_m0) +if(("${BOARD}" STREQUAL "lpcxpresso54114_m0")) + message(INFO " ${BOARD} compile as slave in this sample") +else() + message(FATAL_ERROR "${BOARD} was not supported for this sample") +endif() include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(openamp_remote) -if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m0")) - message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m0") -endif() - target_sources(app PRIVATE src/main.c) target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/samples/subsys/ipc/openamp/remote/Kconfig b/samples/subsys/ipc/openamp/remote/Kconfig new file mode 100644 index 00000000000..39bbc199d0b --- /dev/null +++ b/samples/subsys/ipc/openamp/remote/Kconfig @@ -0,0 +1,30 @@ +# Private config options for openamp sample app + +# Copyright (c) 2020 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +# Workaround for not being able to have commas in macro arguments +DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm +DT_CHOSEN_Z_IPC := zephyr,ipc + +config OPENAMP_IPC_SHM_BASE_ADDRESS + hex + default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies base address of the memory region to + be used for the OpenAMP IPC shared memory + +config OPENAMP_IPC_SHM_SIZE + hex + default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies size of the memory region to be used + for the OpenAMP IPC shared memory + +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" diff --git a/samples/subsys/ipc/openamp/remote/src/main.c b/samples/subsys/ipc/openamp/remote/src/main.c index 0f24b3f0a46..ac9c04bac82 100644 --- a/samples/subsys/ipc/openamp/remote/src/main.c +++ b/samples/subsys/ipc/openamp/remote/src/main.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018, NXP * Copyright (c) 2018, Nordic Semiconductor ASA - * Copyright (c) 2018, Linaro Limited + * Copyright (c) 2018-2019, Linaro Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -168,7 +168,7 @@ void app_task(void *arg1, void *arg2, void *arg3) } /* setup IPM */ - ipm_handle = device_get_binding("MAILBOX_0"); + ipm_handle = device_get_binding(CONFIG_OPENAMP_IPC_DEV_NAME); if (ipm_handle == NULL) { printk("device_get_binding failed to find device\n"); return; diff --git a/samples/subsys/ipc/openamp/src/main.c b/samples/subsys/ipc/openamp/src/main.c index ef4699d63c6..b8c86b40ced 100644 --- a/samples/subsys/ipc/openamp/src/main.c +++ b/samples/subsys/ipc/openamp/src/main.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018, NXP * Copyright (c) 2018, Nordic Semiconductor ASA - * Copyright (c) 2018, Linaro Limited + * Copyright (c) 2018-2019, Linaro Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -192,7 +192,7 @@ void app_task(void *arg1, void *arg2, void *arg3) } /* setup IPM */ - ipm_handle = device_get_binding("MAILBOX_0"); + ipm_handle = device_get_binding(CONFIG_OPENAMP_IPC_DEV_NAME); if (ipm_handle == NULL) { printk("device_get_binding failed to find device\n"); return;