Skip to content

Open amp refactoring and add more platforms support #17553

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
merged 7 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions boards/arm/mps2_an521/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ config I2C_SBCON
default y
depends on I2C

if IPM

config IPM_MHU
default y

endif # IPM

endif
7 changes: 7 additions & 0 deletions boards/arm/v2m_musca/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ config TIMER_DTMR_CMSDK_APB

endif # COUNTER

if IPM

config IPM_MHU
default y

endif # IPM

endif
7 changes: 7 additions & 0 deletions boards/arm/v2m_musca_b1/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ config UART_PL011_PORT1

endif # SERIAL

if IPM

config IPM_MHU
default y

endif # IPM

endif
32 changes: 25 additions & 7 deletions samples/subsys/ipc/openamp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
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)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(openamp)
set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr)

if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m4"))
message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m4")
if("${BOARD}" STREQUAL "lpcxpresso54114_m4")
set(BOARD_REMOTE "lpcxpresso54114_m0")
elseif("${BOARD}" STREQUAL "mps2_an521")
set(QEMU_EXTRA_FLAGS "-device;loader,file=${REMOTE_ZEPHYR_DIR}/zephyr.elf")
set(BOARD_REMOTE "mps2_an521_nonsecure")
elseif("${BOARD}" STREQUAL "v2m_musca")
set(BOARD_REMOTE "v2m_musca_nonsecure")
elseif("${BOARD}" STREQUAL "v2m_musca_b1")
set(BOARD_REMOTE "v2m_musca_b1_nonsecure")
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)

enable_language(C ASM)

target_sources(app PRIVATE src/main.c)
Expand All @@ -22,10 +35,15 @@ ExternalProject_Add(
openamp_remote
SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote
INSTALL_COMMAND "" # This particular build system has no install command
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin"
CMAKE_CACHE_ARGS -DBOARD:string=${BOARD_REMOTE}
CMAKE_CACHE_ARGS -DDTC_OVERLAY_FILE:string=${DTC_OVERLAY_FILE}
BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/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})
30 changes: 30 additions & 0 deletions samples/subsys/ipc/openamp/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
58 changes: 48 additions & 10 deletions samples/subsys/ipc/openamp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,40 @@ Overview

This application demonstrates how to use OpenAMP with Zephyr. It is designed to
demonstrate how to integrate OpenAMP with Zephyr both from a build perspective
and code. Currently this integration is specific to the LPC54114 SoC.
and code.

Building the application
*************************
Building the application for lpcxpresso54114_m4
***********************************************

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/openamp
:board: lpcxpresso54114_m4
:goals: debug

Building the application for mps2_an521
***************************************

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/openamp
:board: mps2_an521
:goals: debug

Building the application for v2m_musca
**************************************

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/openamp
:board: v2m_musca
:goals: debug

Building the application for v2m_musca_b1
*****************************************

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/openamp
:board: v2m_musca_b1
:goals: debug

Open a serial terminal (minicom, putty, etc.) and connect the board with the
following settings:

Expand All @@ -27,17 +51,31 @@ following settings:
- Stop bits: 1

Reset the board and the following message will appear on the corresponding
serial port:
serial port, one is master another is remote:

.. code-block:: console

**** Booting Zephyr OS build zephyr-v1.14.0-2064-g888fc98fddaa ****
Starting application thread!

OpenAMP[master] demo started
Master core received a message: 1
Master core received a message: 3
Master core received a message: 5
...
Master core received a message: 99
OpenAMP demo ended.


.. code-block:: console

***** Booting Zephyr OS v1.11.0-1377-g580b9add47 *****
**** Booting Zephyr OS build zephyr-v1.14.0-2064-g888fc98fddaa ****
Starting application thread!

OpenAMP demo started
Primary core received a message: 1
Primary core received a message: 3
Primary core received a message: 5
OpenAMP[remote] demo started
Remote core received a message: 0
Remote core received a message: 2
Remote core received a message: 4
...
Primary core received a message: 101
Remote core received a message: 98
OpenAMP demo ended.
3 changes: 3 additions & 0 deletions samples/subsys/ipc/openamp/boards/lpcxpresso54114_m4.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_IPM_MCUX=y
CONFIG_SLAVE_CORE_MCUX=y
CONFIG_SLAVE_IMAGE_MCUX="${ZEPHYR_BINARY_DIR}/../openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin"
17 changes: 11 additions & 6 deletions samples/subsys/ipc/openamp/common.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
* Copyright (c) 2018 Linaro Limited
* Copyright (c) 2018-2019 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

#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
20 changes: 20 additions & 0 deletions samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay
Original file line number Diff line number Diff line change
@@ -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>;
};
};
20 changes: 20 additions & 0 deletions samples/subsys/ipc/openamp/mps2_an521.overlay
Original file line number Diff line number Diff line change
@@ -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 = &sramx;
zephyr,ipc = &mhu0;
};

sramx: memory@28180000 {
compatible = "mmio-sram";
reg = <0x28180000 0x8000>;
};
};
3 changes: 0 additions & 3 deletions samples/subsys/ipc/openamp/prj.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
CONFIG_PRINTK=y
CONFIG_IPM=y
CONFIG_IPM_MCUX=y
CONFIG_SLAVE_CORE_MCUX=y
CONFIG_SLAVE_IMAGE_MCUX="${ZEPHYR_BINARY_DIR}/../openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin"
CONFIG_TIMESLICE_SIZE=1
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_HEAP_MEM_POOL_SIZE=4096
Expand Down
15 changes: 10 additions & 5 deletions samples/subsys/ipc/openamp/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +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_m0)

if(("${BOARD}" STREQUAL "lpcxpresso54114_m0")
OR "${BOARD}" STREQUAL "mps2_an521_nonsecure"
OR "${BOARD}" STREQUAL "v2m_musca_nonsecure"
OR "${BOARD}" STREQUAL "v2m_musca_b1_nonsecure")
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}/..)
30 changes: 30 additions & 0 deletions samples/subsys/ipc/openamp/remote/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_IPM_MCUX=y
1 change: 0 additions & 1 deletion samples/subsys/ipc/openamp/remote/prj.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CONFIG_STDOUT_CONSOLE=n
CONFIG_PRINTK=n
CONFIG_IPM=y
CONFIG_IPM_MCUX=y
CONFIG_PLATFORM_SPECIFIC_INIT=n
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_OPENAMP=y
Expand Down
12 changes: 10 additions & 2 deletions samples/subsys/ipc/openamp/remote/src/main.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -73,9 +73,17 @@ static u32_t virtio_get_features(struct virtio_device *vdev)

static void virtio_notify(struct virtqueue *vq)
{
#if defined(CONFIG_SOC_MPS2_AN521) || \
defined(CONFIG_SOC_V2M_MUSCA_A) || \
defined(CONFIG_SOC_V2M_MUSCA_B1)
u32_t current_core = sse_200_platform_get_cpu_id();

ipm_send(ipm_handle, 0, current_core ? 0 : 1, 0, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the data here mater?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dummy data is not necessary here for MHU based hardware. But it needs to distinguish the current core No. for notifications.

#else
u32_t dummy_data = 0x00110011; /* Some data must be provided */

ipm_send(ipm_handle, 0, 0, &dummy_data, sizeof(dummy_data));
#endif /* #if defined(CONFIG_SOC_MPS2_AN521) */
}

struct virtio_dispatch dispatch = {
Expand Down Expand Up @@ -168,7 +176,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;
Expand Down
Loading