├── .readthedocs-conf.py ├── .readthedocs.yaml ├── LICENSE.md ├── README.md ├── examples ├── legacy_apps │ ├── CMakeLists.txt │ ├── README.md │ ├── cmake │ │ ├── collect.cmake │ │ ├── depends.cmake │ │ ├── modules │ │ │ ├── FindLibmetal.cmake │ │ │ └── Findopen_amp.cmake │ │ ├── options.cmake │ │ ├── platforms │ │ │ ├── cross_generic_gcc.cmake │ │ │ ├── cross_linux_gcc.cmake │ │ │ ├── zynqmp_a53_generic.cmake │ │ │ ├── zynqmp_linux.cmake │ │ │ └── zynqmp_r5_generic.cmake │ │ └── syscheck.cmake │ ├── examples │ │ ├── CMakeLists.txt │ │ ├── echo │ │ │ ├── CMakeLists.txt │ │ │ ├── README.rst │ │ │ ├── rpmsg-echo.c │ │ │ ├── rpmsg-echo.h │ │ │ └── rpmsg-ping.c │ │ ├── linux_rpc_demo │ │ │ ├── CMakeLists.txt │ │ │ ├── README.rst │ │ │ ├── linux-rpmsg-rpc-demo.h │ │ │ ├── linux_rpc_demo.c │ │ │ └── linux_rpc_demod.c │ │ ├── load_fw │ │ │ ├── CMakeLists.txt │ │ │ ├── common.h │ │ │ ├── load_fw.c │ │ │ ├── lscript.ld │ │ │ ├── mem_image_store.c │ │ │ ├── platform_info.c │ │ │ ├── platform_info.h │ │ │ ├── zynqmp_apu_lcm_rproc_example.c │ │ │ ├── zynqmp_r5_lcm_rproc_example.c │ │ │ └── zynqmp_rpu_lcm_rproc_example.c │ │ ├── matrix_multiply │ │ │ ├── CMakeLists.txt │ │ │ ├── README.rst │ │ │ ├── matrix_multiply.c │ │ │ ├── matrix_multiply.h │ │ │ └── matrix_multiplyd.c │ │ ├── nocopy_echo │ │ │ ├── CMakeLists.txt │ │ │ ├── README.rst │ │ │ ├── rpmsg-echo.h │ │ │ ├── rpmsg-nocopy-echo.c │ │ │ └── rpmsg-nocopy-ping.c │ │ ├── rpc_demo │ │ │ ├── CMakeLists.txt │ │ │ ├── README.rst │ │ │ ├── rpc_demo.c │ │ │ ├── rpc_demod.c │ │ │ └── rpmsg-rpc-demo.h │ │ └── rpmsg_sample_echo │ │ │ ├── CMakeLists.txt │ │ │ ├── README.rst │ │ │ ├── rpmsg-sample-echo.c │ │ │ └── rpmsg-sample-ping.c │ ├── include │ │ └── platform_info_common.h │ ├── machine │ │ ├── CMakeLists.txt │ │ ├── microblaze_generic │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── platform_info.c │ │ │ ├── platform_info.h │ │ │ ├── rsc_table.c │ │ │ ├── rsc_table.h │ │ │ └── zynqmp_mb_a53_rproc.c │ │ ├── zynqmp │ │ │ ├── CMakeLists.txt │ │ │ ├── openamp-linux-userspace.dtsi │ │ │ ├── platform_info.c │ │ │ ├── platform_info.h │ │ │ └── zynqmp_linux_r5_proc.c │ │ └── zynqmp_r5 │ │ │ ├── CMakeLists.txt │ │ │ ├── platform_info.c │ │ │ ├── platform_info.h │ │ │ ├── rsc_table.c │ │ │ ├── rsc_table.h │ │ │ └── zynqmp_r5_a53_rproc.c │ ├── system │ │ ├── CMakeLists.txt │ │ ├── generic │ │ │ ├── CMakeLists.txt │ │ │ └── machine │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── microblaze_generic │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── helper.c │ │ │ │ └── linker_remote.ld │ │ │ │ └── zynqmp_r5 │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── helper.c │ │ │ │ ├── linker_large_text.ld │ │ │ │ └── linker_remote.ld │ │ └── linux │ │ │ ├── CMakeLists.txt │ │ │ └── machine │ │ │ ├── CMakeLists.txt │ │ │ ├── generic │ │ │ ├── CMakeLists.txt │ │ │ ├── helper.c │ │ │ ├── platform_info.c │ │ │ ├── platform_info.h │ │ │ ├── rsc_table.c │ │ │ └── rsc_table.h │ │ │ └── zynqmp │ │ │ ├── CMakeLists.txt │ │ │ └── helper.c │ ├── tests │ │ ├── CMakeLists.txt │ │ └── msg │ │ │ ├── CMakeLists.txt │ │ │ ├── rpmsg-flood-ping.c │ │ │ ├── rpmsg-nocopy-echo.c │ │ │ ├── rpmsg-nocopy-ping.c │ │ │ ├── rpmsg-ping.c │ │ │ ├── rpmsg-ping.h │ │ │ └── rpmsg-update.c │ └── west.yml ├── linux │ ├── common │ │ ├── common.c │ │ └── common.h │ ├── dts │ │ ├── .gitignore │ │ └── xilinx │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── xilinx-openamp-for-v6.x.dtso │ │ │ ├── zcu102-openamp.dtso │ │ │ ├── zynqmp-lockstep.dtso │ │ │ └── zynqmp-openamp.dtso │ ├── rpmsg-echo-test │ │ ├── Makefile │ │ ├── README.md │ │ └── echo_test.c │ ├── rpmsg-mat-mul │ │ ├── Makefile │ │ ├── README.md │ │ └── mat_mul_demo.c │ ├── rpmsg-proxy-app │ │ ├── Makefile │ │ ├── README.md │ │ ├── proxy_app.c │ │ └── proxy_app.h │ └── rpmsg-utils │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README │ │ ├── rpmsg_destroy_ept.c │ │ ├── rpmsg_export_dev.c │ │ ├── rpmsg_export_ept.c │ │ └── rpmsg_ping.c └── zephyr │ ├── README.md │ ├── dual_qemu_ivshmem │ ├── .gitignore │ ├── README.rst │ ├── host │ │ ├── CMakeLists.txt │ │ ├── app.overlay │ │ ├── boards │ │ │ ├── pcie_ivshmem.dtsi │ │ │ └── qemu_cortex_a53.conf │ │ ├── prj.conf │ │ └── src │ │ │ └── main.c │ ├── remote │ │ ├── CMakeLists.txt │ │ ├── app.overlay │ │ ├── boards │ │ │ ├── pcie_ivshmem.dtsi │ │ │ └── qemu_cortex_a53.conf │ │ ├── prj.conf │ │ └── src │ │ │ └── main.c │ └── rpmsg_ivshmem_backend │ │ ├── rpmsg_ivshmem_backend.c │ │ └── rpmsg_ivshmem_backend.h │ └── rpmsg_multi_services │ ├── CMakeLists.txt │ ├── README.rst │ ├── boards │ ├── imx8mp_evk_mimx8ml8_adsp.conf │ ├── imx8mp_evk_mimx8ml8_adsp.overlay │ ├── kv260_r5.overlay │ ├── stm32mp157c_dk2.overlay │ └── zynqmp_r5_override.dtsi │ ├── prj.conf │ ├── sample.yaml │ └── src │ └── main_remote.c ├── west-virtio-exp.yml └── west.yml /.readthedocs-conf.py: -------------------------------------------------------------------------------- 1 | # Although RTDs now requires sphinx: configuration: it does not pass it to the 2 | # build command and it still looks for conf.py in the current dir. It is 3 | # confusing to have a conf.py that will only work in the very specific RTDs 4 | # dir structure so we don't do that. 5 | 6 | # So we supply a no-op config file and override the build command to run in the 7 | # openamp-docs dir 8 | 9 | # Since we have our own build command now, we could eliminate this file 10 | # completely but that also disables the predefined sphinx steps of 11 | # create_environment and install. The current setup keeps the build 12 | # environment closer to that used by the real openamp-docs build 13 | 14 | print(".readthedocs-conf.py does nothing") 15 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # The main readthedocs build is in openamp-docs and includes this repo as a 2 | # sub-module. 3 | 4 | # This config file supports doc preview for PRs in this repo. 5 | # This allows us to see how a PR in this repo will look in the docs before it 6 | # is promoted to main and before the openamp-docs repo picks up the new version. 7 | 8 | version: 2 9 | # only do html, this is the case for PRs anyway but make sure 10 | formats: [] 11 | sphinx: 12 | # See comments in the file for why this is required 13 | configuration: ./.readthedocs-conf.py 14 | build: 15 | os: "ubuntu-22.04" 16 | tools: 17 | python: "3.10" 18 | apt_packages: 19 | - cmake 20 | - libhugetlbfs-dev 21 | - libsysfs-dev 22 | jobs: 23 | post_checkout: 24 | - echo "post_checkout"; pwd; echo $PATH; env; ls -la . 25 | # we ignore the checkout they did and make a new one of the whole openamp-docs project 26 | - git log -n 1 --oneline 27 | - git rev-parse HEAD 28 | - git clone --recurse-submodules https://github.com/OpenAMP/openamp-docs.git 29 | # now adjust the focused submodule to the PR in progress 30 | - echo "URL=${READTHEDOCS_GIT_CLONE_URL} COMMIT=${READTHEDOCS_GIT_COMMIT_HASH}" 31 | - (cd openamp-docs/openamp-system-reference; git remote add this_pr ../../.git ) 32 | - (cd openamp-docs/openamp-system-reference; git fetch this_pr $(cd ../..; git rev-parse HEAD) ) 33 | - (cd openamp-docs/openamp-system-reference; git checkout $(cd ../..; git rev-parse HEAD) ) 34 | - (cd openamp-docs/openamp-system-reference; git log -n 1 --oneline) 35 | - (cd openamp-docs; git submodule status) 36 | post_install: 37 | - echo "post_install"; pwd; echo $PATH; env; ls -la . openamp-docs 38 | - python -m pip install --exists-action=w --no-cache-dir -r openamp-docs/requirements.txt 39 | pre_build: 40 | - echo "pre_build"; pwd; echo $PATH; env; ls -la . openamp-docs 41 | - echo "READTHEDOCS_OUTPUT=$READTHEDOCS_OUTPUT" 42 | - make -C openamp-docs BUILDDIR=$READTHEDOCS_OUTPUT doxygen 43 | build: 44 | html: 45 | - echo "build"; pwd; echo $PATH; env; ls -la . openamp-docs 46 | # This is the default build command as of 2025/01/12 but with 47 | # "." changed to "openamp-docs" 48 | - python -m sphinx -T -b html -d _build/doctrees -D language=en openamp-docs $READTHEDOCS_OUTPUT/html 49 | post_build: 50 | - echo "post_build"; pwd; echo $PATH; ls -la . openamp-docs 51 | - make -C openamp-docs BUILDDIR=$READTHEDOCS_OUTPUT doxygen_copy 52 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD 3-Clause License) 2 | ======================================== 3 | 4 | Copyright (c) 2014, Mentor Graphics Corporation. All rights reserved. 5 | Copyright (c) 2015 - 2016 Xilinx, Inc. All rights reserved. 6 | Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved 7 | Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 15 | 2. Redistributions in binary form must reproduce the above copyright notice, 16 | this list of conditions and the following disclaimer in the documentation 17 | and/or other materials provided with the distribution. 18 | 19 | 3. Neither the name of nor the names of its contributors 20 | may be used to endorse or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | POSSIBILITY OF SUCH DAMAGE. 34 | 35 | BSD 2-Clause License 36 | ------------------------- 37 | 38 | Copyright (c) . All rights reserved. 39 | 40 | Redistribution and use in source and binary forms, with or without 41 | modification, are permitted provided that the following conditions are met: 42 | 43 | 1. Redistributions of source code must retain the above copyright notice, this 44 | list of conditions and the following disclaimer. 45 | 46 | 2. Redistributions in binary form must reproduce the above copyright notice, 47 | this list of conditions and the following disclaimer in the documentation 48 | and/or other materials provided with the distribution. 49 | 50 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 51 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 53 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 54 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 56 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 57 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 58 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | Notes 62 | ========================================= 63 | Use the following tag instead of the full license text in the individual files: 64 | 65 | SPDX-License-Identifier: BSD-3-Clause 66 | SPDX-License-Identifier: BSD-2-Clause 67 | 68 | This enables machine processing of license information based on the SPDX 69 | License Identifiers that are here available: http://spdx.org/licenses/ 70 | 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openamp-system-reference 2 | End-to-end system reference material showcasing all the different aspects of OpenAMP, on multiple vendor platforms. 3 | -------------------------------------------------------------------------------- /examples/legacy_apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | 3 | set (APPS_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 4 | set (APPS_SHARE_DIR "${CMAKE_CURRENT_BINARY_DIR}/share") 5 | 6 | list (APPEND CMAKE_MODULE_PATH 7 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 8 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" 9 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/platforms") 10 | 11 | include (syscheck) 12 | project (osr_legacy_apps C) 13 | 14 | include (CheckIncludeFiles) 15 | include (CheckCSourceCompiles) 16 | include (collect) 17 | include (options) 18 | include (depends) 19 | enable_testing () 20 | 21 | collector_create (APP_COMMON_SOURCES "") 22 | collector_create (APP_LIB_DIRS "") 23 | collector_create (APP_INC_DIRS "") 24 | collector_create (APP_LIB_DEPS "") 25 | 26 | collector_create (APP_EXTRA_C_FLAGS "") 27 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include") 28 | 29 | add_subdirectory (machine) 30 | add_subdirectory (system) 31 | add_subdirectory (tests) 32 | add_subdirectory (examples) 33 | -------------------------------------------------------------------------------- /examples/legacy_apps/README.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | This directory contains legacy applications and tests examples. 4 | These applications were moved from open-amp repository. 5 | 6 | 7 | # Initialization 8 | 9 | The first step is to initialize the workspace folder (``my-workspace``) where 10 | the examples and all Zephyr modules will be cloned. You can do 11 | that by running: 12 | 13 | ```shell 14 | # initialize my-workspace for the example-application (main branch) 15 | west init -m https://github.com/OpenAMP/openamp-system-reference --mf examples/legacy_apps/west.yml --mr main my-workspace 16 | # update modules 17 | cd my-workspace 18 | west update 19 | ``` 20 | 21 | # Build 22 | 23 | Following steps to build legacy apps on host machine. 24 | 25 | ``` 26 | export PROJECT_ROOT=$PWD 27 | ``` 28 | 29 | ## Build libmetal 30 | ```shell 31 | $ cd $PROJECT_ROOT/libmetal 32 | $ cmake . -Bbuild -DCMAKE_INSTALL_PREFIX=$PROJECT_ROOT/target 33 | $ make -C build VERBOSE=1 install 34 | ``` 35 | 36 | ## Build open_amp 37 | ```shell 38 | $ cd $PROJECT_ROOT/open-amp 39 | $ cmake . -Bbuild -DCMAKE_INCLUDE_PATH=$PROJECT_ROOT/libmetal/build/lib/include/ -DCMAKE_LIBRARY_PATH=$PROJECT_ROOT/libmetal/build/lib/ -DCMAKE_INSTALL_PREFIX=$PROJECT_ROOT/target 40 | $ make -C build VERBOSE=1 install 41 | ``` 42 | ## Build legacy Apps 43 | ```shell 44 | $ cd $PROJECT_ROOT/openamp-system-reference/examples/legacy_apps 45 | $ cmake -Bbuild \ 46 | -DCMAKE_INCLUDE_PATH="$PROJECT_ROOT/libmetal/build/lib/include/;$PROJECT_ROOT/open-amp/build/lib/include/" \ 47 | -DCMAKE_LIBRARY_PATH="$PROJECT_ROOT/libmetal/build/lib/;$PROJECT_ROOT/open-amp/build/lib/" \ 48 | -DCMAKE_INSTALL_PREFIX=$PROJECT_ROOT/target 49 | $ make -C build VERBOSE=1 install 50 | ``` 51 | 52 | ## Run application on a Linux PC 53 | It is possible to run application on a Linux PC to communicate between two Linux processes. 54 | 55 | ```shell 56 | $ cd $PROJECT_ROOT/target 57 | $ echo "################### run ping test #####################" 58 | $ LD_LIBRARY_PATH=./lib ./bin/rpmsg-echo-static & 59 | $ sleep 1 60 | $ LD_LIBRARY_PATH=./lib ./bin//msg-test-rpmsg-ping-static 1 61 | 62 | $ echo "################### run ping test #####################" 63 | $ LD_LIBRARY_PATH=./lib ./bin/rpmsg-nocopy-echo-static & 64 | $ sleep 1 65 | $ LD_LIBRARY_PATH=./lib ./bin//rpmsg-nocopy-ping-static 1 66 | ``` 67 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/collect.cmake: -------------------------------------------------------------------------------- 1 | function (collector_create name base) 2 | set_property (GLOBAL PROPERTY "COLLECT_${name}_LIST") 3 | set_property (GLOBAL PROPERTY "COLLECT_${name}_BASE" "${base}") 4 | endfunction (collector_create) 5 | 6 | function (collector_list var name) 7 | get_property (_list GLOBAL PROPERTY "COLLECT_${name}_LIST") 8 | set (${var} "${_list}" PARENT_SCOPE) 9 | endfunction (collector_list) 10 | 11 | function (collector_base var name) 12 | get_property (_base GLOBAL PROPERTY "COLLECT_${name}_BASE") 13 | set (${var} "${_base}" PARENT_SCOPE) 14 | endfunction (collector_base) 15 | 16 | function (collect name) 17 | collector_base (_base ${name}) 18 | string(COMPARE NOTEQUAL "${_base}" "" _is_rel) 19 | set (_list) 20 | foreach (s IN LISTS ARGN) 21 | if (_is_rel) 22 | get_filename_component (s "${s}" ABSOLUTE) 23 | file (RELATIVE_PATH s "${_base}" "${s}") 24 | else (_is_rel) 25 | get_filename_component (ts "${s}" ABSOLUTE) 26 | if (EXISTS "${ts}") 27 | set (s "${ts}") 28 | endif (EXISTS "${ts}") 29 | endif (_is_rel) 30 | list (APPEND _list "${s}") 31 | endforeach () 32 | set_property (GLOBAL APPEND PROPERTY "COLLECT_${name}_LIST" "${_list}") 33 | endfunction (collect) 34 | 35 | # Create global collectors 36 | collector_create (PROJECT_INC_DIRS "") 37 | collector_create (PROJECT_LIB_DIRS "") 38 | collector_create (PROJECT_LIB_DEPS "") 39 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/depends.cmake: -------------------------------------------------------------------------------- 1 | if (WITH_DOC) 2 | find_package (Doxygen) 3 | endif (WITH_DOC) 4 | 5 | if (WITH_LIBMETAL_FIND) 6 | find_package (Libmetal REQUIRED) 7 | collect (PROJECT_INC_DIRS "${LIBMETAL_INCLUDE_DIR}") 8 | collect (PROJECT_LIB_DIRS "${LIBMETAL_LIB_DIR}") 9 | collect (PROJECT_LIB_DEPS "${LIBMETAL_LIB}") 10 | endif (WITH_LIBMETAL_FIND) 11 | 12 | if (WITH_OPENAMP_FIND) 13 | find_package (open_amp REQUIRED) 14 | collect (PROJECT_INC_DIRS "${OPENAMP_INCLUDE_DIR}") 15 | collect (PROJECT_LIB_DIRS "${OPENAMP_LIB_DIR}") 16 | collect (PROJECT_LIB_DEPS "${OPENAMP_LIB}") 17 | endif (WITH_OPENAMP_FIND) 18 | 19 | if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 20 | check_include_files (stdatomic.h HAVE_STDATOMIC_H) 21 | check_include_files (fcntl.h HAVE_FCNTL_H) 22 | else ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 23 | set (_saved_cmake_required_flags ${CMAKE_REQUIRED_FLAGS}) 24 | set (CMAKE_REQUIRED_FLAGS "-c") 25 | check_include_files (stdatomic.h HAVE_STDATOMIC_H) 26 | check_include_files (fcntl.h HAVE_FCNTL_H) 27 | set (CMAKE_REQUIRED_FLAGS ${_saved_cmake_required_flags}) 28 | endif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 29 | 30 | if (NOT HAVE_FCNTL_H) 31 | unset (WITH_PROXY CACHE) 32 | endif (NOT HAVE_FCNTL_H) 33 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/modules/FindLibmetal.cmake: -------------------------------------------------------------------------------- 1 | # FindLibmetal 2 | # -------- 3 | # 4 | # Find Libmetal 5 | # 6 | # Find the native Libmetal includes and library this module defines 7 | # 8 | # :: 9 | # 10 | # LIBMETAL_INCLUDE_DIR, where to find metal/sysfs.h, etc. 11 | # LIBSYSFS_LIB_DIR, where to find libmetal library. 12 | 13 | # FIX ME, CMAKE_FIND_ROOT_PATH doesn't work 14 | # even use the following 15 | # set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) 16 | # set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) 17 | # set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) 18 | find_path(LIBMETAL_INCLUDE_DIR NAMES metal/sys.h PATHS ${CMAKE_FIND_ROOT_PATH}) 19 | find_library(LIBMETAL_LIB NAMES metal PATHS ${CMAKE_FIND_ROOT_PATH}) 20 | get_filename_component(LIBMETAL_LIB_DIR ${LIBMETAL_LIB} DIRECTORY) 21 | 22 | # handle the QUIETLY and REQUIRED arguments and set HUGETLBFS_FOUND to TRUE if 23 | # all listed variables are TRUE 24 | include (FindPackageHandleStandardArgs) 25 | FIND_PACKAGE_HANDLE_STANDARD_ARGS (Libmetal DEFAULT_MSG LIBMETAL_LIB LIBMETAL_INCLUDE_DIR) 26 | 27 | if (LIBMETAL_FOUND) 28 | set (LIBMETAL_LIBS ${LIBMETAL_LIB}) 29 | endif (LIBMETAL_FOUND) 30 | 31 | mark_as_advanced (LIBMETAL_LIB LIBMETAL_INCLUDE_DIR LIBMETAL_LIB_DIR) 32 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/modules/Findopen_amp.cmake: -------------------------------------------------------------------------------- 1 | # Findopen_amp 2 | # -------- 3 | # 4 | # Find open_amp 5 | # 6 | # Find the native open_amp includes and library this module defines 7 | # 8 | # :: 9 | # 10 | # OPENAMP_INCLUDE_DIR, where to find metal/sysfs.h, etc. 11 | 12 | # FIX ME, CMAKE_FIND_ROOT_PATH doesn't work 13 | # even use the following 14 | # set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) 15 | # set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) 16 | # set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) 17 | find_path(OPENAMP_INCLUDE_DIR NAMES openamp/ PATHS ${CMAKE_FIND_ROOT_PATH}) 18 | find_library(OPENAMP_LIB NAMES open_amp PATHS ${CMAKE_FIND_ROOT_PATH}) 19 | get_filename_component(OPENAMP_LIB_DIR ${OPENAMP_LIB} DIRECTORY) 20 | 21 | # handle the QUIETLY and REQUIRED arguments and set HUGETLBFS_FOUND to TRUE if 22 | # all listed variables are TRUE 23 | include (FindPackageHandleStandardArgs) 24 | FIND_PACKAGE_HANDLE_STANDARD_ARGS (open_amp DEFAULT_MSG OPENAMP_LIB OPENAMP_INCLUDE_DIR) 25 | 26 | if (OPENAMP_FOUND) 27 | set (OPENAMP_LIBS ${OPENAMP_LIB}) 28 | endif (OPENAMP_FOUND) 29 | 30 | mark_as_advanced (OPENAMP_LIB OPENAMP_INCLUDE_DIR OPENAMP_LIB_DIR) 31 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/options.cmake: -------------------------------------------------------------------------------- 1 | if (NOT DEFINED CMAKE_BUILD_TYPE) 2 | set (CMAKE_BUILD_TYPE Debug) 3 | endif (NOT DEFINED CMAKE_BUILD_TYPE) 4 | 5 | if (NOT CMAKE_INSTALL_LIBDIR) 6 | set (CMAKE_INSTALL_LIBDIR "lib") 7 | endif (NOT CMAKE_INSTALL_LIBDIR) 8 | 9 | if (NOT CMAKE_INSTALL_BINDIR) 10 | set (CMAKE_INSTALL_BINDIR "bin") 11 | endif (NOT CMAKE_INSTALL_BINDIR) 12 | 13 | set (_host "${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR}") 14 | message ("-- Host: ${_host}") 15 | 16 | set (_target "${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}") 17 | message ("-- Target: ${_target}") 18 | 19 | if (NOT DEFINED MACHINE) 20 | set (MACHINE "Generic") 21 | endif (NOT DEFINED MACHINE) 22 | message ("-- Machine: ${MACHINE}") 23 | 24 | string (TOLOWER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM) 25 | string (TOUPPER ${CMAKE_SYSTEM_NAME} PROJECT_SYSTEM_UPPER) 26 | string (TOLOWER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR) 27 | string (TOUPPER ${CMAKE_SYSTEM_PROCESSOR} PROJECT_PROCESSOR_UPPER) 28 | string (TOLOWER ${MACHINE} PROJECT_MACHINE) 29 | string (TOUPPER ${MACHINE} PROJECT_MACHINE_UPPER) 30 | 31 | # Select which components are in the openamp lib 32 | option (WITH_PROXY "Build with proxy(access device controlled by other processor)" ON) 33 | option (WITH_APPS "Build with sample applications" OFF) 34 | option (WITH_PROXY_APPS "Build with proxy sample applications" OFF) 35 | if (WITH_APPS) 36 | if (WITH_PROXY) 37 | set (WITH_PROXY_APPS ON) 38 | endif (WITH_PROXY) 39 | endif (WITH_APPS) 40 | 41 | # LOAD_FW only allowed for R5, otherwise turn off 42 | if (NOT ${MACHINE} STREQUAL "zynqmp_r5") 43 | set (WITH_LOAD_FW OFF) 44 | endif(NOT ${MACHINE} STREQUAL "zynqmp_r5") 45 | 46 | option (WITH_VIRTIO_DRIVER "Build with virtio driver (front end) enabled" ON) 47 | option (WITH_VIRTIO_DEVICE "Build with virtio device (back end) enabled" ON) 48 | 49 | 50 | if (NOT WITH_VIRTIO_DRIVER) 51 | add_definitions(-DVIRTIO_DRIVER_SUPPORT=0) 52 | else (NOT WITH_VIRTIO_DRIVER) 53 | add_definitions(-DVIRTIO_DRIVER_SUPPORT=1) 54 | endif (NOT WITH_VIRTIO_DRIVER) 55 | 56 | if (NOT WITH_VIRTIO_DEVICE) 57 | add_definitions(-DVIRTIO_DEVICE_SUPPORT=0) 58 | else (NOT WITH_VIRTIO_DEVICE) 59 | add_definitions(-DVIRTIO_DEVICE_SUPPORT=1) 60 | endif (NOT WITH_VIRTIO_DEVICE) 61 | 62 | option (WITH_VIRTIO_MMIO_DRV "Build with virtio mmio driver support enabled" OFF) 63 | 64 | if (WITH_VIRTIO_MMIO_DRV) 65 | add_definitions(-DWITH_VIRTIO_MMIO_DRV) 66 | endif (WITH_VIRTIO_MMIO_DRV) 67 | 68 | option (WITH_DCACHE "Build with all cache operations enabled" OFF) 69 | 70 | if (WITH_DCACHE) 71 | add_definitions(-DVIRTIO_USE_DCACHE) 72 | endif (WITH_DCACHE) 73 | 74 | option (WITH_DCACHE_VRINGS "Build with vrings cache operations enabled" OFF) 75 | 76 | if (WITH_DCACHE_VRINGS) 77 | add_definitions(-DVIRTIO_CACHED_VRINGS) 78 | message(DEPRECATION "deprecated cmake option replaced by WITH_DCACHE" ...) 79 | endif (WITH_DCACHE_VRINGS) 80 | 81 | option (WITH_DCACHE_BUFFERS "Build with buffers cache operations enabled" OFF) 82 | 83 | if (WITH_DCACHE_BUFFERS) 84 | add_definitions(-DVIRTIO_CACHED_BUFFERS) 85 | message(DEPRECATION "deprecated cmake option replaced by WITH_DCACHE" ...) 86 | endif (WITH_DCACHE_BUFFERS) 87 | 88 | option (WITH_DCACHE_RSC_TABLE "Build with resource table cache operations enabled" OFF) 89 | 90 | if (WITH_DCACHE_RSC_TABLE) 91 | add_definitions(-DVIRTIO_CACHED_RSC_TABLE) 92 | message(DEPRECATION "deprecated cmake option replaced by WITH_DCACHE" ...) 93 | endif (WITH_DCACHE_RSC_TABLE) 94 | 95 | # Set the complication flags 96 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") 97 | 98 | option (WITH_STATIC_LIB "Build with a static library" ON) 99 | 100 | if ("${PROJECT_SYSTEM}" STREQUAL "linux") 101 | option (WITH_SHARED_LIB "Build with a shared library" ON) 102 | endif ("${PROJECT_SYSTEM}" STREQUAL "linux") 103 | 104 | if (WITH_ZEPHYR) 105 | option (WITH_ZEPHYR_LIB "Build open-amp as a zephyr library" OFF) 106 | endif (WITH_ZEPHYR) 107 | 108 | option (WITH_LIBMETAL_FIND "Check Libmetal library can be found" ON) 109 | 110 | option (WITH_OPENAMP_FIND "Check libopen_amp library can be found" ON) 111 | 112 | if (DEFINED RPMSG_BUFFER_SIZE) 113 | add_definitions( -DRPMSG_BUFFER_SIZE=${RPMSG_BUFFER_SIZE} ) 114 | endif (DEFINED RPMSG_BUFFER_SIZE) 115 | 116 | option (WITH_DOC "Build with documentation" OFF) 117 | 118 | message ("-- C_FLAGS : ${CMAKE_C_FLAGS}") 119 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/platforms/cross_generic_gcc.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") 2 | 3 | set (CMAKE_C_COMPILER "${CROSS_PREFIX}gcc") 4 | set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") 5 | # _exit is in the BSP rather than in libgcc, leaving this out 6 | # causes errors in try_compile on ARM generic. 7 | set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 8 | 9 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "") 10 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER CACHE STRING "") 11 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER CACHE STRING "") 12 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/platforms/cross_linux_gcc.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_NAME "Linux") 2 | set (CMAKE_C_COMPILER "${CROSS_PREFIX}gcc") 3 | set (CMAKE_CXX_COMPILER "${CROSS_PREFIX}g++") 4 | 5 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 6 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 7 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 8 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/platforms/zynqmp_a53_generic.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm64") 2 | set (CROSS_PREFIX "aarch64-none-elf-") 3 | 4 | include (cross_generic_gcc) 5 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/platforms/zynqmp_linux.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm64") 2 | set (CROSS_PREFIX "aarch64-linux-gnu-") 3 | set (MACHINE "zynqmp" CACHE STRING "") 4 | 5 | include (cross_linux_gcc) 6 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/platforms/zynqmp_r5_generic.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_PROCESSOR "arm" CACHE STRING "") 2 | set (MACHINE "zynqmp_r5" CACHE STRING "") 3 | set (CROSS_PREFIX "armr5-none-eabi-" CACHE STRING "") 4 | 5 | # Xilinx SDK version earlier than 2017.2 use mfloat-abi=soft by default to generate libxil 6 | set (CMAKE_C_FLAGS "-mfloat-abi=hard -mfpu=vfpv3-d16 -mcpu=cortex-r5" CACHE STRING "") 7 | 8 | include (cross_generic_gcc) 9 | -------------------------------------------------------------------------------- /examples/legacy_apps/cmake/syscheck.cmake: -------------------------------------------------------------------------------- 1 | # use "Generic" as CMAKE_SYSTEM_NAME 2 | 3 | if (WITH_ZEPHYR) 4 | set (CMAKE_SYSTEM_NAME "Generic" CACHE STRING "") 5 | string (TOLOWER "Zephyr" PROJECT_SYSTEM) 6 | string (TOUPPER "Zephyr" PROJECT_SYSTEM_UPPER) 7 | if (NOT WITH_ZEPHYR_LIB) 8 | include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) 9 | endif () 10 | if (CONFIG_CPU_CORTEX_M) 11 | set (MACHINE "cortexm" CACHE STRING "") 12 | endif (CONFIG_CPU_CORTEX_M) 13 | endif (WITH_ZEPHYR) 14 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | option (WITH_LOAD_FW "Include loading firmware example" OFF) 3 | 4 | if (MACHINE MATCHES ".*microblaze.*") 5 | add_subdirectory (echo) 6 | else () 7 | add_subdirectory (echo) 8 | add_subdirectory (nocopy_echo) 9 | add_subdirectory (rpmsg_sample_echo) 10 | add_subdirectory (matrix_multiply) 11 | if (WITH_LOAD_FW) 12 | add_subdirectory (load_fw) 13 | endif (WITH_LOAD_FW) 14 | 15 | if (WITH_PROXY_APPS) 16 | add_subdirectory (rpc_demo) 17 | add_subdirectory (linux_rpc_demo) 18 | endif (WITH_PROXY_APPS) 19 | endif (MACHINE MATCHES ".*microblaze.*") 20 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/echo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app rpmsg-echo-ping rpmsg-echo) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | if (${_app} STREQUAL "rpmsg-echo-ping") 21 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-ping.c") 22 | elseif (${_app} STREQUAL "rpmsg-echo") 23 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-echo.c") 24 | endif (${_app} STREQUAL "rpmsg-echo-ping") 25 | 26 | if (WITH_SHARED_LIB) 27 | add_executable (${_app}-shared ${_sources}) 28 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 29 | target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) 30 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 31 | endif (WITH_SHARED_LIB) 32 | 33 | if (WITH_STATIC_LIB) 34 | if (${PROJECT_SYSTEM} STREQUAL "linux") 35 | add_executable (${_app}-static ${_sources}) 36 | target_compile_options (${_app}-static PRIVATE "-static") 37 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 38 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 39 | else (${PROJECT_SYSTEM}) 40 | add_executable (${_app}.out ${_sources}) 41 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 42 | 43 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 44 | 45 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 46 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 47 | endif (WITH_STATIC_LIB) 48 | endforeach(_app) 49 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/echo/README.rst: -------------------------------------------------------------------------------- 1 | Overview 2 | ******** 3 | 4 | This readme is about the OpenAMP echo demonstration. 5 | The echo test is about one processor sending a message to the other one, and the other one echoing 6 | back the message. The processor that sends the message will verify the echoed message. 7 | 8 | Compilation 9 | *********** 10 | 11 | See `README.md <../../README.md>`_ for details. 12 | 13 | Run demonstration on a Linux PC 14 | ******************************* 15 | 16 | It is possible to run the application on a Linux PC to communicate between two Linux processes. 17 | 18 | .. code-block:: shell 19 | 20 | cd $PROJECT_ROOT/target 21 | LD_LIBRARY_PATH=./lib ./bin/rpmsg-echo-static & 22 | sleep 1 23 | LD_LIBRARY_PATH=./lib ./bin/msg-test-rpmsg-ping-static 1 24 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/echo/rpmsg-echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | /* 6 | * This is a sample demonstration application that showcases usage of rpmsg 7 | * This application is meant to run on the remote CPU running baremetal code. 8 | * This application echoes back data that was sent to it by the host core. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "platform_info.h" 17 | #include "rpmsg-echo.h" 18 | 19 | #define SHUTDOWN_MSG 0xEF56A55A 20 | 21 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 22 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 23 | 24 | static struct rpmsg_endpoint lept; 25 | static int shutdown_req = 0; 26 | 27 | /*-----------------------------------------------------------------------------* 28 | * RPMSG endpoint callbacks 29 | *-----------------------------------------------------------------------------*/ 30 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 31 | uint32_t src, void *priv) 32 | { 33 | (void)priv; 34 | (void)src; 35 | 36 | /* On reception of a shutdown we signal the application to terminate */ 37 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 38 | LPRINTF("shutdown message is received.\r\n"); 39 | shutdown_req = 1; 40 | return RPMSG_SUCCESS; 41 | } 42 | 43 | /* Send data back to host */ 44 | if (rpmsg_send(ept, data, len) < 0) { 45 | LPERROR("rpmsg_send failed\r\n"); 46 | } 47 | return RPMSG_SUCCESS; 48 | } 49 | 50 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 51 | { 52 | (void)ept; 53 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 54 | shutdown_req = 1; 55 | } 56 | 57 | /*-----------------------------------------------------------------------------* 58 | * Application 59 | *-----------------------------------------------------------------------------*/ 60 | int app(struct rpmsg_device *rdev, void *priv) 61 | { 62 | int ret; 63 | 64 | /* Initialize RPMSG framework */ 65 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 66 | 67 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 68 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 69 | rpmsg_endpoint_cb, 70 | rpmsg_service_unbind); 71 | if (ret) { 72 | LPERROR("Failed to create endpoint.\r\n"); 73 | return -1; 74 | } 75 | 76 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 77 | 78 | LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept)); 79 | LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept)); 80 | 81 | while(1) { 82 | platform_poll(priv); 83 | /* we got a shutdown request, exit */ 84 | if (shutdown_req) { 85 | break; 86 | } 87 | } 88 | rpmsg_destroy_ept(&lept); 89 | 90 | return 0; 91 | } 92 | 93 | /*-----------------------------------------------------------------------------* 94 | * Application entry point 95 | *-----------------------------------------------------------------------------*/ 96 | int main(int argc, char *argv[]) 97 | { 98 | void *platform; 99 | struct rpmsg_device *rpdev; 100 | int ret; 101 | 102 | LPRINTF("openamp lib version: %s (", openamp_version()); 103 | LPRINTF("Major: %d, ", openamp_version_major()); 104 | LPRINTF("Minor: %d, ", openamp_version_minor()); 105 | LPRINTF("Patch: %d)\r\n", openamp_version_patch()); 106 | 107 | LPRINTF("libmetal lib version: %s (", metal_ver()); 108 | LPRINTF("Major: %d, ", metal_ver_major()); 109 | LPRINTF("Minor: %d, ", metal_ver_minor()); 110 | LPRINTF("Patch: %d)\r\n", metal_ver_patch()); 111 | 112 | LPRINTF("Starting application...\r\n"); 113 | 114 | /* Initialize platform */ 115 | ret = platform_init(argc, argv, &platform); 116 | if (ret) { 117 | LPERROR("Failed to initialize platform.\r\n"); 118 | ret = -1; 119 | } else { 120 | rpdev = platform_create_rpmsg_vdev(platform, 0, 121 | VIRTIO_DEV_DEVICE, 122 | NULL, NULL); 123 | if (!rpdev) { 124 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 125 | ret = -1; 126 | } else { 127 | app(rpdev, platform); 128 | platform_release_rpmsg_vdev(rpdev, platform); 129 | ret = 0; 130 | } 131 | } 132 | 133 | LPRINTF("Stopping application...\r\n"); 134 | platform_cleanup(platform); 135 | 136 | return ret; 137 | } 138 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/echo/rpmsg-echo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | #ifndef RPMSG_ECHO_H 6 | #define RPMSG_ECHO_H 7 | 8 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 9 | 10 | #endif /* RPMSG_ECHO_H */ 11 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/linux_rpc_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS}") 2 | set (_fw_dir "${APPS_SHARE_DIR}") 3 | 4 | collector_list (_list PROJECT_INC_DIRS) 5 | collector_list (_app_list APP_INC_DIRS) 6 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 7 | 8 | collector_list (_list PROJECT_LIB_DIRS) 9 | collector_list (_app_list APP_LIB_DIRS) 10 | link_directories (${_list} ${_app_list}) 11 | 12 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_LARGE_TEXT_OPT) 13 | if (NOT _linker_opt) 14 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 15 | endif (NOT _linker_opt) 16 | collector_list (_deps PROJECT_LIB_DEPS) 17 | 18 | set (OPENAMP_LIB open_amp) 19 | 20 | if (${PROJECT_SYSTEM} STREQUAL "linux") 21 | set (app_list linux_rpc_demod linux_rpc_demo) 22 | endif (${PROJECT_SYSTEM} STREQUAL "linux") 23 | 24 | foreach (_app ${app_list}) 25 | collector_list (_sources APP_COMMON_SOURCES) 26 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 27 | 28 | if (WITH_SHARED_LIB) 29 | add_executable (${_app}-shared ${_sources}) 30 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 31 | target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) 32 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 33 | endif (WITH_SHARED_LIB) 34 | 35 | if (WITH_STATIC_LIB) 36 | if (${PROJECT_SYSTEM} STREQUAL "linux") 37 | add_executable (${_app}-static ${_sources}) 38 | target_compile_options (${_app}-static PRIVATE "-static") 39 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 40 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 41 | else (${PROJECT_SYSTEM}) 42 | add_executable (${_app}.out ${_sources}) 43 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 44 | 45 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 46 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 47 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 48 | endif (WITH_STATIC_LIB) 49 | endforeach(_app) 50 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/linux_rpc_demo/README.rst: -------------------------------------------------------------------------------- 1 | This readme is about the OpenAMP linux_rpc_demo. 2 | 3 | The linux_rpc_demo is about remote procedure calls between linux host and a linux 4 | remote using rpmsg to perform 5 | 1. File operations such as open, read, write and close 6 | 2. I/O operation such as printf, scanf 7 | 8 | Compilation 9 | *********** 10 | Add cmake option `-DWITH_PROXY_APPS=ON` to build the system reference demonstration applications. 11 | 12 | See `README.md <../../README.md>`_ for details. 13 | 14 | Run demonstration on a Linux PC 15 | ******************************* 16 | 17 | * Start rpc demo server on one console 18 | 19 | .. code-block:: shell 20 | 21 | sudo LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib \ 22 | build-openamp/usr/local/bin/linux_rpc_demod-shared 23 | 24 | * Run rpc demo client on another console to perform file and I/O operations on the server 25 | 26 | .. code-block:: shell 27 | 28 | sudo LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib \ 29 | build-openamp/usr/local/bin/linux_rpc_demo-shared 1 30 | 31 | Enter the inputs on the host side the same gets printed on the remote side. You will see 32 | communication between the host and remote process using rpmsg calls. 33 | 34 | Note: 35 | ***** 36 | `sudo` is required to run the OpenAMP demos between Linux processes, as it doesn't work on 37 | some systems if you are normal users. 38 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/linux_rpc_demo/linux-rpmsg-rpc-demo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, L&T Technology Services Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #ifndef RPMSG_RPC_DEMO_H 9 | #define RPMSG_RPC_DEMO_H 10 | 11 | #define OPEN_ID 0x1UL 12 | #define CLOSE_ID 0x2UL 13 | #define WRITE_ID 0x3UL 14 | #define READ_ID 0x4UL 15 | #define ACK_STATUS_ID 0x5UL 16 | #define TERM_ID 0x6UL 17 | #define INPUT_ID 0x7UL 18 | #define MAX_STRING_LEN 300 19 | #define MAX_FILE_NAME_LEN 10 20 | 21 | typedef int (*rpmsg_rpc_poll)(void *arg); 22 | 23 | struct polling { 24 | rpmsg_rpc_poll poll; 25 | void *poll_arg; 26 | }; 27 | 28 | struct rpmsg_rpc_req_open { 29 | char filename[MAX_FILE_NAME_LEN]; 30 | int flags; 31 | int mode; 32 | }; 33 | 34 | struct rpmsg_rpc_req_read { 35 | int fd; 36 | uint32_t buflen; 37 | }; 38 | 39 | struct rpmsg_rpc_req_input { 40 | uint32_t buflen; 41 | }; 42 | 43 | struct rpmsg_rpc_req_write { 44 | int fd; 45 | uint32_t len; 46 | char ptr[MAX_STRING_LEN]; 47 | }; 48 | 49 | struct rpmsg_rpc_req_close { 50 | int fd; 51 | }; 52 | 53 | struct rpmsg_rpc_req_term { 54 | int id; 55 | }; 56 | 57 | struct rpmsg_rpc_resp_open { 58 | int fd; 59 | }; 60 | 61 | struct rpmsg_rpc_resp_read { 62 | int bytes_read; 63 | char buf[MAX_STRING_LEN]; 64 | }; 65 | 66 | struct rpmsg_rpc_resp_input { 67 | int bytes_read; 68 | char buf[MAX_STRING_LEN]; 69 | }; 70 | 71 | struct rpmsg_rpc_resp_write { 72 | int bytes_written; 73 | }; 74 | 75 | struct rpmsg_rpc_resp_close { 76 | int close_ret; 77 | }; 78 | 79 | #endif /* RPMSG_RPC_DEMO_H */ 80 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collector_list (_app_extra_c_flags APP_EXTRA_C_FLAGS) 2 | set (_cflags "${CMAKE_C_FLAGS} ${_app_extra_c_flags}") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collect (PROJECT_LIB_DEPS xilpm) 15 | collector_list (_deps PROJECT_LIB_DEPS) 16 | 17 | set (OPENAMP_LIB open_amp) 18 | 19 | foreach (_app load_fw) 20 | collector_list (_sources APP_COMMON_SOURCES) 21 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/mem_image_store.c") 22 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_apu_lcm_rproc_example.c") 23 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_rpu_lcm_rproc_example.c") 24 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/platform_info.c") 25 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 26 | 27 | if (WITH_STATIC_LIB) 28 | add_executable (${_app}.out ${_sources}) 29 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 30 | 31 | target_compile_options (${_app}.out PRIVATE "-static") 32 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections -T"${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld" -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group) 33 | 34 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 35 | endif (WITH_STATIC_LIB) 36 | endforeach(_app) 37 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #ifndef COMMON_H_ 9 | #define COMMON_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | /* Xilinx headers */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef versal 27 | #include 28 | #include 29 | 30 | #ifndef NODE_APU_0 31 | #define NODE_APU_0 PM_DEV_ACPU_0 32 | #endif 33 | #ifndef NODE_APU_1 34 | #define NODE_APU_1 PM_DEV_ACPU_1 35 | #endif 36 | #ifndef NODE_RPU_0 37 | #define NODE_RPU_0 PM_DEV_RPU0_0 38 | #endif 39 | #ifndef NODE_RPU 40 | #define NODE_RPU PM_DEV_RPU0_0 41 | #endif 42 | 43 | #ifndef NODE_RPU_1 44 | #define NODE_RPU_1 PM_DEV_RPU0_1 45 | #endif 46 | 47 | #ifndef NODE_TCM_0_A 48 | #define NODE_TCM_0_A PM_DEV_TCM_0_A 49 | #endif 50 | #ifndef NODE_TCM_0_B 51 | #define NODE_TCM_0_B PM_DEV_TCM_0_B 52 | #endif 53 | #ifndef NODE_TCM_1_A 54 | #define NODE_TCM_1_A PM_DEV_TCM_1_A 55 | #endif 56 | #ifndef NODE_TCM_1_B 57 | #define NODE_TCM_1_B PM_DEV_TCM_1_B 58 | #endif 59 | 60 | #ifndef NODE_DDR 61 | #define NODE_DDR PM_DEV_DDR_0 62 | #endif 63 | 64 | #ifndef NODE_OCM_BANK_0 65 | #define NODE_OCM_BANK_0 PM_DEV_OCM_0 66 | #endif 67 | #ifndef NODE_OCM_BANK_1 68 | #define NODE_OCM_BANK_1 PM_DEV_OCM_1 69 | #endif 70 | #ifndef NODE_OCM_BANK_2 71 | #define NODE_OCM_BANK_2 PM_DEV_OCM_2 72 | #endif 73 | #ifndef NODE_OCM_BANK_3 74 | #define NODE_OCM_BANK_3 PM_DEV_OCM_3 75 | #endif 76 | 77 | /* Requirement limits */ 78 | #define XPM_MAX_CAPABILITY (PM_CAP_ACCESS | PM_CAP_CONTEXT | PM_CAP_WAKEUP) 79 | #define XPM_MAX_LATENCY (0xFFFFU) 80 | #define XPM_MAX_QOS (100) 81 | #define XPM_MIN_CAPABILITY (0) 82 | #define XPM_MIN_LATENCY (0) 83 | #define XPM_MIN_QOS (0) 84 | #define XPM_DEF_CAPABILITY XPM_MAX_CAPABILITY 85 | #define XPM_DEF_LATENCY XPM_MAX_LATENCY 86 | #define XPM_DEF_QOS XPM_MAX_QOS 87 | 88 | enum XPmRequestAck { 89 | REQUEST_ACK_NO = 1, 90 | REQUEST_ACK_BLOCKING, 91 | REQUEST_ACK_NON_BLOCKING, 92 | REQUEST_ACK_CB_CERROR, 93 | }; 94 | 95 | #else /* zynqmp */ 96 | #include 97 | #define XPM_MAX_QOS MAX_QOS 98 | #define XPM_MIN_QOS (0) 99 | #endif /* versal */ 100 | 101 | #define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__) 102 | //#define LPRINTF(format, ...) 103 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 104 | 105 | struct rproc_priv { 106 | struct remoteproc *rproc; 107 | int cpu_id; 108 | }; 109 | 110 | #endif /* COMMON_H_ */ 111 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/load_fw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Load firmware example 3 | * 4 | * Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved. 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #include "platform_info.h" 9 | #include 10 | 11 | extern const struct image_store_ops mem_image_store_ops; 12 | 13 | struct mem_file { 14 | const void *base; 15 | }; 16 | 17 | static struct mem_file image = { 18 | .base = (void *)0x3ED00000, 19 | }; 20 | 21 | int load_exectuable_block(struct remoteproc *rproc, 22 | const struct image_store_ops *store_ops, void *store, 23 | const char *img_path) 24 | { 25 | int ret; 26 | 27 | (void)img_path; 28 | if (rproc == NULL) 29 | return -EINVAL; 30 | /* Configure remoteproc to get ready to load executable */ 31 | remoteproc_config(rproc, NULL); 32 | 33 | /* Load remoteproc executable */ 34 | LPRINTF("Start to load executable with remoteproc_load() \r\n"); 35 | ret = remoteproc_load(rproc, NULL, store, store_ops, NULL); 36 | if (ret) { 37 | LPRINTF("failed to load firmware\r\n"); 38 | return ret; 39 | } 40 | /* Start the processor */ 41 | ret = remoteproc_start(rproc); 42 | if (ret) { 43 | LPRINTF("failed to start processor\r\n"); 44 | return ret; 45 | } 46 | LPRINTF("successfully started the processor\r\n"); 47 | #ifndef RPU_BOOT_LINUX 48 | /* ... */ 49 | asm volatile("wfi"); 50 | LPRINTF("going to stop the processor\r\n"); 51 | remoteproc_stop(rproc); 52 | /* application may want to do some cleanup before shutdown */ 53 | LPRINTF("going to shutdown the processor\r\n"); 54 | remoteproc_shutdown(rproc); 55 | #endif /* RPU_BOOT_LINUX */ 56 | return 0; 57 | } 58 | 59 | #ifndef RPU_BOOT_LINUX 60 | int load_exectuable_noblock(struct remoteproc *rproc, 61 | const struct image_store_ops *store_ops, 62 | void *store, const char *img_path) 63 | { 64 | int ret; 65 | const void *img_data; 66 | void *img_info = NULL; 67 | metal_phys_addr_t pa; 68 | struct metal_io_region *io; 69 | size_t offset, noffset; 70 | size_t len, nlen, nmlen; 71 | unsigned char padding; 72 | 73 | if (rproc == NULL) 74 | return -EINVAL; 75 | /* Configure remoteproc to get ready to load executable */ 76 | remoteproc_config(rproc, NULL); 77 | /* Load remoteproc executable */ 78 | LPRINTF("Start to load executable with remoteproc_load() \r\n"); 79 | ret = store_ops->open(store, img_path, &img_data); 80 | if (ret <= 0) 81 | return -EINVAL; 82 | offset = 0; 83 | len = (size_t)ret; 84 | do { 85 | nlen = 0; 86 | pa = METAL_BAD_PHYS; 87 | io = NULL; 88 | nmlen = 0; 89 | LPRINTF("%s, loading 0x%lx,0x%lx\r\n", 90 | __func__, offset, len); 91 | ret = remoteproc_load_noblock(rproc, img_data, offset, len, 92 | &img_info, &pa, &io, &noffset, 93 | &nlen, &nmlen, &padding); 94 | if (ret) { 95 | LPERROR("failed to load executable, 0x%lx,0x%lx\r\n", 96 | offset, len); 97 | return ret; 98 | } 99 | if (nlen == 0 && nmlen == 0) 100 | break; 101 | offset = noffset; 102 | len = nlen; 103 | ret = store_ops->load(store, noffset, nlen, &img_data, pa, 104 | io, 1); 105 | if (ret != (int)nlen) { 106 | LPERROR("failed to load data to memory, 0x%lx,0x%lx\r\n", 107 | noffset, nlen); 108 | return ret; 109 | } 110 | if (nmlen > nlen && io != NULL) { 111 | /* pad the rest of the memory with 0 */ 112 | size_t tmpoffset; 113 | 114 | tmpoffset = metal_io_phys_to_offset(io, pa + nlen); 115 | metal_io_block_set(io, tmpoffset, padding, 116 | (nmlen - nlen)); 117 | 118 | } 119 | } while(1); 120 | 121 | /* Start the processor */ 122 | ret = remoteproc_start(rproc); 123 | if (ret) { 124 | LPRINTF("failed to start processor\r\n"); 125 | return ret; 126 | } 127 | LPRINTF("successfully started the processor\r\n"); 128 | /* ... */ 129 | asm volatile("wfi"); 130 | LPRINTF("going to stop the processor\r\n"); 131 | remoteproc_stop(rproc); 132 | /* application may want to do some cleanup before shutdown */ 133 | LPRINTF("going to shutdown the processor\r\n"); 134 | remoteproc_shutdown(rproc); 135 | return 0; 136 | } 137 | #endif /* RPU_BOOT_LINUX */ 138 | 139 | int main(void) 140 | { 141 | struct remoteproc *rproc = NULL; 142 | void *store = ℑ 143 | unsigned int cpu_id = LOAD_FW_TARGET; 144 | int ret; 145 | 146 | LPRINTF("Loading Executable Demo\n"); 147 | rproc = app_init(cpu_id); 148 | if (!rproc) { 149 | LPERROR("app_init failed\r\n"); 150 | return -1; 151 | } 152 | ret = load_exectuable_block(rproc, &mem_image_store_ops, store, NULL); 153 | if (ret < 0) { 154 | LPERROR("load_exectuable_block failed\r\n"); 155 | /* Make sure the remote is shut down */ 156 | remoteproc_shutdown(rproc); 157 | return -1; 158 | } 159 | #ifndef RPU_BOOT_LINUX 160 | ret = load_exectuable_noblock(rproc, &mem_image_store_ops, store, 161 | NULL); 162 | if (ret < 0) { 163 | LPERROR("load_exectuable_noblock failed\r\n"); 164 | /* Make sure the remote is shut down */ 165 | remoteproc_shutdown(rproc); 166 | return -1; 167 | } 168 | #endif /* RPU_BOOT_LINUX */ 169 | remoteproc_remove(rproc); 170 | return ret; 171 | } 172 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/mem_image_store.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory based image store Operation 3 | * 4 | * Copyright(c) 2018 Xilinx Ltd. 5 | * All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | struct mem_file { 14 | const void *base; 15 | }; 16 | 17 | int mem_image_open(void *store, const char *path, const void **image_data) 18 | { 19 | struct mem_file *image = store; 20 | const void *fw_base = image->base; 21 | 22 | (void)(path); 23 | if (image_data == NULL) { 24 | LPERROR("%s: input image_data is NULL\r\n", __func__); 25 | return -EINVAL; 26 | } 27 | *image_data = fw_base; 28 | /* return an abitrary length, as the whole firmware is in memory */ 29 | return 0x100; 30 | } 31 | 32 | void mem_image_close(void *store) 33 | { 34 | /* The image is in memory, does nothing */ 35 | (void)store; 36 | } 37 | 38 | int mem_image_load(void *store, size_t offset, size_t size, 39 | const void **data, metal_phys_addr_t pa, 40 | struct metal_io_region *io, 41 | char is_blocking) 42 | { 43 | struct mem_file *image = store; 44 | const void *fw_base = image->base; 45 | 46 | (void)is_blocking; 47 | 48 | LPRINTF("%s: offset=0x%x, size=0x%x\n\r", 49 | __func__, offset, size); 50 | if (pa == METAL_BAD_PHYS) { 51 | if (data == NULL) { 52 | LPERROR("%s: data is NULL while pa is ANY\r\n", 53 | __func__); 54 | return -EINVAL; 55 | } 56 | *data = (const void *)((const char *)fw_base + offset); 57 | } else { 58 | void *va; 59 | 60 | if (io == NULL) { 61 | LPERROR("%s, io is NULL while pa is not ANY\r\n", 62 | __func__); 63 | return -EINVAL; 64 | } 65 | va = metal_io_phys_to_virt(io, pa); 66 | if (va == NULL) { 67 | LPERROR("%s: no va is found\r\n", __func__); 68 | return -EINVAL; 69 | } 70 | memcpy(va, (const void *)((const char *)fw_base + offset), size); 71 | } 72 | 73 | return (int)size; 74 | } 75 | 76 | const struct image_store_ops mem_image_store_ops = { 77 | .open = mem_image_open, 78 | .close = mem_image_close, 79 | .load = mem_image_load, 80 | .features = SUPPORT_SEEK, 81 | }; 82 | 83 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/platform_info.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | extern const struct remoteproc_ops zynqmp_apu_rproc_ops; 12 | extern const struct remoteproc_ops zynqmp_rpu_rproc_ops; 13 | 14 | static struct remoteproc rproc_inst; 15 | 16 | static struct remoteproc * platform_create_proc(unsigned int cpu_id) 17 | { 18 | const struct remoteproc_ops *ops; 19 | struct remoteproc * rproc; 20 | if (NODE_RPU_0 <= LOAD_FW_TARGET && LOAD_FW_TARGET <= NODE_RPU_1) 21 | ops = &zynqmp_rpu_rproc_ops; 22 | else if (NODE_APU_0 <= LOAD_FW_TARGET && LOAD_FW_TARGET <= NODE_APU_1) 23 | ops = &zynqmp_apu_rproc_ops; 24 | else 25 | return NULL; 26 | 27 | rproc = remoteproc_init(&rproc_inst, ops, &cpu_id); 28 | if (!rproc) 29 | return NULL; 30 | return &rproc_inst; 31 | } 32 | 33 | static void app_log_handler(enum metal_log_level level, 34 | const char *format, ...) 35 | { 36 | char msg[1024]; 37 | va_list args; 38 | static const char *level_strs[] = { 39 | "metal: emergency: ", 40 | "metal: alert: ", 41 | "metal: critical: ", 42 | "metal: error: ", 43 | "metal: warning: ", 44 | "metal: notice: ", 45 | "metal: info: ", 46 | "metal: debug: ", 47 | }; 48 | 49 | va_start(args, format); 50 | vsnprintf(msg, sizeof(msg), format, args); 51 | va_end(args); 52 | 53 | if (level <= METAL_LOG_EMERGENCY || level > METAL_LOG_DEBUG) 54 | level = METAL_LOG_EMERGENCY; 55 | 56 | xil_printf("%s%s", level_strs[level], msg); 57 | } 58 | 59 | static XIpiPsu IpiInst; 60 | 61 | static XStatus IpiConfigure(XIpiPsu *const IpiInstPtr) 62 | { 63 | XStatus Status; 64 | XIpiPsu_Config *IpiCfgPtr; 65 | 66 | /* Look Up the config data */ 67 | IpiCfgPtr = XIpiPsu_LookupConfig(XPAR_XIPIPSU_0_DEVICE_ID); 68 | if (NULL == IpiCfgPtr) { 69 | Status = XST_FAILURE; 70 | LPERROR("%s ERROR in getting CfgPtr\n", __func__); 71 | return Status; 72 | } 73 | 74 | /* Init with the Cfg Data */ 75 | Status = XIpiPsu_CfgInitialize(IpiInstPtr, IpiCfgPtr, 76 | IpiCfgPtr->BaseAddress); 77 | if (XST_SUCCESS != Status) { 78 | LPERROR("%s ERROR #%d in configuring IPI\n", __func__, Status); 79 | return Status; 80 | } 81 | return Status; 82 | } 83 | 84 | struct remoteproc * app_init(unsigned int cpu_id){ 85 | struct metal_init_params metal_param = { 86 | .log_handler = app_log_handler, 87 | .log_level = METAL_LOG_DEBUG, 88 | }; 89 | metal_init(&metal_param); 90 | 91 | if (XST_SUCCESS != IpiConfigure(&IpiInst)) { 92 | LPERROR("Failed to config IPI instance\r\n"); 93 | return NULL; 94 | } 95 | 96 | if (XST_SUCCESS != XPm_InitXilpm(&IpiInst)) { 97 | LPERROR("Failed to initialize PM\r\n"); 98 | return NULL; 99 | } 100 | 101 | 102 | return platform_create_proc(cpu_id); 103 | } 104 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Xilinx Ltd. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | #ifndef PLATFORM_INFO_H_ 8 | #define PLATFORM_INFO_H_ 9 | 10 | struct remoteproc * app_init(unsigned int cpu_id); 11 | #endif /* PLATFORM_INFO_H_ */ 12 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/load_fw/zynqmp_apu_lcm_rproc_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ZynqMP APU life cycle management remoteproc example implementation 3 | * 4 | * Copyright(c) 2019 Xilinx Ltd. 5 | * All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include 11 | 12 | static struct remoteproc *apu_rproc_init(struct remoteproc *rproc, 13 | const struct remoteproc_ops *ops, void *arg) 14 | { 15 | struct rproc_priv *priv; 16 | unsigned int cpu_id = *((unsigned int *)arg); 17 | if(cpu_id < NODE_APU_0 || cpu_id > NODE_APU_1) { 18 | LPERROR("%s: invalid node id: %d \n\r",__func__, cpu_id); 19 | return NULL; 20 | } 21 | 22 | (void)ops; 23 | LPRINTF("%s: node id: %d\n\r", __func__, cpu_id); 24 | priv = metal_allocate_memory(sizeof(*priv)); 25 | if (!priv) 26 | return NULL; 27 | memset(priv, 0, sizeof(*priv)); 28 | priv->rproc = rproc; 29 | priv->cpu_id = cpu_id; 30 | priv->rproc->priv = priv; 31 | rproc->state = RPROC_READY; 32 | return priv->rproc; 33 | } 34 | 35 | static void apu_rproc_remove(struct remoteproc *rproc) 36 | { 37 | struct rproc_priv *priv; 38 | 39 | priv = (struct rproc_priv *)rproc->priv; 40 | metal_free_memory(priv); 41 | } 42 | 43 | static void *apu_rproc_mmap(struct remoteproc *rproc, 44 | metal_phys_addr_t *pa, metal_phys_addr_t *da, 45 | size_t size, unsigned int attribute, 46 | struct metal_io_region **io) 47 | { 48 | struct remoteproc_mem *mem; 49 | metal_phys_addr_t lpa, lda, lda_end; 50 | 51 | if ((!da || !pa) || (*da == METAL_BAD_PHYS && *pa == METAL_BAD_PHYS)) 52 | return NULL; 53 | 54 | LPRINTF("%s: pa=0x%x, da=0x%x, size=0x%x, attribute=0x%x\n\r", 55 | __func__, *pa, *da, size, attribute); 56 | lda = *da; 57 | lpa = *pa; 58 | if (!attribute) 59 | attribute = NORM_SHARED_NCACHE | PRIV_RW_USER_RW; 60 | 61 | 62 | lda_end = lda + size; 63 | if (lda_end <= 0x80000000) 64 | XPm_RequestNode(NODE_DDR,PM_CAP_ACCESS, 65 | XPM_MIN_QOS,REQUEST_ACK_NO); 66 | if (lda >= 0xFFFC0000 && lda < 0xFFFD0000) 67 | XPm_RequestNode(NODE_OCM_BANK_0,PM_CAP_ACCESS, 68 | XPM_MIN_QOS,REQUEST_ACK_NO); 69 | if (lda <= 0xFFFDFFFF && lda_end >= 0xFFFD0000) 70 | XPm_RequestNode(NODE_OCM_BANK_1,PM_CAP_ACCESS, 71 | XPM_MIN_QOS,REQUEST_ACK_NO); 72 | if (lda <= 0xFFFEFFFF && lda_end >= 0xFFFE0000) 73 | XPm_RequestNode(NODE_OCM_BANK_2,PM_CAP_ACCESS, 74 | XPM_MIN_QOS,REQUEST_ACK_NO); 75 | if (lda_end >= 0xFFFF0000) 76 | XPm_RequestNode(NODE_OCM_BANK_3,PM_CAP_ACCESS, 77 | XPM_MIN_QOS,REQUEST_ACK_NO); 78 | 79 | mem = metal_allocate_memory(sizeof(*mem)); 80 | if (!mem) 81 | return NULL; 82 | mem->pa = lpa; 83 | 84 | *io = metal_allocate_memory(sizeof(struct metal_io_region)); 85 | if (!*io) { 86 | metal_free_memory(mem); 87 | return NULL; 88 | } 89 | 90 | /* 91 | * This code only runs on the R5, which has a flat memory 92 | * space. Therefore, we use the same value for the physical 93 | * and virtual addresses we pass in to metal_io_init(). 94 | */ 95 | metal_io_init(*io, (void *)mem->pa, &mem->pa, size, 96 | sizeof(metal_phys_addr_t)<<3, attribute, NULL); 97 | remoteproc_init_mem(mem, NULL, lpa, lda, size, *io); 98 | remoteproc_add_mem(rproc, mem); 99 | *pa = lpa; 100 | *da = lda; 101 | return metal_io_phys_to_virt(*io, mem->pa); 102 | } 103 | 104 | static int apu_rproc_start(struct remoteproc *rproc) 105 | { 106 | struct rproc_priv *priv; 107 | int ret; 108 | 109 | priv = rproc->priv; 110 | ret = XPm_RequestWakeUp(priv->cpu_id, true,rproc->bootaddr, 111 | REQUEST_ACK_NO); 112 | if (ret != XST_SUCCESS) { 113 | LPRINTF("%s: Failed to start APU 0x%x, ret=0x%x\n\r", 114 | __func__, priv->cpu_id, ret); 115 | return -1; 116 | } 117 | return 0; 118 | } 119 | 120 | static int apu_rproc_stop(struct remoteproc *rproc) 121 | { 122 | /* It is lacking a stop operation in the libPM */ 123 | (void)rproc; 124 | return 0; 125 | } 126 | 127 | static int apu_rproc_shutdown(struct remoteproc *rproc) 128 | { 129 | struct rproc_priv *priv; 130 | int ret; 131 | struct remoteproc_mem *mem; 132 | struct metal_list *node; 133 | 134 | priv = rproc->priv; 135 | /* Delete all the registered remoteproc memories */ 136 | metal_list_for_each(&rproc->mems, node) { 137 | struct metal_list *tmpnode; 138 | metal_phys_addr_t pa, pa_end; 139 | 140 | mem = metal_container_of(node, struct remoteproc_mem, node); 141 | tmpnode = node; 142 | /* Release TCM resource */ 143 | pa = mem->pa; 144 | pa_end = metal_io_phys(mem->io, metal_io_region_size(mem->io)); 145 | if (pa_end <= 0x7FFFFFFF) 146 | XPm_ReleaseNode(NODE_DDR); 147 | if (pa >= 0xFFFC0000 && pa < 0xFFFD0000) 148 | XPm_ReleaseNode(NODE_OCM_BANK_0); 149 | if (pa <= 0xFFFDFFFF && pa_end >= 0xFFFD0000) 150 | XPm_ReleaseNode(NODE_OCM_BANK_1); 151 | if (pa <= 0xFFFEFFFF && pa_end >= 0xFFFE0000) 152 | XPm_ReleaseNode(NODE_OCM_BANK_2); 153 | if (pa_end >= 0xFFFF0000) 154 | XPm_ReleaseNode(NODE_OCM_BANK_3); 155 | 156 | node = tmpnode->prev; 157 | metal_list_del(tmpnode); 158 | metal_free_memory(mem->io); 159 | metal_free_memory(mem); 160 | } 161 | ret = XPm_ForcePowerDown(priv->cpu_id, REQUEST_ACK_NO); 162 | if (ret != XST_SUCCESS) 163 | return -1; 164 | return 0; 165 | } 166 | 167 | const struct remoteproc_ops zynqmp_apu_rproc_ops = { 168 | .init = apu_rproc_init, 169 | .remove = apu_rproc_remove, 170 | .start = apu_rproc_start, 171 | .stop = apu_rproc_stop, 172 | .shutdown = apu_rproc_shutdown, 173 | .mmap = apu_rproc_mmap, 174 | }; 175 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/matrix_multiply/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 2 | set (_fw_dir "${APPS_SHARE_DIR}") 3 | 4 | collector_list (_list PROJECT_INC_DIRS) 5 | collector_list (_app_list APP_INC_DIRS) 6 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 7 | 8 | collector_list (_list PROJECT_LIB_DIRS) 9 | collector_list (_app_list APP_LIB_DIRS) 10 | link_directories (${_list} ${_app_list}) 11 | 12 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 13 | collector_list (_deps PROJECT_LIB_DEPS) 14 | 15 | set (OPENAMP_LIB open_amp) 16 | foreach (_app matrix_multiply matrix_multiplyd) 17 | collector_list (_sources APP_COMMON_SOURCES) 18 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 19 | 20 | if (WITH_SHARED_LIB) 21 | add_executable (${_app}-shared ${_sources}) 22 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 23 | target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) 24 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 25 | endif (WITH_SHARED_LIB) 26 | 27 | if (WITH_STATIC_LIB) 28 | if (${PROJECT_SYSTEM} STREQUAL "linux") 29 | add_executable (${_app}-static ${_sources}) 30 | target_compile_options (${_app}-static PRIVATE "-static") 31 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 32 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 33 | else (${PROJECT_SYSTEM}) 34 | add_executable (${_app}.out ${_sources}) 35 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 36 | 37 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 38 | 39 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 40 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 41 | endif (WITH_STATIC_LIB) 42 | endforeach(_app) 43 | 44 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/matrix_multiply/README.rst: -------------------------------------------------------------------------------- 1 | Overview 2 | ******** 3 | 4 | This readme is about the OpenAMP matrix_multiply demo. 5 | The matrix_multiply is about one processor generates two matrices, and sends them to the one, 6 | The other processor calculates the matrix multiplication and returns the result matrix. 7 | 8 | Compilation 9 | *********** 10 | 11 | See `README.md <../../README.md>`_ for details. 12 | 13 | Run demonstration on a Linux PC 14 | ******************************* 15 | 16 | It is possible to run the application on a Linux PC to communicate between two Linux processes. 17 | 18 | .. code-block:: shell 19 | 20 | cd $PROJECT_ROOT/target 21 | LD_LIBRARY_PATH=./lib ./bin/matrix_multiplyd-static & 22 | sleep 1 23 | LD_LIBRARY_PATH=./lib ./bin/matrix_multiply-static 1 24 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/matrix_multiply/matrix_multiply.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | #ifndef MATRIX_MULTIPLY_H 6 | #define MATRIX_MULTIPLY_H 7 | 8 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 9 | 10 | #endif /* MATRIX_MULTIPLY_H */ 11 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/matrix_multiply/matrix_multiplyd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | /* 6 | * This is a sample demonstration application that showcases usage of remoteproc 7 | * and rpmsg APIs on the remote core. This application is meant to run on the remote CPU 8 | * running baremetal code. This applicationr receives two matrices from the host, 9 | * multiplies them and returns the result to the host core. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "matrix_multiply.h" 17 | #include "platform_info.h" 18 | 19 | #define MAX_SIZE 6 20 | #define NUM_MATRIX 2 21 | 22 | #define SHUTDOWN_MSG 0xEF56A55A 23 | 24 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 25 | //#define LPRINTF(format, ...) 26 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 27 | 28 | typedef struct _matrix { 29 | unsigned int size; 30 | unsigned int elements[MAX_SIZE][MAX_SIZE]; 31 | } matrix; 32 | 33 | /* Local variables */ 34 | static struct rpmsg_endpoint lept; 35 | static int shutdown_req = 0; 36 | 37 | /*-----------------------------------------------------------------------------* 38 | * Calculate the Matrix 39 | *-----------------------------------------------------------------------------*/ 40 | static void Matrix_Multiply(const matrix *m, const matrix *n, matrix *r) 41 | { 42 | unsigned int i, j, k; 43 | 44 | memset(r, 0x0, sizeof(matrix)); 45 | r->size = m->size; 46 | 47 | for (i = 0; i < m->size; ++i) { 48 | for (j = 0; j < n->size; ++j) { 49 | for (k = 0; k < r->size; ++k) { 50 | r->elements[i][j] += 51 | m->elements[i][k] * n->elements[k][j]; 52 | } 53 | } 54 | } 55 | } 56 | 57 | /*-----------------------------------------------------------------------------* 58 | * RPMSG callbacks setup by remoteproc_resource_init() 59 | *-----------------------------------------------------------------------------*/ 60 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 61 | uint32_t src, void *priv) 62 | { 63 | matrix matrix_array[NUM_MATRIX]; 64 | matrix matrix_result; 65 | 66 | (void)priv; 67 | (void)src; 68 | 69 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 70 | LPRINTF("shutdown message is received.\r\n"); 71 | shutdown_req = 1; 72 | return RPMSG_SUCCESS; 73 | } 74 | 75 | memcpy(matrix_array, data, len); 76 | /* Process received data and multiple matrices. */ 77 | Matrix_Multiply(&matrix_array[0], &matrix_array[1], &matrix_result); 78 | 79 | /* Send the result of matrix multiplication back to host. */ 80 | if (rpmsg_send(ept, &matrix_result, sizeof(matrix)) < 0) { 81 | LPERROR("rpmsg_send failed\r\n"); 82 | } 83 | return RPMSG_SUCCESS; 84 | } 85 | 86 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 87 | { 88 | (void)ept; 89 | LPERROR("Endpoint is destroyed\r\n"); 90 | shutdown_req = 1; 91 | } 92 | 93 | /*-----------------------------------------------------------------------------* 94 | * Application 95 | *-----------------------------------------------------------------------------*/ 96 | int app(struct rpmsg_device *rdev, void *priv) 97 | { 98 | int ret; 99 | 100 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 101 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 102 | rpmsg_endpoint_cb, 103 | rpmsg_service_unbind); 104 | if (ret) { 105 | LPERROR("Failed to create endpoint.\r\n"); 106 | return -1; 107 | } 108 | 109 | LPRINTF("Waiting for events...\r\n"); 110 | while(1) { 111 | platform_poll(priv); 112 | /* we got a shutdown request, exit */ 113 | if (shutdown_req) { 114 | break; 115 | } 116 | } 117 | rpmsg_destroy_ept(&lept); 118 | 119 | return 0; 120 | } 121 | 122 | /*-----------------------------------------------------------------------------* 123 | * Application entry point 124 | *-----------------------------------------------------------------------------*/ 125 | int main(int argc, char *argv[]) 126 | { 127 | void *platform; 128 | struct rpmsg_device *rpdev; 129 | int ret; 130 | 131 | LPRINTF("Starting application...\r\n"); 132 | 133 | /* Initialize platform */ 134 | ret = platform_init(argc, argv, &platform); 135 | if (ret) { 136 | LPERROR("Failed to initialize platform.\r\n"); 137 | ret = -1; 138 | } else { 139 | rpdev = platform_create_rpmsg_vdev(platform, 0, 140 | VIRTIO_DEV_DEVICE, 141 | NULL, NULL); 142 | if (!rpdev) { 143 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 144 | ret = -1; 145 | } else { 146 | app(rpdev, platform); 147 | platform_release_rpmsg_vdev(rpdev, platform); 148 | ret = 0; 149 | } 150 | } 151 | 152 | LPRINTF("Stopping application...\r\n"); 153 | platform_cleanup(platform); 154 | 155 | return ret; 156 | } 157 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/nocopy_echo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app rpmsg-nocopy-ping rpmsg-nocopy-echo) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | if (${_app} STREQUAL "rpmsg-nocopy-ping") 21 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-nocopy-ping.c") 22 | elseif (${_app} STREQUAL "rpmsg-nocopy-echo") 23 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-nocopy-echo.c") 24 | endif (${_app} STREQUAL "rpmsg-nocopy-ping") 25 | 26 | if (WITH_SHARED_LIB) 27 | add_executable (${_app}-shared ${_sources}) 28 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 29 | target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) 30 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 31 | endif (WITH_SHARED_LIB) 32 | 33 | if (WITH_STATIC_LIB) 34 | if (${PROJECT_SYSTEM} STREQUAL "linux") 35 | add_executable (${_app}-static ${_sources}) 36 | target_compile_options (${_app}-static PRIVATE "-static") 37 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 38 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 39 | else (${PROJECT_SYSTEM}) 40 | add_executable (${_app}.out ${_sources}) 41 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 42 | 43 | target_compile_options (${_app}.out PRIVATE "-static") 44 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 45 | 46 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 47 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 48 | endif (WITH_STATIC_LIB) 49 | endforeach(_app) 50 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/nocopy_echo/README.rst: -------------------------------------------------------------------------------- 1 | Overview 2 | ******** 3 | 4 | This readme is about the OpenAMP echo demonstration using the RPmsg no copy API. 5 | The demonstration is about one processor sending a message to the other one, and the other one 6 | echoing back the message. The processor that sends the message will verify the echoed message. 7 | 8 | Compilation 9 | *********** 10 | 11 | See `README.md <../../README.md>`_ for details. 12 | 13 | Run demonstration on a Linux PC 14 | ******************************* 15 | 16 | It is possible to run the application on a Linux PC to communicate between two Linux processes. 17 | 18 | .. code-block:: shell 19 | 20 | LD_LIBRARY_PATH=./lib ./bin/rpmsg-nocopy-echo-static & 21 | sleep 1 22 | LD_LIBRARY_PATH=./lib ./bin/rpmsg-nocopy-ping-static 1 -------------------------------------------------------------------------------- /examples/legacy_apps/examples/nocopy_echo/rpmsg-echo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | #ifndef RPMSG_ECHO_H 6 | #define RPMSG_ECHO_H 7 | 8 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 9 | 10 | #endif /* RPMSG_ECHO_H */ 11 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/nocopy_echo/rpmsg-nocopy-echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 2020, STMicroelectronics 5 | */ 6 | 7 | /* 8 | * This is a sample demonstration application that showcases usage of rpmsg 9 | * This application is meant to run on the remote CPU running baremetal code. 10 | * This application echoes back data that was sent to it by the host core. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include "platform_info.h" 17 | #include "rpmsg-echo.h" 18 | 19 | #define SHUTDOWN_MSG 0xEF56A55A 20 | 21 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 22 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 23 | 24 | static struct rpmsg_endpoint lept; 25 | static int shutdown_req; 26 | 27 | struct rpmsg_rcv_msg { 28 | void *data; 29 | size_t len; 30 | struct rpmsg_endpoint *ept; 31 | struct rpmsg_rcv_msg *next; 32 | }; 33 | 34 | struct rpmsg_rcv_msg *rpmsg_list; 35 | 36 | /*----------------------------------------------------------------------------- 37 | * RPMSG endpoint callbacks 38 | *----------------------------------------------------------------------------- 39 | */ 40 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 41 | uint32_t src, void *priv) 42 | { 43 | (void)src; 44 | (void)priv; 45 | struct rpmsg_rcv_msg *rpmsg_node, *p_msg; 46 | 47 | /* On reception of a shutdown we signal the application to terminate */ 48 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 49 | LPRINTF("shutdown message is received.\r\n"); 50 | shutdown_req = 1; 51 | return RPMSG_SUCCESS; 52 | } 53 | 54 | rpmsg_node = metal_allocate_memory(sizeof(*rpmsg_node)); 55 | if (!rpmsg_node) { 56 | LPERROR("rpmsg_node allocation failed\r\n"); 57 | return -1; 58 | } 59 | rpmsg_hold_rx_buffer(ept, data); 60 | rpmsg_node->ept = ept; 61 | rpmsg_node->data = data; 62 | rpmsg_node->len = len; 63 | rpmsg_node->next = NULL; 64 | 65 | if (!rpmsg_list) 66 | rpmsg_list = rpmsg_node; 67 | else { 68 | p_msg = rpmsg_list; 69 | while (p_msg->next) 70 | p_msg = p_msg->next; 71 | p_msg->next = rpmsg_node; 72 | } 73 | 74 | return RPMSG_SUCCESS; 75 | } 76 | 77 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 78 | { 79 | (void)ept; 80 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 81 | shutdown_req = 1; 82 | } 83 | 84 | /*----------------------------------------------------------------------------- 85 | * Application 86 | *----------------------------------------------------------------------------- 87 | */ 88 | int app(struct rpmsg_device *rdev, void *priv) 89 | { 90 | int ret; 91 | struct rpmsg_rcv_msg *rpmsg_node; 92 | 93 | /* Initialize RPMSG framework */ 94 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 95 | 96 | rpmsg_list = NULL; 97 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 98 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 99 | rpmsg_endpoint_cb, 100 | rpmsg_service_unbind); 101 | if (ret) { 102 | LPERROR("Failed to create endpoint.\r\n"); 103 | return -1; 104 | } 105 | 106 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 107 | while (1) { 108 | platform_poll(priv); 109 | /* we got a shutdown request, exit */ 110 | if (shutdown_req) { 111 | break; 112 | } 113 | while (rpmsg_list) { 114 | /* Send data back to host */ 115 | ret = rpmsg_send(rpmsg_list->ept, rpmsg_list->data, 116 | rpmsg_list->len); 117 | if (ret < 0) { 118 | LPERROR("rpmsg_send failed\r\n"); 119 | return ret; 120 | } 121 | rpmsg_release_rx_buffer(rpmsg_list->ept, 122 | rpmsg_list->data); 123 | rpmsg_node = rpmsg_list; 124 | rpmsg_list = rpmsg_list->next; 125 | metal_free_memory(rpmsg_node); 126 | } 127 | } 128 | rpmsg_destroy_ept(&lept); 129 | 130 | return 0; 131 | } 132 | 133 | /*----------------------------------------------------------------------------- 134 | * Application entry point 135 | *----------------------------------------------------------------------------- 136 | */ 137 | int main(int argc, char *argv[]) 138 | { 139 | void *platform; 140 | struct rpmsg_device *rpdev; 141 | int ret; 142 | 143 | LPRINTF("Starting application...\r\n"); 144 | 145 | /* Initialize platform */ 146 | ret = platform_init(argc, argv, &platform); 147 | if (ret) { 148 | LPERROR("Failed to initialize platform.\r\n"); 149 | ret = -1; 150 | } else { 151 | rpdev = platform_create_rpmsg_vdev(platform, 0, 152 | VIRTIO_DEV_DEVICE, 153 | NULL, NULL); 154 | if (!rpdev) { 155 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 156 | ret = -1; 157 | } else { 158 | app(rpdev, platform); 159 | platform_release_rpmsg_vdev(rpdev, platform); 160 | ret = 0; 161 | } 162 | } 163 | 164 | LPRINTF("Stopping application...\r\n"); 165 | platform_cleanup(platform); 166 | 167 | return ret; 168 | } 169 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpc_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS}") 2 | set (_fw_dir "${APPS_SHARE_DIR}") 3 | 4 | collector_list (_list PROJECT_INC_DIRS) 5 | collector_list (_app_list APP_INC_DIRS) 6 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 7 | 8 | collector_list (_list PROJECT_LIB_DIRS) 9 | collector_list (_app_list APP_LIB_DIRS) 10 | link_directories (${_list} ${_app_list}) 11 | 12 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_LARGE_TEXT_OPT) 13 | if (NOT _linker_opt) 14 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 15 | endif (NOT _linker_opt) 16 | collector_list (_deps PROJECT_LIB_DEPS) 17 | 18 | set (OPENAMP_LIB open_amp) 19 | 20 | if (${PROJECT_SYSTEM} STREQUAL "linux") 21 | set (app_list rpc_demod) 22 | else (${PROJECT_SYSTEM}) 23 | set (app_list rpc_demo) 24 | endif (${PROJECT_SYSTEM} STREQUAL "linux") 25 | 26 | foreach (_app ${app_list}) 27 | collector_list (_sources APP_COMMON_SOURCES) 28 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 29 | 30 | if (WITH_SHARED_LIB) 31 | add_executable (${_app}-shared ${_sources}) 32 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 33 | target_link_libraries (${_app}-shared -shared ${OPENAMP_LIB} ${_deps}) 34 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 35 | endif (WITH_SHARED_LIB) 36 | 37 | if (WITH_STATIC_LIB) 38 | if (${PROJECT_SYSTEM} STREQUAL "linux") 39 | add_executable (${_app}-static ${_sources}) 40 | target_compile_options (${_app}-static PRIVATE "-static") 41 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 42 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 43 | else (${PROJECT_SYSTEM}) 44 | add_executable (${_app}.out ${_sources}) 45 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 46 | 47 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 48 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 49 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 50 | endif (WITH_STATIC_LIB) 51 | endforeach(_app) 52 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpc_demo/README.rst: -------------------------------------------------------------------------------- 1 | This readme is about the OpenAMP rpc_demo demo. 2 | The rpc_demo is about one processor uses the UART on the other processor and creates file on 3 | the other processor's filesystem with file operations. 4 | 5 | For now, It implements the remote processor running generic(baremetal) application accesses the 6 | devices on the Linux. 7 | 8 | Compilation 9 | *********** 10 | 11 | Add cmake option `-DWITH_PROXY=ON -DWITH_APPS=ON` to build the system reference demonstration applications. 12 | 13 | Baremetal Compilation 14 | ===================== 15 | 16 | Here is an example to generate the to generate the `rpc_demo` application: 17 | 18 | .. code-block:: shell 19 | 20 | cmake -DCMAKE_TOOLCHAIN_FILE=zynqmp_r5_generic -DWITH_APPS=ON -DWITH_PROXY=ON 21 | 22 | See `README.md <../../README.md>`_ to generate the `rpc_demod` application. 23 | 24 | Linux Compilation 25 | ================= 26 | 27 | See `README.md <../../README.md>`_ to generate the `rpc_demod` application. 28 | 29 | Run the Demo 30 | ************ 31 | 32 | The demo application will load the remoteproc module, then the proxy rpmsg module, will output 33 | message sent from the other processor, send the console input back to the other processor. 34 | When the demo application exits, it will unload the kernel modules. -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpc_demo/rpc_demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | /* 6 | * This sample code demonstrates how to use file system of host processor 7 | * using proxy mechanism. Proxy service is implemented on host processor. 8 | * This application can print to the host console, take input from host console 9 | * and perform regular file I/O such as open, read, write and close. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "rsc_table.h" 20 | #include "platform_info.h" 21 | #include "rpmsg-rpc-demo.h" 22 | 23 | #define REDEF_O_CREAT 0000100 24 | #define REDEF_O_EXCL 0000200 25 | #define REDEF_O_RDONLY 0000000 26 | #define REDEF_O_WRONLY 0000001 27 | #define REDEF_O_RDWR 0000002 28 | #define REDEF_O_APPEND 0002000 29 | #define REDEF_O_ACCMODE 0000003 30 | 31 | #define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__) 32 | //#define LPRINTF(format, ...) 33 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 34 | 35 | static void rpmsg_rpc_shutdown(struct rpmsg_rpc_data *rpc) 36 | { 37 | (void)rpc; 38 | LPRINTF("RPMSG RPC is shutting down.\r\n"); 39 | } 40 | 41 | /*-----------------------------------------------------------------------------* 42 | * Application specific 43 | *-----------------------------------------------------------------------------*/ 44 | int app(struct rpmsg_device *rdev, void *priv) 45 | { 46 | struct rpmsg_rpc_data rpc; 47 | struct rpmsg_rpc_syscall rpccall; 48 | int fd, bytes_written, bytes_read; 49 | char fname[] = "remote.file"; 50 | char wbuff[50]; 51 | char rbuff[1024]; 52 | char ubuff[50]; 53 | float fdata; 54 | int idata; 55 | int ret; 56 | 57 | /* redirect I/Os */ 58 | LPRINTF("Initializating I/Os redirection...\r\n"); 59 | ret = rpmsg_rpc_init(&rpc, rdev, RPMSG_SERVICE_NAME, 60 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 61 | priv, platform_poll, rpmsg_rpc_shutdown); 62 | rpmsg_set_default_rpc(&rpc); 63 | if (ret) { 64 | LPRINTF("Failed to initialize rpmsg rpc\r\n"); 65 | return -1; 66 | } 67 | 68 | printf("\nRemote>Baremetal Remote Procedure Call (RPC) Demonstration\r\n"); 69 | printf("\nRemote>***************************************************\r\n"); 70 | 71 | printf("\nRemote>Rpmsg based retargetting to proxy initialized..\r\n"); 72 | 73 | /* Remote performing file IO on Host */ 74 | printf("\nRemote>FileIO demo ..\r\n"); 75 | 76 | printf("\nRemote>Creating a file on host and writing to it..\r\n"); 77 | fd = open(fname, REDEF_O_CREAT | REDEF_O_WRONLY | REDEF_O_APPEND, 78 | S_IRUSR | S_IWUSR); 79 | printf("\nRemote>Opened file '%s' with fd = %d\r\n", fname, fd); 80 | 81 | sprintf(wbuff, "This is a test string being written to file.."); 82 | bytes_written = write(fd, wbuff, strlen(wbuff)); 83 | printf("\nRemote>Wrote to fd = %d, size = %d, content = %s\r\n", fd, 84 | bytes_written, wbuff); 85 | close(fd); 86 | printf("\nRemote>Closed fd = %d\r\n", fd); 87 | 88 | /* Remote performing file IO on Host */ 89 | printf("\nRemote>Reading a file on host and displaying its contents..\r\n"); 90 | fd = open(fname, REDEF_O_RDONLY, S_IRUSR | S_IWUSR); 91 | printf("\nRemote>Opened file '%s' with fd = %d\r\n", fname, fd); 92 | bytes_read = read(fd, rbuff, 1024); 93 | *(char *)(&rbuff[0] + bytes_read + 1) = 0; 94 | printf("\nRemote>Read from fd = %d, size = %d, printing contents below .. %s\r\n", 95 | fd, bytes_read, rbuff); 96 | close(fd); 97 | printf("\nRemote>Closed fd = %d\r\n", fd); 98 | 99 | while (1) { 100 | /* Remote performing STDIO on Host */ 101 | printf("\nRemote>Remote firmware using scanf and printf ..\r\n"); 102 | printf("\nRemote>Scanning user input from host..\r\n"); 103 | printf("\nRemote>Enter name\r\n"); 104 | ret = scanf("%s", ubuff); 105 | if (ret) { 106 | printf("\nRemote>Enter age\r\n"); 107 | ret = scanf("%d", &idata); 108 | if (ret) { 109 | printf("\nRemote>Enter value for pi\r\n"); 110 | ret = scanf("%f", &fdata); 111 | if (ret) { 112 | printf("\nRemote>User name = '%s'\r\n", ubuff); 113 | printf("\nRemote>User age = '%d'\r\n", idata); 114 | printf("\nRemote>User entered value of pi = '%f'\r\n", fdata); 115 | } 116 | } 117 | } 118 | if (!ret) { 119 | scanf("%s", ubuff); 120 | printf("Remote> Invalid value. Starting again...."); 121 | } else { 122 | printf("\nRemote>Repeat demo ? (enter yes or no) \r\n"); 123 | scanf("%s", ubuff); 124 | if ((strcmp(ubuff, "no")) && (strcmp(ubuff, "yes"))) { 125 | printf("\nRemote>Invalid option. Starting again....\r\n"); 126 | } else if ((!strcmp(ubuff, "no"))) { 127 | printf("\nRemote>RPC retargetting quitting ...\r\n"); 128 | break; 129 | } 130 | } 131 | } 132 | 133 | printf("\nRemote> Firmware's rpmsg-rpc-channel going down! \r\n"); 134 | rpccall.id = TERM_SYSCALL_ID; 135 | (void)rpmsg_rpc_send(&rpc, &rpccall, sizeof(rpccall), NULL, 0); 136 | 137 | LPRINTF("Release remoteproc procedure call\r\n"); 138 | rpmsg_rpc_release(&rpc); 139 | return 0; 140 | } 141 | 142 | /*-----------------------------------------------------------------------------* 143 | * Application entry point 144 | *-----------------------------------------------------------------------------*/ 145 | int main(int argc, char *argv[]) 146 | { 147 | void *platform; 148 | struct rpmsg_device *rpdev; 149 | int ret; 150 | 151 | LPRINTF("Starting application...\r\n"); 152 | 153 | /* Initialize platform */ 154 | ret = platform_init(argc, argv, &platform); 155 | if (ret) { 156 | LPERROR("Failed to initialize platform.\r\n"); 157 | ret = -1; 158 | } else { 159 | rpdev = platform_create_rpmsg_vdev(platform, 0, 160 | VIRTIO_DEV_DEVICE, 161 | NULL, NULL); 162 | if (!rpdev) { 163 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 164 | ret = -1; 165 | } else { 166 | app(rpdev, platform); 167 | platform_release_rpmsg_vdev(rpdev, platform); 168 | ret = 0; 169 | } 170 | } 171 | 172 | LPRINTF("Stopping application...\r\n"); 173 | platform_cleanup(platform); 174 | 175 | return ret; 176 | } 177 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpc_demo/rpmsg-rpc-demo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | #ifndef RPMSG_RPC_DEMO_H 6 | #define RPMSG_RPC_DEMO_H 7 | 8 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 9 | 10 | #endif /* RPMSG_RPC_DEMO_H */ 11 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpmsg_sample_echo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app rpmsg-sample-echo rpmsg-sample-ping) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c") 21 | 22 | if (WITH_SHARED_LIB) 23 | add_executable (${_app}-shared ${_sources}) 24 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 25 | target_link_libraries (${_app}-shared ${OPENAMP_LIB} ${_deps}) 26 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 27 | endif (WITH_SHARED_LIB) 28 | 29 | if (WITH_STATIC_LIB) 30 | if (${PROJECT_SYSTEM} STREQUAL "linux") 31 | add_executable (${_app}-static ${_sources}) 32 | target_compile_options (${_app}-static PRIVATE "-static") 33 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 34 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 35 | else (${PROJECT_SYSTEM}) 36 | add_executable (${_app}.out ${_sources}) 37 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 38 | 39 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 40 | 41 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 42 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 43 | endif (WITH_STATIC_LIB) 44 | endforeach(_app) 45 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpmsg_sample_echo/README.rst: -------------------------------------------------------------------------------- 1 | Overview 2 | ******** 3 | 4 | This readme is about the Linux sample echo demo. 5 | A `rpmsg_client_sample` driver is available by default in the Linux kernel. This example offers the 6 | pending implementation for the remote processor, but also an alternative to generate the echo sample 7 | in the Linux user space or on baremetal. 8 | 9 | Compilation 10 | *********** 11 | Add cmake option `-DWITH_APPS=ON` to build the system reference demonstration applications. 12 | 13 | Baremetal Compilation 14 | ===================== 15 | 16 | .. code-block:: shell 17 | 18 | cmake -DCMAKE_TOOLCHAIN_FILE=zynqmp_r5_generic -DWITH_APPS=ON 19 | 20 | 21 | See `README.md <../../README.md>`_ for details. 22 | 23 | Linux Compilation 24 | ================= 25 | 26 | Linux kernel Compilation 27 | ------------------------ 28 | 29 | Enable the `CONFIG_SAMPLE_RPMSG_CLIENT` to build the `rpmsg_sample_client` module 30 | 31 | Linux Userspace Compilation 32 | --------------------------- 33 | 34 | See `README.md <../../README.md>`_ to generate the `rpmsg-sample-ping` application. 35 | 36 | Run demonstration on a Linux PC 37 | ******************************* 38 | 39 | It is possible to run the application on a Linux PC to communicate between two Linux processes. 40 | 41 | .. code-block:: shell 42 | 43 | cd $PROJECT_ROOT/target 44 | LD_LIBRARY_PATH=./lib ./bin/rpmsg-sample-echo-static & 45 | sleep 1 46 | LD_LIBRARY_PATH=./lib ./bin/rpmsg-sample-ping-static 1 47 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpmsg_sample_echo/rpmsg-sample-echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | /* 6 | * This is a sample demonstration application that showcases usage of rpmsg 7 | * This application is meant to run on the remote CPU running baremetal code. 8 | * This application allows to check the compatibility with linux OS running on 9 | * the host CPU. For this it echo MSG_LIMIT time message sent by the rpmsg 10 | * sample client available in linux kernel distribution. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include "platform_info.h" 17 | 18 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 19 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 20 | 21 | 22 | #define RPMSG_SERV_NAME "rpmsg-client-sample" 23 | #define MSG_LIMIT 100 24 | 25 | static struct rpmsg_endpoint lept; 26 | static int shutdown_req = 0; 27 | 28 | /*-----------------------------------------------------------------------------* 29 | * RPMSG endpoint callbacks 30 | *-----------------------------------------------------------------------------*/ 31 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 32 | uint32_t src, void *priv) 33 | { 34 | (void)priv; 35 | (void)src; 36 | static uint32_t count = 0; 37 | char payload[RPMSG_BUFFER_SIZE]; 38 | 39 | /* Send data back MSG_LIMIT time to host */ 40 | memset(payload, 0, RPMSG_BUFFER_SIZE); 41 | memcpy(payload, data, len); 42 | if (++count <= MSG_LIMIT) { 43 | LPRINTF("echo message number %u: %s\r\n", 44 | (unsigned int)count, payload); 45 | if (rpmsg_send(ept, (char *)data, len) < 0) { 46 | LPERROR("rpmsg_send failed\r\n"); 47 | goto destroy_ept; 48 | } 49 | 50 | if (count == MSG_LIMIT) { 51 | goto destroy_ept; 52 | } 53 | } 54 | return RPMSG_SUCCESS; 55 | 56 | destroy_ept: 57 | shutdown_req = 1; 58 | return RPMSG_SUCCESS; 59 | } 60 | 61 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 62 | { 63 | (void)ept; 64 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 65 | shutdown_req = 1; 66 | } 67 | 68 | /*-----------------------------------------------------------------------------* 69 | * Application 70 | *-----------------------------------------------------------------------------*/ 71 | int app(struct rpmsg_device *rdev, void *priv) 72 | { 73 | int ret; 74 | 75 | /* Initialize RPMSG framework */ 76 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 77 | 78 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 79 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 80 | rpmsg_endpoint_cb, rpmsg_service_unbind); 81 | if (ret) { 82 | LPERROR("Failed to create endpoint.\r\n"); 83 | return -1; 84 | } 85 | 86 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 87 | while (1) { 88 | platform_poll(priv); 89 | /* we got a shutdown request, exit */ 90 | if (shutdown_req) { 91 | break; 92 | } 93 | } 94 | rpmsg_destroy_ept(&lept); 95 | 96 | return 0; 97 | } 98 | 99 | /*-----------------------------------------------------------------------------* 100 | * Application entry point 101 | *-----------------------------------------------------------------------------*/ 102 | int main(int argc, char *argv[]) 103 | { 104 | void *platform; 105 | struct rpmsg_device *rpdev; 106 | int ret; 107 | 108 | LPRINTF("Starting application...\r\n"); 109 | 110 | /* Initialize platform */ 111 | ret = platform_init(argc, argv, &platform); 112 | if (ret) { 113 | LPERROR("Failed to initialize platform.\r\n"); 114 | ret = -1; 115 | } else { 116 | rpdev = platform_create_rpmsg_vdev(platform, 0, 117 | VIRTIO_DEV_DEVICE, 118 | NULL, NULL); 119 | if (!rpdev) { 120 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 121 | ret = -1; 122 | } else { 123 | app(rpdev, platform); 124 | platform_release_rpmsg_vdev(rpdev, platform); 125 | ret = 0; 126 | } 127 | } 128 | 129 | LPRINTF("Stopping application...\r\n"); 130 | platform_cleanup(platform); 131 | 132 | return ret; 133 | } 134 | -------------------------------------------------------------------------------- /examples/legacy_apps/examples/rpmsg_sample_echo/rpmsg-sample-ping.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | /* 6 | * This is a sample demonstration application that showcases usage of rpmsg 7 | * This application is meant to run on the remote CPU running baremetal code. 8 | * This application simulate linux sample rpmsg driver. For this it echo 100 9 | * time message sent by the rpmsg sample client available in linux kernel 10 | * distribution. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "platform_info.h" 20 | 21 | #define RPMSG_SERV_NAME "rpmsg-client-sample" 22 | 23 | #define HELLO_MSG "hello world!" 24 | #define BYE_MSG "goodbye!" 25 | #define MSG_LIMIT 100 26 | 27 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 28 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 29 | 30 | static int err_cnt; 31 | 32 | 33 | /* Globals */ 34 | static struct rpmsg_endpoint lept; 35 | static int rnum = 0; 36 | static int err_cnt = 0; 37 | static int ept_deleted = 0; 38 | 39 | /*-----------------------------------------------------------------------------* 40 | * RPMSG endpoint callbacks 41 | *-----------------------------------------------------------------------------*/ 42 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 43 | uint32_t src, void *priv) 44 | { 45 | char payload[RPMSG_BUFFER_SIZE]; 46 | char seed[20]; 47 | 48 | (void)ept; 49 | (void)src; 50 | (void)priv; 51 | 52 | memset(payload, 0, RPMSG_BUFFER_SIZE); 53 | memcpy(payload, data, len); 54 | LPRINTF("received message %d: %s of size %lu \r\n", 55 | rnum + 1, payload, (unsigned long)len); 56 | 57 | if (rnum == (MSG_LIMIT - 1)) 58 | sprintf (seed, "%s", BYE_MSG); 59 | else 60 | sprintf (seed, "%s", HELLO_MSG); 61 | 62 | LPRINTF(" seed %s: \r\n", seed); 63 | 64 | if (strncmp(payload, seed, len)) { 65 | LPERROR(" Invalid message is received.\r\n"); 66 | err_cnt++; 67 | return RPMSG_SUCCESS; 68 | } 69 | LPRINTF(" rnum %d: \r\n", rnum); 70 | rnum++; 71 | 72 | return RPMSG_SUCCESS; 73 | } 74 | 75 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 76 | { 77 | (void)ept; 78 | rpmsg_destroy_ept(&lept); 79 | LPRINTF("echo test: service is destroyed\r\n"); 80 | ept_deleted = 1; 81 | } 82 | 83 | static void rpmsg_name_service_bind_cb(struct rpmsg_device *rdev, 84 | const char *name, uint32_t dest) 85 | { 86 | LPRINTF("new endpoint notification is received.\r\n"); 87 | if (strcmp(name, RPMSG_SERV_NAME)) 88 | LPERROR("Unexpected name service %s.\r\n", name); 89 | else 90 | (void)rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 91 | RPMSG_ADDR_ANY, dest, 92 | rpmsg_endpoint_cb, 93 | rpmsg_service_unbind); 94 | 95 | } 96 | 97 | /*-----------------------------------------------------------------------------* 98 | * Application 99 | *-----------------------------------------------------------------------------*/ 100 | int app(struct rpmsg_device *rdev, void *priv) 101 | { 102 | int ret; 103 | int i; 104 | 105 | LPRINTF(" 1 - Send data to remote core, retrieve the echo"); 106 | LPRINTF(" and validate its integrity ..\r\n"); 107 | 108 | /* Create RPMsg endpoint */ 109 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERV_NAME, 110 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 111 | rpmsg_endpoint_cb, rpmsg_service_unbind); 112 | 113 | if (ret) { 114 | LPERROR("Failed to create RPMsg endpoint.\r\n"); 115 | return ret; 116 | } 117 | 118 | while (!is_rpmsg_ept_ready(&lept)) 119 | platform_poll(priv); 120 | 121 | LPRINTF("RPMSG endpoint is binded with remote.\r\n"); 122 | for (i = 1; i <= MSG_LIMIT; i++) { 123 | 124 | 125 | if (i < MSG_LIMIT) 126 | ret = rpmsg_send(&lept, HELLO_MSG, strlen(HELLO_MSG)); 127 | else 128 | ret = rpmsg_send(&lept, BYE_MSG, strlen(BYE_MSG)); 129 | 130 | if (ret < 0) { 131 | LPERROR("Failed to send data...\r\n"); 132 | break; 133 | } 134 | LPRINTF("rpmsg sample test: message %d sent\r\n", i); 135 | 136 | do { 137 | platform_poll(priv); 138 | } while ((rnum < i) && !err_cnt); 139 | 140 | } 141 | 142 | LPRINTF("**********************************\r\n"); 143 | LPRINTF(" Test Results: Error count = %d\r\n", err_cnt); 144 | LPRINTF("**********************************\r\n"); 145 | while (!ept_deleted) 146 | platform_poll(priv); 147 | LPRINTF("Quitting application .. rpmsg sample test end\r\n"); 148 | 149 | return 0; 150 | } 151 | 152 | int main(int argc, char *argv[]) 153 | { 154 | void *platform; 155 | struct rpmsg_device *rpdev; 156 | int ret; 157 | 158 | /* Initialize platform */ 159 | ret = platform_init(argc, argv, &platform); 160 | if (ret) { 161 | LPERROR("Failed to initialize platform.\r\n"); 162 | ret = -1; 163 | } else { 164 | rpdev = platform_create_rpmsg_vdev(platform, 0, 165 | VIRTIO_DEV_DRIVER, 166 | NULL, 167 | rpmsg_name_service_bind_cb); 168 | if (!rpdev) { 169 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 170 | ret = -1; 171 | } else { 172 | app(rpdev, platform); 173 | platform_release_rpmsg_vdev(rpdev, platform); 174 | ret = 0; 175 | } 176 | } 177 | 178 | LPRINTF("Stopping application...\r\n"); 179 | platform_cleanup(platform); 180 | 181 | return ret; 182 | } 183 | 184 | -------------------------------------------------------------------------------- /examples/legacy_apps/include/platform_info_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Texas Instruments, Inc. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #ifndef PLATFORM_INFO_COMMON_H 8 | #define PLATFORM_INFO_COMMON_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #if defined __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /** 19 | * platform_init - initialize the platform 20 | * 21 | * Initialize the platform. 22 | * 23 | * @argc: number of arguments 24 | * @argv: array of the input arguments 25 | * @platform: pointer to store the platform data pointer 26 | * 27 | * return 0 for success or negative value for failure 28 | */ 29 | int platform_init(int argc, char *argv[], void **platform); 30 | 31 | /** 32 | * platform_create_rpmsg_vdev - create rpmsg vdev 33 | * 34 | * Create rpmsg virtio device, and return the rpmsg virtio 35 | * device pointer. 36 | * 37 | * @platform: pointer to the private data 38 | * @vdev_index: index of the virtio device, there can more than one vdev 39 | * on the platform. 40 | * @role: virtio driver or virtio device of the vdev 41 | * @rst_cb: virtio device reset callback 42 | * @ns_bind_cb: rpmsg name service bind callback 43 | * 44 | * return pointer to the rpmsg virtio device 45 | */ 46 | struct rpmsg_device * 47 | platform_create_rpmsg_vdev(void *platform, unsigned int vdev_index, 48 | unsigned int role, 49 | void (*rst_cb)(struct virtio_device *vdev), 50 | rpmsg_ns_bind_cb ns_bind_cb); 51 | 52 | /** 53 | * platform_poll - platform poll function 54 | * 55 | * @platform: pointer to the platform 56 | * 57 | * return negative value for errors, otherwise 0. 58 | */ 59 | int platform_poll(void *platform); 60 | 61 | /** 62 | * platform_release_rpmsg_vdev - release rpmsg virtio device 63 | * 64 | * @rpdev: pointer to the rpmsg device 65 | */ 66 | void platform_release_rpmsg_vdev(struct rpmsg_device *rpdev, void *platform); 67 | 68 | /** 69 | * platform_cleanup - clean up the platform resource 70 | * 71 | * @platform: pointer to the platform 72 | */ 73 | void platform_cleanup(void *platform); 74 | 75 | #if defined __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* PLATFORM_INFO_COMMON_H */ 80 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 2 | add_subdirectory (${PROJECT_MACHINE}) 3 | endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 4 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/microblaze_generic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES rsc_table.c) 3 | collect (APP_COMMON_SOURCES zynqmp_mb_a53_rproc.c) 4 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 5 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/microblaze_generic/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | #ifndef PLATFORM_INFO_H_ 7 | #define PLATFORM_INFO_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "platform_info_common.h" 14 | 15 | #if defined __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* MicroBlaze memory attributes. Depends on MB memory the design */ 20 | #define DEVICE_SHARED 0x00000001U /* device, shareable */ 21 | #define DEVICE_NONSHARED 0x00000010U /* device, non shareable */ 22 | #define NORM_NSHARED_NCACHE 0x00000008U /* Non cacheable non shareable */ 23 | #define NORM_SHARED_NCACHE 0x0000000CU /* Non cacheable shareable */ 24 | #define PRIV_RW_USER_RW (0x00000003U << 8U) /* Full Access */ 25 | 26 | #define POLL_SHM_LOCATION 0x3EE40000 27 | #define POLL_STOP 0x1U 28 | 29 | struct remoteproc_priv { 30 | const char *ipi_name; /**< IPI device name */ 31 | const char *ipi_bus_name; /**< IPI bus name */ 32 | struct metal_device *ipi_dev; /**< pointer to IPI device */ 33 | struct metal_io_region *ipi_io; /**< pointer to IPI i/o region */ 34 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 35 | atomic_int ipi_nokick; 36 | }; 37 | 38 | #if defined __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* PLATFORM_INFO_H_ */ 43 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/microblaze_generic/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2022 Xilinx, Inc. All rights reserved. 3 | * Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | /* 9 | * This file populates resource table for BM remote 10 | * for use by the Linux host 11 | */ 12 | 13 | #include 14 | #include "rsc_table.h" 15 | 16 | /* Place resource table in special ELF section */ 17 | #define __section_t(S) __attribute__((__section__(#S))) 18 | #define __resource __section_t(.resource_table) 19 | 20 | #define RPMSG_VDEV_DFEATURES (1 << VIRTIO_RPMSG_F_NS) 21 | 22 | #define NUM_VRINGS 0x02 23 | #define VRING_ALIGN 0x1000 24 | #define RING_TX 0x3ed40000 25 | #define RING_RX 0x3ed44000 26 | #define VRING_SIZE 256 27 | 28 | #define NUM_TABLE_ENTRIES 1 29 | 30 | struct remote_resource_table __resource resources = { 31 | /* Version */ 32 | 1, 33 | 34 | /* NUmber of table entries */ 35 | NUM_TABLE_ENTRIES, 36 | /* reserved fields */ 37 | {0, 0,}, 38 | 39 | /* Offsets of rsc entries */ 40 | { 41 | offsetof(struct remote_resource_table, rpmsg_vdev), 42 | }, 43 | 44 | /* Virtio device entry */ 45 | { 46 | RSC_VDEV, VIRTIO_ID_RPMSG_, 31, RPMSG_VDEV_DFEATURES, 0, 0, 0, 47 | NUM_VRINGS, {0, 0}, 48 | }, 49 | 50 | /* Vring rsc entry - part of vdev rsc entry */ 51 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 52 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 53 | }; 54 | 55 | void *get_resource_table(int rsc_id, int *len) 56 | { 57 | (void)rsc_id; 58 | *len = sizeof(resources); 59 | return &resources; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/microblaze_generic/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /* 8 | * Resource table declarations. Resource table is placed in a separate 9 | * section of a bare-metal binary or firmware. It's used to describe 10 | * shared memory (virtIO devices) resources the remoteproc host should 11 | * initialize and / or use to communicate with the firmware. 12 | */ 13 | #ifndef RSC_TABLE_H_ 14 | #define RSC_TABLE_H_ 15 | 16 | #include 17 | #include 18 | 19 | #if defined __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define NO_RESOURCE_ENTRIES 8 24 | 25 | /* Resource table for the given remote */ 26 | struct __packed remote_resource_table { 27 | unsigned int version; 28 | unsigned int num; 29 | unsigned int reserved[2]; 30 | unsigned int offset[NO_RESOURCE_ENTRIES]; 31 | /* rpmsg vdev entry */ 32 | struct fw_rsc_vdev rpmsg_vdev; 33 | struct fw_rsc_vdev_vring rpmsg_vring0; 34 | struct fw_rsc_vdev_vring rpmsg_vring1; 35 | }; 36 | 37 | void *get_resource_table(int rsc_id, int *len); 38 | 39 | #if defined __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* RSC_TABLE_H_ */ 44 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/microblaze_generic/zynqmp_mb_a53_rproc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /************************************************************************** 8 | * FILE NAME 9 | * 10 | * zynqmp_mb_a53_rproc.c 11 | * 12 | * DESCRIPTION 13 | * 14 | * OpenAMP remoteproc implementation for Xilinx MicroBlaze design 15 | * example. The design instantiates Xilinx MicroBlaze soft processor 16 | * in ZynqMP's programmable logic and uses processing system (PS) 17 | * DDR memory for its text and data. The APU in PS runs Linux with 18 | * reserved-memory nodes in its device tree toaccommodat the 19 | * MicroBlaze text, data. 20 | * 21 | **************************************************************************/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "platform_info.h" 30 | 31 | static inline void zynqmp_mb_a53_proc_remove(struct remoteproc *rproc) 32 | { 33 | (void)rproc; 34 | } 35 | 36 | static void * 37 | zynqmp_mb_a53_proc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, 38 | metal_phys_addr_t *da, size_t size, 39 | unsigned int attribute, struct metal_io_region **io) 40 | { 41 | struct remoteproc_mem *mem; 42 | metal_phys_addr_t lpa, lda; 43 | struct metal_io_region *tmpio; 44 | 45 | lpa = *pa; 46 | lda = *da; 47 | 48 | if (lpa == METAL_BAD_PHYS && lda == METAL_BAD_PHYS) 49 | return NULL; 50 | if (lpa == METAL_BAD_PHYS) 51 | lpa = lda; 52 | if (lda == METAL_BAD_PHYS) 53 | lda = lpa; 54 | 55 | mem = metal_allocate_memory(sizeof(*mem)); 56 | if (!mem) 57 | return NULL; 58 | tmpio = metal_allocate_memory(sizeof(*tmpio)); 59 | if (!tmpio) { 60 | metal_free_memory(mem); 61 | return NULL; 62 | } 63 | remoteproc_init_mem(mem, NULL, lpa, lda, size, tmpio); 64 | /* va is the same as pa in this platform */ 65 | metal_io_init(tmpio, (void *)lpa, &mem->pa, size, 66 | sizeof(metal_phys_addr_t) << 3, attribute, NULL); 67 | remoteproc_add_mem(rproc, mem); 68 | *pa = lpa; 69 | *da = lda; 70 | if (io) { 71 | *io = tmpio; 72 | } else { 73 | metal_free_memory(tmpio); 74 | metal_free_memory(mem); 75 | return NULL; 76 | } 77 | 78 | return metal_io_phys_to_virt(tmpio, mem->pa); 79 | } 80 | 81 | static int zynqmp_mb_a53_proc_notify(struct remoteproc *rproc, uint32_t id) 82 | { 83 | (void)rproc; 84 | (void)id; 85 | if (!rproc) 86 | return -1; 87 | 88 | char *notify = (char *)POLL_SHM_LOCATION; 89 | *notify = POLL_STOP; 90 | return 0; 91 | } 92 | 93 | /* 94 | * processor operations from mb to a53. It defines 95 | * notification operation and remote processor management operations. 96 | */ 97 | const struct remoteproc_ops zynqmp_mb_a53_proc_ops = { 98 | .init = NULL, 99 | .remove = zynqmp_mb_a53_proc_remove, 100 | .mmap = zynqmp_mb_a53_proc_mmap, 101 | .notify = zynqmp_mb_a53_proc_notify, 102 | .start = NULL, 103 | .stop = NULL, 104 | .shutdown = NULL, 105 | }; 106 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES zynqmp_linux_r5_proc.c) 3 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 4 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp/openamp-linux-userspace.dtsi: -------------------------------------------------------------------------------- 1 | / { 2 | reserved-memory { 3 | #address-cells = <2>; 4 | #size-cells = <2>; 5 | ranges; 6 | rproc_0_reserved: rproc@3ed000000 { 7 | no-map; 8 | reg = <0x0 0x3ed00000 0x0 0x1000000>; 9 | }; 10 | }; 11 | 12 | amba { 13 | vring: vring@0 { 14 | compatible = "vring_uio"; 15 | reg = <0x0 0x3ed40000 0x0 0x40000>; 16 | }; 17 | shm0: shm@0 { 18 | compatible = "shm_uio"; 19 | reg = <0x0 0x3ed20000 0x0 0x0100000>; 20 | }; 21 | ipi0: ipi@0 { 22 | compatible = "ipi_uio"; 23 | reg = <0x0 0xff340000 0x0 0x1000>; 24 | interrupt-parent = <&gic>; 25 | interrupts = <0 29 4>; 26 | }; 27 | }; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /* 8 | * This file populates resource table for BM remote 9 | * for use by the Linux host 10 | */ 11 | 12 | #ifndef PLATFORM_INFO_H_ 13 | #define PLATFORM_INFO_H_ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "platform_info_common.h" 20 | 21 | #if defined __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | struct remoteproc_priv { 26 | const char *ipi_name; /**< IPI device name */ 27 | const char *ipi_bus_name; /**< IPI bus name */ 28 | const char *rsc_name; /**< rsc device name */ 29 | const char *rsc_bus_name; /**< rsc bus name */ 30 | const char *shm_name; /**< shared memory device name */ 31 | const char *shm_bus_name; /**< shared memory bus name */ 32 | struct metal_device *ipi_dev; /**< pointer to IPI device */ 33 | struct metal_io_region *ipi_io; /**< pointer to IPI i/o region */ 34 | struct metal_device *shm_dev; /**< pointer to shared memory device */ 35 | struct metal_io_region *shm_io; /**< pointer to sh mem i/o region */ 36 | 37 | struct remoteproc_mem shm_mem; /**< shared memory */ 38 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 39 | atomic_int ipi_nokick; 40 | #ifdef RPMSG_NO_IPI 41 | const char *shm_poll_name; /**< shared memory device name */ 42 | const char *shm_poll_bus_name; /**< shared memory bus name */ 43 | struct metal_device *shm_poll_dev; /**< pointer to poll mem device */ 44 | struct metal_io_region *shm_poll_io; /**< pointer to poll mem i/o */ 45 | #endif /* RPMSG_NO_IPI */ 46 | 47 | }; 48 | 49 | #ifdef RPMSG_NO_IPI 50 | #ifndef POLL_DEV_NAME 51 | #define POLL_DEV_NAME "3ee40000.poll" /* shared device name */ 52 | #endif /* !POLL_DEV_NAME */ 53 | #define POLL_STOP 0x1U 54 | #endif /* RPMSG_NO_IPI */ 55 | 56 | #if defined __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* PLATFORM_INFO_H_ */ 61 | 62 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp_r5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES platform_info.c) 2 | collect (APP_COMMON_SOURCES rsc_table.c) 3 | collect (APP_COMMON_SOURCES zynqmp_r5_a53_rproc.c) 4 | collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") 5 | 6 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp_r5/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2017 Xilinx, Inc. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | #ifndef PLATFORM_INFO_H_ 10 | #define PLATFORM_INFO_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "platform_info_common.h" 17 | 18 | #if defined __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* Cortex R5 memory attributes */ 23 | #define DEVICE_SHARED 0x00000001U /* device, shareable */ 24 | #define DEVICE_NONSHARED 0x00000010U /* device, non shareable */ 25 | #define NORM_NSHARED_NCACHE 0x00000008U /* Non cacheable non shareable */ 26 | #define NORM_SHARED_NCACHE 0x0000000CU /* Non cacheable shareable */ 27 | #define PRIV_RW_USER_RW (0x00000003U<<8U) /* Full Access */ 28 | 29 | /* Interrupt vectors */ 30 | #ifdef versal 31 | 32 | #ifndef IPI_IRQ_VECT_ID 33 | #define IPI_IRQ_VECT_ID 63 34 | #endif /* !IPI_IRQ_VECT_ID */ 35 | 36 | #ifndef POLL_BASE_ADDR 37 | #define POLL_BASE_ADDR 0xFF340000 /* IPI base address*/ 38 | #endif /* !POLL_BASE_ADDR */ 39 | 40 | #ifndef IPI_CHN_BITMASK 41 | #define IPI_CHN_BITMASK 0x0000020 /* IPI channel bit mask for IPI from/to 42 | APU */ 43 | #endif /* !IPI_CHN_BITMASK */ 44 | 45 | #else 46 | 47 | #ifndef IPI_IRQ_VECT_ID 48 | #define IPI_IRQ_VECT_ID XPAR_XIPIPSU_0_INT_ID 49 | #endif /* !IPI_IRQ_VECT_ID */ 50 | 51 | #ifndef POLL_BASE_ADDR 52 | #define POLL_BASE_ADDR XPAR_XIPIPSU_0_BASE_ADDRESS 53 | #endif /* !POLL_BASE_ADDR */ 54 | 55 | #ifndef IPI_CHN_BITMASK 56 | #define IPI_CHN_BITMASK 0x01000000 57 | #endif /* !IPI_CHN_BITMASK */ 58 | 59 | #endif /* versal */ 60 | 61 | #ifdef RPMSG_NO_IPI 62 | #undef POLL_BASE_ADDR 63 | #define POLL_BASE_ADDR 0x3EE40000 64 | #define POLL_STOP 0x1U 65 | #endif /* RPMSG_NO_IPI */ 66 | 67 | struct remoteproc_priv { 68 | const char *kick_dev_name; 69 | const char *kick_dev_bus_name; 70 | struct metal_device *kick_dev; 71 | struct metal_io_region *kick_io; 72 | #ifndef RPMSG_NO_IPI 73 | unsigned int ipi_chn_mask; /**< IPI channel mask */ 74 | atomic_int ipi_nokick; 75 | #endif /* !RPMSG_NO_IPI */ 76 | }; 77 | 78 | #if defined __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* PLATFORM_INFO_H_ */ 83 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp_r5/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* 10 | * This file populates resource table for BM remote 11 | * for use by the Linux host 12 | */ 13 | 14 | #include 15 | #include "rsc_table.h" 16 | 17 | /* Place resource table in special ELF section */ 18 | #define __section_t(S) __attribute__((__section__(#S))) 19 | #define __resource __section_t(.resource_table) 20 | 21 | #define RPMSG_VDEV_DFEATURES (1 << VIRTIO_RPMSG_F_NS) 22 | 23 | /* VirtIO rpmsg device id */ 24 | #define VIRTIO_ID_RPMSG_ 7 25 | 26 | #define NUM_VRINGS 0x02 27 | #define VRING_ALIGN 0x1000 28 | #ifndef RING_TX 29 | #define RING_TX FW_RSC_U32_ADDR_ANY 30 | #endif /* !RING_TX */ 31 | #ifndef RING_RX 32 | #define RING_RX FW_RSC_U32_ADDR_ANY 33 | #endif /* RING_RX */ 34 | #define VRING_SIZE 256 35 | 36 | #define NUM_TABLE_ENTRIES 1 37 | 38 | struct remote_resource_table __resource resources = { 39 | /* Version */ 40 | 1, 41 | 42 | /* NUmber of table entries */ 43 | NUM_TABLE_ENTRIES, 44 | /* reserved fields */ 45 | {0, 0,}, 46 | 47 | /* Offsets of rsc entries */ 48 | { 49 | offsetof(struct remote_resource_table, rpmsg_vdev), 50 | }, 51 | 52 | /* Virtio device entry */ 53 | { 54 | RSC_VDEV, VIRTIO_ID_RPMSG_, 31, RPMSG_VDEV_DFEATURES, 0, 0, 0, 55 | NUM_VRINGS, {0, 0}, 56 | }, 57 | 58 | /* Vring rsc entry - part of vdev rsc entry */ 59 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 60 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 61 | }; 62 | 63 | void *get_resource_table (int rsc_id, int *len) 64 | { 65 | (void) rsc_id; 66 | *len = sizeof(resources); 67 | return &resources; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp_r5/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * Copyright (C) 2015 Xilinx, Inc. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | /* 11 | * This file populates resource table for BM remote 12 | * for use by the Linux host 13 | */ 14 | 15 | #ifndef RSC_TABLE_H_ 16 | #define RSC_TABLE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #if defined __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define NO_RESOURCE_ENTRIES 8 26 | 27 | /* Resource table for the given remote */ 28 | struct remote_resource_table { 29 | unsigned int version; 30 | unsigned int num; 31 | unsigned int reserved[2]; 32 | unsigned int offset[NO_RESOURCE_ENTRIES]; 33 | /* rpmsg vdev entry */ 34 | struct fw_rsc_vdev rpmsg_vdev; 35 | struct fw_rsc_vdev_vring rpmsg_vring0; 36 | struct fw_rsc_vdev_vring rpmsg_vring1; 37 | }__attribute__((packed, aligned(0x100))); 38 | 39 | void *get_resource_table (int rsc_id, int *len); 40 | 41 | #if defined __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* RSC_TABLE_H_ */ 46 | -------------------------------------------------------------------------------- /examples/legacy_apps/machine/zynqmp_r5/zynqmp_r5_a53_rproc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2017 Xilinx, Inc. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /************************************************************************** 10 | * FILE NAME 11 | * 12 | * zynqmp_r5_a53_rproc.c 13 | * 14 | * DESCRIPTION 15 | * 16 | * This file define Xilinx ZynqMP R5 to A53 platform specific 17 | * remoteproc implementation. 18 | * 19 | **************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "platform_info.h" 28 | #ifndef RPMSG_NO_IPI 29 | /* IPI REGs OFFSET */ 30 | #define IPI_TRIG_OFFSET 0x00000000 /* IPI trigger register offset */ 31 | #define IPI_OBS_OFFSET 0x00000004 /* IPI observation register offset */ 32 | #define IPI_ISR_OFFSET 0x00000010 /* IPI interrupt status register offset */ 33 | #define IPI_IMR_OFFSET 0x00000014 /* IPI interrupt mask register offset */ 34 | #define IPI_IER_OFFSET 0x00000018 /* IPI interrupt enable register offset */ 35 | #define IPI_IDR_OFFSET 0x0000001C /* IPI interrupt disable register offset */ 36 | 37 | static int zynqmp_r5_a53_proc_irq_handler(int vect_id, void *data) 38 | { 39 | struct remoteproc *rproc = data; 40 | struct remoteproc_priv *prproc; 41 | unsigned int ipi_intr_status; 42 | 43 | (void)vect_id; 44 | if (!rproc) 45 | return METAL_IRQ_NOT_HANDLED; 46 | prproc = rproc->priv; 47 | ipi_intr_status = (unsigned int)metal_io_read32(prproc->kick_io, 48 | IPI_ISR_OFFSET); 49 | if (ipi_intr_status & prproc->ipi_chn_mask) { 50 | atomic_flag_clear(&prproc->ipi_nokick); 51 | metal_io_write32(prproc->kick_io, IPI_ISR_OFFSET, 52 | prproc->ipi_chn_mask); 53 | return METAL_IRQ_HANDLED; 54 | } 55 | return METAL_IRQ_NOT_HANDLED; 56 | } 57 | #endif /* !RPMSG_NO_IPI */ 58 | 59 | static struct remoteproc * 60 | zynqmp_r5_a53_proc_init(struct remoteproc *rproc, 61 | const struct remoteproc_ops *ops, void *arg) 62 | { 63 | struct remoteproc_priv *prproc = arg; 64 | struct metal_device *kick_dev; 65 | unsigned int irq_vect; 66 | int ret; 67 | 68 | (void)ops; 69 | if (!rproc || !prproc) 70 | return NULL; 71 | ret = metal_device_open(prproc->kick_dev_bus_name, 72 | prproc->kick_dev_name, 73 | &kick_dev); 74 | if (ret) { 75 | xil_printf("failed to open polling device: %d.\r\n", ret); 76 | return NULL; 77 | } 78 | prproc->kick_dev = kick_dev; 79 | prproc->kick_io = metal_device_io_region(kick_dev, 0); 80 | if (!prproc->kick_io) 81 | goto err1; 82 | #ifndef RPMSG_NO_IPI 83 | atomic_store(&prproc->ipi_nokick, 1); 84 | /* Register interrupt handler and enable interrupt */ 85 | irq_vect = (uintptr_t)kick_dev->irq_info; 86 | metal_irq_register(irq_vect, zynqmp_r5_a53_proc_irq_handler, rproc); 87 | metal_irq_enable(irq_vect); 88 | metal_io_write32(prproc->kick_io, IPI_IER_OFFSET, 89 | prproc->ipi_chn_mask); 90 | #else 91 | (void)irq_vect; 92 | metal_io_write32(prproc->kick_io, 0, !POLL_STOP); 93 | #endif /* !RPMSG_NO_IPI */ 94 | 95 | return rproc; 96 | err1: 97 | metal_device_close(kick_dev); 98 | return NULL; 99 | } 100 | 101 | static void zynqmp_r5_a53_proc_remove(struct remoteproc *rproc) 102 | { 103 | struct remoteproc_priv *prproc; 104 | struct metal_device *dev; 105 | 106 | if (!rproc) 107 | return; 108 | prproc = rproc->priv; 109 | #ifndef RPMSG_NO_IPI 110 | metal_io_write32(prproc->kick_io, IPI_IDR_OFFSET, 111 | prproc->ipi_chn_mask); 112 | dev = prproc->kick_dev; 113 | if (dev) { 114 | metal_irq_disable((uintptr_t)dev->irq_info); 115 | metal_irq_unregister((uintptr_t)dev->irq_info); 116 | } 117 | #else /* RPMSG_NO_IPI */ 118 | (void)dev; 119 | #endif /* !RPMSG_NO_IPI */ 120 | metal_device_close(prproc->kick_dev); 121 | } 122 | 123 | static void * 124 | zynqmp_r5_a53_proc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, 125 | metal_phys_addr_t *da, size_t size, 126 | unsigned int attribute, struct metal_io_region **io) 127 | { 128 | struct remoteproc_mem *mem; 129 | metal_phys_addr_t lpa, lda; 130 | struct metal_io_region *tmpio; 131 | 132 | lpa = *pa; 133 | lda = *da; 134 | 135 | if (lpa == METAL_BAD_PHYS && lda == METAL_BAD_PHYS) 136 | return NULL; 137 | if (lpa == METAL_BAD_PHYS) 138 | lpa = lda; 139 | if (lda == METAL_BAD_PHYS) 140 | lda = lpa; 141 | 142 | if (!attribute) 143 | attribute = NORM_SHARED_NCACHE | PRIV_RW_USER_RW; 144 | mem = metal_allocate_memory(sizeof(*mem)); 145 | if (!mem) 146 | return NULL; 147 | tmpio = metal_allocate_memory(sizeof(*tmpio)); 148 | if (!tmpio) { 149 | metal_free_memory(mem); 150 | return NULL; 151 | } 152 | remoteproc_init_mem(mem, NULL, lpa, lda, size, tmpio); 153 | /* va is the same as pa in this platform */ 154 | metal_io_init(tmpio, (void *)lpa, &mem->pa, size, 155 | sizeof(metal_phys_addr_t) << 3, attribute, NULL); 156 | remoteproc_add_mem(rproc, mem); 157 | *pa = lpa; 158 | *da = lda; 159 | if (io) 160 | *io = tmpio; 161 | return metal_io_phys_to_virt(tmpio, mem->pa); 162 | } 163 | 164 | static int zynqmp_r5_a53_proc_notify(struct remoteproc *rproc, uint32_t id) 165 | { 166 | struct remoteproc_priv *prproc; 167 | 168 | (void)id; 169 | if (!rproc) 170 | return -1; 171 | prproc = rproc->priv; 172 | 173 | #ifdef RPMSG_NO_IPI 174 | metal_io_write32(prproc->kick_io, 0, POLL_STOP); 175 | #else 176 | metal_io_write32(prproc->kick_io, IPI_TRIG_OFFSET, 177 | prproc->ipi_chn_mask); 178 | #endif /* RPMSG_NO_IPI */ 179 | return 0; 180 | } 181 | 182 | /* 183 | * processor operations from r5 to a53. It defines 184 | * notification operation and remote processor management operations. 185 | */ 186 | const struct remoteproc_ops zynqmp_r5_a53_proc_ops = { 187 | .init = zynqmp_r5_a53_proc_init, 188 | .remove = zynqmp_r5_a53_proc_remove, 189 | .mmap = zynqmp_r5_a53_proc_mmap, 190 | .notify = zynqmp_r5_a53_proc_notify, 191 | .start = NULL, 192 | .stop = NULL, 193 | .shutdown = NULL, 194 | }; 195 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM}/CMakeLists.txt") 2 | add_subdirectory (${PROJECT_SYSTEM}) 3 | endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SYSTEM}/CMakeLists.txt") 4 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory (machine) 2 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/machine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 2 | add_subdirectory (${PROJECT_MACHINE}) 3 | endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt") 4 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/machine/microblaze_generic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckSymbolExists) 2 | 3 | collect (APP_COMMON_SOURCES helper.c) 4 | 5 | set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_remote.ld") 6 | set_property (GLOBAL PROPERTY APP_LINKER_OPT "-T\"${_linker_script}\"") 7 | 8 | find_path(XIL_INCLUDE_DIR NAMES xparameters.h PATHS ${CMAKE_FIND_ROOT_PATH}) 9 | collect (PROJECT_INC_DIRS "${XIL_INCLUDE_DIR}") 10 | 11 | find_library(LIBXIL_LIB NAMES xil PATHS ${CMAKE_FIND_ROOT_PATH}) 12 | get_filename_component(LIBXIL_LIB_DIR ${LIBXIL_LIB} DIRECTORY) 13 | collect(PROJECT_LIB_DIRS ${LIBXIL_LIB_DIR}) 14 | 15 | 16 | collect(PROJECT_LIB_DEPS xil) 17 | collect(PROJECT_LIB_DEPS c) 18 | collect(PROJECT_LIB_DEPS m) 19 | 20 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/machine/microblaze_generic/helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Xilinx, Inc. All rights reserved. 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | */ 7 | 8 | #include "xparameters.h" 9 | #include "xil_exception.h" 10 | #include "xil_printf.h" 11 | #include 12 | #include "platform_info.h" 13 | 14 | static void system_metal_logger(enum metal_log_level level, 15 | const char *format, ...) 16 | { 17 | (void)level; 18 | (void)format; 19 | } 20 | 21 | /* Main hw machinery initialization entry point, called from main()*/ 22 | /* return 0 on success */ 23 | int init_system(void) 24 | { 25 | int ret; 26 | struct metal_init_params metal_param = { 27 | .log_handler = system_metal_logger, 28 | .log_level = METAL_LOG_INFO, 29 | }; 30 | 31 | /* Low level abstraction layer for openamp initialization */ 32 | ret = metal_init(&metal_param); 33 | return ret; 34 | } 35 | 36 | void cleanup_system(void) 37 | { 38 | metal_finish(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/machine/microblaze_generic/linker_remote.ld: -------------------------------------------------------------------------------- 1 | /*******************************************************************/ 2 | /* */ 3 | /* This file is automatically generated by linker script generator.*/ 4 | /* */ 5 | /* Version: 2020.1.0 */ 6 | /* */ 7 | /* Copyright (c) 2010-2020 Xilinx, Inc. All rights reserved. */ 8 | /* */ 9 | /* Description : MicroBlaze Linker Script */ 10 | /* */ 11 | /*******************************************************************/ 12 | 13 | _STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x400; 14 | _HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x1800; 15 | 16 | /* Define Memories in the system */ 17 | 18 | MEMORY 19 | { 20 | psu_ddr_0_HP0_AXI_BASENAME_MEM_0 : ORIGIN = 0x70000050, LENGTH = 0x7FEFFFB0 21 | rsc_table_psu_ddr_S_AXI_BASEADDR : ORIGIN = 0x3ED00000, LENGTH = 0x00040000 22 | } 23 | 24 | /* Specify the default entry point to the program */ 25 | 26 | ENTRY(_start) 27 | 28 | /* Define the sections, and where they are mapped in memory */ 29 | 30 | SECTIONS 31 | { 32 | .vectors.reset 0x70000000 : { 33 | KEEP (*(.vectors.reset)) 34 | } 35 | 36 | .vectors.sw_exception 0x70000008 : { 37 | KEEP (*(.vectors.sw_exception)) 38 | } 39 | 40 | .vectors.interrupt 0x70000010 : { 41 | KEEP (*(.vectors.interrupt)) 42 | } 43 | 44 | .vectors.hw_exception 0x70000020 : { 45 | KEEP (*(.vectors.hw_exception)) 46 | } 47 | 48 | .text : { 49 | *(.text) 50 | *(.text.*) 51 | *(.gnu.linkonce.t.*) 52 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 53 | 54 | .init : { 55 | KEEP (*(.init)) 56 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 57 | 58 | .fini : { 59 | KEEP (*(.fini)) 60 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 61 | 62 | .ctors : { 63 | __CTOR_LIST__ = .; 64 | ___CTORS_LIST___ = .; 65 | KEEP (*crtbegin.o(.ctors)) 66 | KEEP (*(EXCLUDE_FILE(*crtend.o) .ctors)) 67 | KEEP (*(SORT(.ctors.*))) 68 | KEEP (*(.ctors)) 69 | __CTOR_END__ = .; 70 | ___CTORS_END___ = .; 71 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 72 | 73 | .dtors : { 74 | __DTOR_LIST__ = .; 75 | ___DTORS_LIST___ = .; 76 | KEEP (*crtbegin.o(.dtors)) 77 | KEEP (*(EXCLUDE_FILE(*crtend.o) .dtors)) 78 | KEEP (*(SORT(.dtors.*))) 79 | KEEP (*(.dtors)) 80 | PROVIDE(__DTOR_END__ = .); 81 | PROVIDE(___DTORS_END___ = .); 82 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 83 | 84 | .rodata : { 85 | __rodata_start = .; 86 | *(.rodata) 87 | *(.rodata.*) 88 | *(.gnu.linkonce.r.*) 89 | __rodata_end = .; 90 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 91 | 92 | .sdata2 : { 93 | . = ALIGN(8); 94 | __sdata2_start = .; 95 | *(.sdata2) 96 | *(.sdata2.*) 97 | *(.gnu.linkonce.s2.*) 98 | . = ALIGN(8); 99 | __sdata2_end = .; 100 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 101 | 102 | .sbss2 : { 103 | __sbss2_start = .; 104 | *(.sbss2) 105 | *(.sbss2.*) 106 | *(.gnu.linkonce.sb2.*) 107 | __sbss2_end = .; 108 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 109 | 110 | .data : { 111 | . = ALIGN(4); 112 | __data_start = .; 113 | *(.data) 114 | *(.data.*) 115 | *(.gnu.linkonce.d.*) 116 | __data_end = .; 117 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 118 | 119 | .got : { 120 | *(.got) 121 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 122 | 123 | .got1 : { 124 | *(.got1) 125 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 126 | 127 | .got2 : { 128 | *(.got2) 129 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 130 | 131 | .eh_frame : { 132 | *(.eh_frame) 133 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 134 | 135 | .jcr : { 136 | *(.jcr) 137 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 138 | 139 | .gcc_except_table : { 140 | *(.gcc_except_table) 141 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 142 | 143 | .sdata : { 144 | . = ALIGN(8); 145 | __sdata_start = .; 146 | *(.sdata) 147 | *(.sdata.*) 148 | *(.gnu.linkonce.s.*) 149 | __sdata_end = .; 150 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 151 | 152 | .sbss (NOLOAD) : { 153 | . = ALIGN(4); 154 | __sbss_start = .; 155 | *(.sbss) 156 | *(.sbss.*) 157 | *(.gnu.linkonce.sb.*) 158 | . = ALIGN(8); 159 | __sbss_end = .; 160 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 161 | 162 | .tdata : { 163 | __tdata_start = .; 164 | *(.tdata) 165 | *(.tdata.*) 166 | *(.gnu.linkonce.td.*) 167 | __tdata_end = .; 168 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 169 | 170 | .tbss : { 171 | __tbss_start = .; 172 | *(.tbss) 173 | *(.tbss.*) 174 | *(.gnu.linkonce.tb.*) 175 | __tbss_end = .; 176 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 177 | 178 | .bss (NOLOAD) : { 179 | . = ALIGN(4); 180 | __bss_start = .; 181 | *(.bss) 182 | *(.bss.*) 183 | *(.gnu.linkonce.b.*) 184 | *(COMMON) 185 | . = ALIGN(4); 186 | __bss_end = .; 187 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 188 | 189 | _SDA_BASE_ = __sdata_start + ((__sbss_end - __sdata_start) / 2 ); 190 | 191 | _SDA2_BASE_ = __sdata2_start + ((__sbss2_end - __sdata2_start) / 2 ); 192 | 193 | /* Generate Stack and Heap definitions */ 194 | 195 | .heap (NOLOAD) : { 196 | . = ALIGN(8); 197 | _heap = .; 198 | _heap_start = .; 199 | . += _HEAP_SIZE; 200 | _heap_end = .; 201 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 202 | 203 | .stack (NOLOAD) : { 204 | _stack_end = .; 205 | . += _STACK_SIZE; 206 | . = ALIGN(8); 207 | _stack = .; 208 | __stack = _stack; 209 | } > psu_ddr_0_HP0_AXI_BASENAME_MEM_0 210 | 211 | /* Linux must have reserved-memory node for this resource_table */ 212 | .resource_table 0x3ed20000 : { 213 | . = ALIGN(4); 214 | *(.resource_table) 215 | } > rsc_table_psu_ddr_S_AXI_BASEADDR 216 | 217 | _end = .; 218 | } 219 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/machine/zynqmp_r5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckSymbolExists) 2 | 3 | collect (APP_COMMON_SOURCES helper.c) 4 | 5 | # If not provided, add default value for resource table 6 | if(NOT DEFINED ${RSC_TABLE}) 7 | set(RSC_TABLE 0x3ed20000 CACHE STRING "") 8 | endif(NOT DEFINED ${RSC_TABLE}) 9 | 10 | set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_remote.ld") 11 | set_property (GLOBAL PROPERTY APP_LINKER_OPT "-Wl,--defsym,_rsc_table=${RSC_TABLE} -T\"${_linker_script}\"") 12 | set (_linker_large_text_script "${CMAKE_CURRENT_SOURCE_DIR}/linker_large_text.ld") 13 | set_property (GLOBAL PROPERTY APP_LINKER_LARGE_TEXT_OPT "-Wl,--defsym,_rsc_table=${RSC_TABLE} -T\"${_linker_large_text_script}\"") 14 | 15 | find_path(XIL_INCLUDE_DIR NAMES xparameters.h PATHS ${CMAKE_FIND_ROOT_PATH}) 16 | collect (PROJECT_INC_DIRS "${XIL_INCLUDE_DIR}") 17 | 18 | find_library(LIBXIL_LIB NAMES xil PATHS ${CMAKE_FIND_ROOT_PATH}) 19 | get_filename_component(LIBXIL_LIB_DIR ${LIBXIL_LIB} DIRECTORY) 20 | collect(PROJECT_LIB_DIRS ${LIBXIL_LIB_DIR}) 21 | 22 | # check PM API for certain headers and set client version based 23 | CHECK_SYMBOL_EXISTS(XPAR_XILPM_ENABLED "xparameters.h" PM_FOUND) 24 | if(PM_FOUND) 25 | find_library(HAS_PM_LIB NAMES xilpm PATHS ${CMAKE_FIND_ROOT_PATH}) 26 | collect (PROJECT_LIB_DEPS xilpm) 27 | CHECK_SYMBOL_EXISTS(versal "xparameters.h" VERSION_2_PM_CLIENT) 28 | if (VERSION_2_PM_CLIENT) 29 | collect (APP_EXTRA_C_FLAGS " -DVERSION_2_PM_CLIENT ") 30 | else() 31 | collect (APP_EXTRA_C_FLAGS " -DVERSION_1_PM_CLIENT ") 32 | endif(VERSION_2_PM_CLIENT) 33 | endif(PM_FOUND) 34 | 35 | collect(PROJECT_LIB_DEPS xil) 36 | collect(PROJECT_LIB_DEPS c) 37 | collect(PROJECT_LIB_DEPS m) 38 | find_library(XILMEM_LIB NAMES xilmem PATHS ${CMAKE_FIND_ROOT_PATH}) 39 | if(XILMEM_LIB) 40 | collect (PROJECT_LIB_DEPS xilmem) 41 | endif(XILMEM_LIB) 42 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/generic/machine/zynqmp_r5/helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * 5 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 6 | * 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | */ 9 | 10 | #include "xparameters.h" 11 | #include "xil_exception.h" 12 | #include "xil_printf.h" 13 | #include "xscugic.h" 14 | #include "xil_cache.h" 15 | #include 16 | #include 17 | #include "platform_info.h" 18 | 19 | #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID 20 | 21 | static XScuGic xInterruptController; 22 | 23 | /* Interrupt Controller setup */ 24 | static int app_gic_initialize(void) 25 | { 26 | uint32_t status; 27 | XScuGic_Config *int_ctrl_config; /* interrupt controller configuration params */ 28 | uint32_t int_id; 29 | uint32_t mask_cpu_id = ((u32)0x1 << XPAR_CPU_ID); 30 | uint32_t target_cpu; 31 | 32 | mask_cpu_id |= mask_cpu_id << 8U; 33 | mask_cpu_id |= mask_cpu_id << 16U; 34 | 35 | Xil_ExceptionDisable(); 36 | 37 | /* 38 | * Initialize the interrupt controller driver 39 | */ 40 | int_ctrl_config = XScuGic_LookupConfig(INTC_DEVICE_ID); 41 | if (NULL == int_ctrl_config) { 42 | return XST_FAILURE; 43 | } 44 | 45 | status = XScuGic_CfgInitialize(&xInterruptController, int_ctrl_config, 46 | int_ctrl_config->CpuBaseAddress); 47 | if (status != XST_SUCCESS) { 48 | return XST_FAILURE; 49 | } 50 | 51 | /* Only associate interrupt needed to this CPU */ 52 | for (int_id = 32U; int_id 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | int init_system() 19 | { 20 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 21 | 22 | metal_param.log_level = LOG_DEBUG; 23 | metal_init(&metal_param); 24 | 25 | return 0; 26 | } 27 | 28 | void cleanup_system() 29 | { 30 | metal_finish(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/linux/machine/generic/platform_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | /* 8 | * This file populates resource table for BM remote 9 | * for use by the Linux host 10 | */ 11 | 12 | #ifndef PLATFORM_INFO_H 13 | #define PLATFORM_INFO_H 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "platform_info_common.h" 20 | 21 | #endif /* PLATFORM_INFO_H */ 22 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/linux/machine/generic/rsc_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* 10 | * This file populates resource table for BM remote 11 | * for use by the Linux host 12 | */ 13 | 14 | #include 15 | #include "rsc_table.h" 16 | 17 | #define RPMSG_VDEV_DFEATURES (1 << VIRTIO_RPMSG_F_NS) 18 | 19 | /* VirtIO rpmsg device id */ 20 | #define VIRTIO_ID_RPMSG_ 7 21 | 22 | #define NUM_VRINGS 0x02 23 | #define VRING_ALIGN 0x1000 24 | #define RING_TX 0x00004000 25 | #define RING_RX 0x00008000 26 | #define VRING_SIZE 256 27 | 28 | #define NUM_TABLE_ENTRIES 1 29 | 30 | struct remote_resource_table resources = { 31 | /* Version */ 32 | 1, 33 | 34 | /* NUmber of table entries */ 35 | NUM_TABLE_ENTRIES, 36 | /* reserved fields */ 37 | {0, 0,}, 38 | 39 | /* Offsets of rsc entries */ 40 | { 41 | offsetof(struct remote_resource_table, rpmsg_vdev), 42 | }, 43 | 44 | /* Virtio device entry */ 45 | { 46 | RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_VDEV_DFEATURES, 0, 0, 0, 47 | NUM_VRINGS, {0, 0}, 48 | }, 49 | 50 | /* Vring rsc entry - part of vdev rsc entry */ 51 | {RING_TX, VRING_ALIGN, VRING_SIZE, 1, 0}, 52 | {RING_RX, VRING_ALIGN, VRING_SIZE, 2, 0}, 53 | }; 54 | 55 | void *get_resource_table (int rsc_id, int *len) 56 | { 57 | (void) rsc_id; 58 | *len = sizeof(resources); 59 | return &resources; 60 | } 61 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/linux/machine/generic/rsc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Mentor Graphics Corporation 3 | * All rights reserved. 4 | * Copyright (c) 2016 Xilinx, Inc. All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-3-Clause 7 | */ 8 | 9 | /* 10 | * This file populates resource table for BM remote 11 | * for use by the Linux host 12 | */ 13 | 14 | #ifndef RSC_TABLE_H_ 15 | #define RSC_TABLE_H_ 16 | 17 | #include 18 | #include 19 | 20 | #if defined __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define NO_RESOURCE_ENTRIES 1 25 | 26 | /* Resource table for the given remote */ 27 | struct remote_resource_table { 28 | unsigned int version; 29 | unsigned int num; 30 | unsigned int reserved[2]; 31 | unsigned int offset[NO_RESOURCE_ENTRIES]; 32 | /* rpmsg vdev entry */ 33 | struct fw_rsc_vdev rpmsg_vdev; 34 | struct fw_rsc_vdev_vring rpmsg_vring0; 35 | struct fw_rsc_vdev_vring rpmsg_vring1; 36 | }; 37 | 38 | void *get_resource_table (int rsc_id, int *len); 39 | 40 | #if defined __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* RSC_TABLE_H_ */ 45 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/linux/machine/zynqmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | collect (APP_COMMON_SOURCES helper.c) 2 | 3 | -------------------------------------------------------------------------------- /examples/legacy_apps/system/linux/machine/zynqmp/helper.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2014, Mentor Graphics Corporation 4 | * All rights reserved. 5 | * 6 | * Copyright (c) 2015 Xilinx, Inc. All rights reserved. 7 | * 8 | * SPDX-License-Identifier: BSD-3-Clause 9 | */ 10 | #include 11 | #include 12 | #include 13 | 14 | int init_system() 15 | { 16 | struct metal_init_params metal_param = METAL_INIT_DEFAULTS; 17 | 18 | metal_init(&metal_param); 19 | 20 | return 0; 21 | } 22 | 23 | void cleanup_system() 24 | { 25 | metal_finish(); 26 | } 27 | -------------------------------------------------------------------------------- /examples/legacy_apps/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # tests presently do not support microblaze 2 | if (MACHINE MATCHES ".*microblaze.*") 3 | return() 4 | endif (MACHINE MATCHES ".*microblaze.*") 5 | 6 | add_subdirectory (msg) 7 | -------------------------------------------------------------------------------- /examples/legacy_apps/tests/msg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections") 3 | set (_fw_dir "${APPS_SHARE_DIR}") 4 | 5 | collector_list (_list PROJECT_INC_DIRS) 6 | collector_list (_app_list APP_INC_DIRS) 7 | include_directories (${_list} ${_app_list} ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | collector_list (_list PROJECT_LIB_DIRS) 10 | collector_list (_app_list APP_LIB_DIRS) 11 | link_directories (${_list} ${_app_list}) 12 | 13 | get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT) 14 | collector_list (_deps PROJECT_LIB_DEPS) 15 | 16 | set (OPENAMP_LIB open_amp) 17 | 18 | foreach (_app msg-test-rpmsg-ping msg-test-rpmsg-nocopy-ping msg-test-rpmsg-nocopy-echo msg-test-rpmsg-update msg-test-rpmsg-flood-ping ) 19 | collector_list (_sources APP_COMMON_SOURCES) 20 | if (${_app} STREQUAL "msg-test-rpmsg-ping") 21 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-ping.c") 22 | elseif (${_app} STREQUAL "msg-test-rpmsg-nocopy-ping") 23 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-nocopy-ping.c") 24 | elseif (${_app} STREQUAL "msg-test-rpmsg-nocopy-echo") 25 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-nocopy-echo.c") 26 | elseif (${_app} STREQUAL "msg-test-rpmsg-update") 27 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-update.c") 28 | elseif (${_app} STREQUAL "msg-test-rpmsg-flood-ping") 29 | list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/rpmsg-flood-ping.c") 30 | endif (${_app} STREQUAL "msg-test-rpmsg-ping") 31 | 32 | if (WITH_SHARED_LIB) 33 | add_executable (${_app}-shared ${_sources}) 34 | target_compile_options (${_app}-shared PRIVATE "-fPIC") 35 | target_link_libraries (${_app}-shared -shared ${OPENAMP_LIB} ${_deps}) 36 | install (TARGETS ${_app}-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 37 | endif (WITH_SHARED_LIB) 38 | 39 | if (WITH_STATIC_LIB) 40 | if (${PROJECT_SYSTEM} STREQUAL "linux") 41 | add_executable (${_app}-static ${_sources}) 42 | target_compile_options (${_app}-static PRIVATE "-static") 43 | target_link_libraries (${_app}-static ${OPENAMP_LIB} ${_deps}) 44 | install (TARGETS ${_app}-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 45 | else (${PROJECT_SYSTEM}) 46 | add_executable (${_app}.out ${_sources}) 47 | set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}") 48 | 49 | target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections ${_linker_opt} -Wl,--start-group -static ${OPENAMP_LIB} ${_deps} -Wl,--end-group) 50 | 51 | install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 52 | endif (${PROJECT_SYSTEM} STREQUAL "linux" ) 53 | endif (WITH_STATIC_LIB) 54 | endforeach(_app) 55 | -------------------------------------------------------------------------------- /examples/legacy_apps/tests/msg/rpmsg-ping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | #ifndef RPMSG_PING_H 6 | #define RPMSG_PING_H 7 | 8 | #define RPMSG_SERVICE_NAME "rpmsg-openamp-demo-channel" 9 | 10 | #endif /* RPMSG_PING_H */ 11 | -------------------------------------------------------------------------------- /examples/legacy_apps/tests/msg/rpmsg-update.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | */ 4 | 5 | /* 6 | * This is a sample demonstration application that showcases usage of rpmsg 7 | * This application is meant to run on the remote CPU running baremetal code. 8 | * This application echoes back data that was sent to it by the host core. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "platform_info.h" 15 | #include "rpmsg-ping.h" 16 | 17 | #define SHUTDOWN_MSG 0xEF56A55A 18 | 19 | #define LPRINTF(format, ...) printf(format, ##__VA_ARGS__) 20 | //#define LPRINTF(format, ...) 21 | #define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__) 22 | 23 | static struct rpmsg_endpoint lept; 24 | static int shutdown_req = 0; 25 | 26 | /* External functions */ 27 | extern int init_system(void); 28 | extern void cleanup_system(void); 29 | 30 | /*-----------------------------------------------------------------------------* 31 | * RPMSG endpoint callbacks 32 | *-----------------------------------------------------------------------------*/ 33 | static int rpmsg_endpoint_cb(struct rpmsg_endpoint *ept, void *data, size_t len, 34 | uint32_t src, void *priv) 35 | { 36 | (void)priv; 37 | (void)src; 38 | 39 | /* On reception of a shutdown we signal the application to terminate */ 40 | if ((*(unsigned int *)data) == SHUTDOWN_MSG) { 41 | LPRINTF("shutdown message is received.\r\n"); 42 | shutdown_req = 1; 43 | return RPMSG_SUCCESS; 44 | } 45 | 46 | /* Send data back to host */ 47 | while (1) { 48 | int ret; 49 | 50 | ret = rpmsg_send(ept, data, len); 51 | if (ret == RPMSG_ERR_NO_BUFF) { 52 | LPRINTF("%s, wait for buffer\r\n", __func__); 53 | continue; 54 | } else { 55 | if (ret < 0) 56 | LPERROR("rpmsg_send, size %lu failed %d\r\n", 57 | (unsigned long)len, ret); 58 | break; 59 | } 60 | } 61 | return RPMSG_SUCCESS; 62 | } 63 | 64 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 65 | { 66 | (void)ept; 67 | LPRINTF("unexpected Remote endpoint destroy\r\n"); 68 | shutdown_req = 1; 69 | } 70 | 71 | /*-----------------------------------------------------------------------------* 72 | * Application 73 | *-----------------------------------------------------------------------------*/ 74 | int app(struct rpmsg_device *rdev, void *priv) 75 | { 76 | int ret; 77 | 78 | /* Initialize RPMSG framework */ 79 | LPRINTF("Try to create rpmsg endpoint.\r\n"); 80 | 81 | ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, 82 | RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, 83 | rpmsg_endpoint_cb, 84 | rpmsg_service_unbind); 85 | if (ret) { 86 | LPERROR("Failed to create endpoint.\r\n"); 87 | return -1; 88 | } 89 | 90 | LPRINTF("Successfully created rpmsg endpoint.\r\n"); 91 | while(1) { 92 | platform_poll(priv); 93 | /* we got a shutdown request, exit */ 94 | if (shutdown_req) { 95 | break; 96 | } 97 | } 98 | rpmsg_destroy_ept(&lept); 99 | 100 | return 0; 101 | } 102 | 103 | /*-----------------------------------------------------------------------------* 104 | * Application entry point 105 | *-----------------------------------------------------------------------------*/ 106 | int main(int argc, char *argv[]) 107 | { 108 | void *platform; 109 | struct rpmsg_device *rpdev; 110 | int ret; 111 | 112 | LPRINTF("Starting application...\r\n"); 113 | 114 | /* Initialize platform */ 115 | ret = platform_init(argc, argv, &platform); 116 | if (ret) { 117 | LPERROR("Failed to initialize platform.\r\n"); 118 | ret = -1; 119 | } else { 120 | rpdev = platform_create_rpmsg_vdev(platform, 0, 121 | VIRTIO_DEV_DEVICE, 122 | NULL, NULL); 123 | if (!rpdev) { 124 | LPERROR("Failed to create rpmsg virtio device.\r\n"); 125 | ret = -1; 126 | } else { 127 | app(rpdev, platform); 128 | platform_release_rpmsg_vdev(rpdev, platform); 129 | ret = 0; 130 | } 131 | } 132 | 133 | LPRINTF("Stopping application...\r\n"); 134 | platform_cleanup(platform); 135 | 136 | return ret; 137 | } 138 | -------------------------------------------------------------------------------- /examples/legacy_apps/west.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022 STMicroelectronics 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | manifest: 5 | remotes: 6 | - name: openamp 7 | url-base: https://github.com/OpenAMP 8 | defaults: 9 | remote: openamp 10 | 11 | self: 12 | path: openamp-system-reference 13 | 14 | projects: 15 | - name: libmetal 16 | revision: main 17 | 18 | - name: open-amp 19 | revision: main 20 | -------------------------------------------------------------------------------- /examples/linux/common/common.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BSD-3-Clause 2 | 3 | #ifndef __COMMON__H__ 4 | #define __COMMON__H__ 5 | 6 | #include 7 | 8 | #define RPMSG_BUS_SYS "/sys/bus/rpmsg" 9 | 10 | int app_rpmsg_create_ept(int rpfd, struct rpmsg_endpoint_info *eptinfo); 11 | char *get_rpmsg_ept_dev_name(const char *rpmsg_char_name, 12 | const char *ept_name, 13 | char *ept_dev_name); 14 | int bind_rpmsg_chrdev(const char *rpmsg_dev_name); 15 | int get_rpmsg_chrdev_fd(const char *rpmsg_dev_name, char *rpmsg_ctrl_name); 16 | int lookup_channel(char *out, struct rpmsg_endpoint_info *pep); 17 | 18 | #endif /* __COMMON__H__ */ 19 | -------------------------------------------------------------------------------- /examples/linux/dts/.gitignore: -------------------------------------------------------------------------------- 1 | *.dtb 2 | *.dtbo 3 | *.dts.pp 4 | *.dtso.pp 5 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/.gitignore: -------------------------------------------------------------------------------- 1 | # These files come from a copy command in the Makefile 2 | # don't check them in even though they look like source files 3 | 4 | zynqmp-zcu102-rev1.0.dts 5 | zynqmp-smk-k26-revA.dts 6 | zynqmp-sck-kv-g-revB.dtso 7 | .linux-src-check 8 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/Makefile: -------------------------------------------------------------------------------- 1 | # Build Devicetree Binaries and Devicetree Binary Overlays 2 | 3 | DTBS := zcu102-openamp-lockstep.dtb zcu102-openamp-split.dtb 4 | DTBS += kv260-openamp-lockstep.dtb kv260-openamp-split.dtb 5 | DTBS += zynqmp-smk-k26-revA.dtb zynqmp-zcu102-rev1.0.dtb 6 | DTBS += zcu102-xilinx-bm-lockstep.dtb kv260-xilinx-bm-lockstep.dtb 7 | 8 | DTBOS := zynqmp-lockstep.dtbo zcu102-openamp.dtbo zynqmp-openamp.dtbo 9 | DTBOS += zynqmp-sck-kv-g-revB.dtbo xilinx-openamp-for-v6.x.dtbo 10 | 11 | # any file to test we have a valid kernel source dir 12 | XILINX_DTS_DIR := $(LINUX_SRC_DIR)/arch/arm64/boot/dts/xilinx 13 | LINUX_INC_DIR := $(LINUX_SRC_DIR)/include/ 14 | 15 | SHELL := /bin/bash 16 | 17 | all: $(DTBS) $(DTBOS) $(DTBCS) 18 | 19 | .linux-src-check: 20 | @if [ ! -d $(XILINX_DTS_DIR) ]; then \ 21 | echo "LINUX_SRC_DIR must point to a Linux source directory"; \ 22 | echo "LINUX_SRC_DIR=$(LINUX_SRC_DIR)"; \ 23 | exit 2; \ 24 | fi 25 | touch .linux-src-check 26 | 27 | .PHONY : all 28 | 29 | DTC_CPP_FLAGS= -E -x assembler-with-cpp -nostdinc -undef -D__DTS__ 30 | 31 | # Note: -@ includes symbols which is need to apply overlays 32 | # We always enable overlays 33 | %.dtb: %.dts 34 | # Linux DTS uses C preprocessor first 35 | $(CC) $(DTC_CPP_FLAGS) \ 36 | -I $(XILINX_DTS_DIR) \ 37 | -I $(LINUX_INC_DIR) \ 38 | -o $<.pp $< 39 | dtc -@ -I dts -O dtb -o $@ $<.pp 40 | 41 | %.dtbo: %.dtso 42 | # Linux DTS uses C preprocessor first 43 | $(CC) $(DTC_CPP_FLAGS) \ 44 | -I $(XILINX_DTS_DIR) \ 45 | -I $(LINUX_INC_DIR) \ 46 | -o $<.pp $< 47 | dtc -@ -I dts -O dtb -o $@ $<.pp 48 | 49 | DTB_KERNEL_SRC := \ 50 | zynqmp-zcu102-rev1.0.dts \ 51 | zynqmp-smk-k26-revA.dts \ 52 | zynqmp-sck-kv-g-revB.dtso 53 | 54 | $(DTBS) $(DTBOS) $(DTB_KERNEL_SRC): .linux-src-check 55 | 56 | # copy needed sources from Kernel 57 | zynqmp-zcu102-rev1.0.dts: $(XILINX_DTS_DIR)/zynqmp-zcu102-rev1.0.dts 58 | cp $< $@ 59 | 60 | zynqmp-smk-k26-revA.dts: $(XILINX_DTS_DIR)/zynqmp-smk-k26-revA.dts 61 | cp $< $@ 62 | 63 | zynqmp-sck-kv-g-revB.dtso: $(XILINX_DTS_DIR)/zynqmp-sck-kv-g-revB.dtso 64 | cp $< $@ 65 | 66 | zcu102-openamp-lockstep.dtb: \ 67 | zynqmp-zcu102-rev1.0.dtb \ 68 | zynqmp-openamp.dtbo \ 69 | zcu102-openamp.dtbo \ 70 | zynqmp-lockstep.dtbo 71 | fdtoverlay -o $@ -i $(filter-out .linux-src-check,$^) 72 | 73 | zcu102-openamp-split.dtb: \ 74 | zynqmp-zcu102-rev1.0.dtb \ 75 | zynqmp-openamp.dtbo \ 76 | zcu102-openamp.dtbo 77 | fdtoverlay -o $@ -i $(filter-out .linux-src-check,$^) 78 | 79 | kv260-openamp-lockstep.dtb: \ 80 | zynqmp-smk-k26-revA.dtb zynqmp-sck-kv-g-revB.dtbo \ 81 | zynqmp-openamp.dtbo \ 82 | zynqmp-lockstep.dtbo 83 | fdtoverlay -o $@ -i $(filter-out .linux-src-check,$^) 84 | 85 | kv260-openamp-split.dtb: \ 86 | zynqmp-smk-k26-revA.dtb zynqmp-sck-kv-g-revB.dtbo \ 87 | zynqmp-openamp.dtbo 88 | fdtoverlay -o $@ -i $(filter-out .linux-src-check,$^) 89 | 90 | zcu102-xilinx-bm-lockstep.dtb: \ 91 | zynqmp-zcu102-rev1.0.dtb \ 92 | xilinx-openamp-for-v6.x.dtbo \ 93 | zcu102-openamp.dtbo 94 | fdtoverlay -o $@ -i $(filter-out .linux-src-check,$^) 95 | 96 | kv260-xilinx-bm-lockstep.dtb: \ 97 | zynqmp-smk-k26-revA.dtb zynqmp-sck-kv-g-revB.dtbo \ 98 | xilinx-openamp-for-v6.x.dtbo 99 | fdtoverlay -o $@ -i $(filter-out .linux-src-check,$^) 100 | 101 | clean: 102 | rm -f $(DTBS) $(DTBOS) $(DTBCS) *.pp .linux-src-check $(DTB_KERNEL_SRC) 103 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/README.md: -------------------------------------------------------------------------------- 1 | 2 | #### Building DTBs 3 | - You will need a copy of the Linux source tree 4 | - For consitency use the same kernel version as the OpenAMP-CI Builds is using 5 | - Below we assume the kernel source is at ~/my-dir/kernel-source 6 | - `make LINUX_SRC_DIR=~/my-dir/kernel-source' 7 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/xilinx-openamp-for-v6.x.dtso: -------------------------------------------------------------------------------- 1 | /* Applies to all zynqmp boards to configure the IPC & memory for OpenAMP 2 | ** 3 | ** This configuration is compatible with old bare-metal apps built with 4 | ** petalinux v2023 and before. 5 | ** 6 | ** It uses different IPC interrupt channels 7 | ** It only supports lockstep mode 8 | ** 9 | ** Bare-metal apps that do not use rpmsg (or any other IPI) can use the normal 10 | ** dtbs and thus can support lockstep and split mode. 11 | */ 12 | 13 | /dts-v1/; 14 | /plugin/; 15 | 16 | &{/} { 17 | #address-cells = <2>; 18 | #size-cells = <2>; 19 | 20 | reserved-memory { 21 | #address-cells = <0x02>; 22 | #size-cells = <0x02>; 23 | ranges; 24 | 25 | rproc_0_fw_image: memory@3ed00000 { 26 | no-map; 27 | reg = <0x0 0x3ed00000 0x0 0x40000>; 28 | }; 29 | 30 | rpu0vdev0vring0: vdev0vring0@3ed40000 { 31 | no-map; 32 | reg = <0x00 0x3ed40000 0x00 0x4000>; 33 | }; 34 | 35 | rpu0vdev0vring1: vdev0vring1@3ed44000 { 36 | no-map; 37 | reg = <0x00 0x3ed44000 0x00 0x4000>; 38 | }; 39 | 40 | rpu0vdev0buffer: vdev0buffer@3ed48000 { 41 | no-map; 42 | compatible = "shared-dma-pool"; 43 | reg = <0x00 0x3ed48000 0x00 0x100000>; 44 | }; 45 | 46 | }; 47 | 48 | zynqmp_ipi1 { 49 | compatible = "xlnx,zynqmp-ipi-mailbox"; 50 | interrupt-parent = <&gic>; 51 | interrupts = <0x00 0x1d 0x04>; 52 | xlnx,ipi-id = <0x07>; /* bare-metal apps send on channel 7 */ 53 | #address-cells = <0x01>; 54 | #size-cells = <0x01>; 55 | ranges; 56 | 57 | ipi_mailbox_rpu0: mailbox@ff990600 { 58 | reg = <0xff990600 0x20>, 59 | <0xff990620 0x20>, 60 | <0xff9900c0 0x20>, 61 | <0xff9900e0 0x20>; 62 | reg-names = "local_request_region", 63 | "local_response_region", 64 | "remote_request_region", 65 | "remote_response_region"; 66 | #mbox-cells = <0x01>; 67 | xlnx,ipi-id = <0x01>; /* host still sends to RPU0 on ch 1 */ 68 | }; 69 | }; 70 | 71 | remoteproc@ffe00000 { 72 | r5f@0 { 73 | memory-region = <&rproc_0_fw_image>, <&rpu0vdev0vring0>, 74 | <&rpu0vdev0vring1>, <&rpu0vdev0buffer>; 75 | mboxes = <&ipi_mailbox_rpu0 0>, <&ipi_mailbox_rpu0 1>; 76 | mbox-names = "tx", "rx"; 77 | }; 78 | }; 79 | }; 80 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/zcu102-openamp.dtso: -------------------------------------------------------------------------------- 1 | /* Changes specific to zcu102 but common to mode */ 2 | 3 | /dts-v1/; 4 | /plugin/; 5 | 6 | /* Plus make these specific zcu102 changes */ 7 | &{/axi} { 8 | serial@ff010000 { 9 | status = "disabled"; 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/zynqmp-lockstep.dtso: -------------------------------------------------------------------------------- 1 | /* Applies to all zynqmp boards to select split mode */ 2 | 3 | /dts-v1/; 4 | /plugin/; 5 | 6 | &rproc_lockstep { 7 | status = "okay"; 8 | }; 9 | 10 | &rproc_split { 11 | status = "disabled"; 12 | }; 13 | -------------------------------------------------------------------------------- /examples/linux/dts/xilinx/zynqmp-openamp.dtso: -------------------------------------------------------------------------------- 1 | /* Applies to all zynqmp boards to configure the IPC & memory for OpenAMP 2 | ** This configuration is compatible with zephyr rpmsg and other modern uses of 3 | ** rpmsg 4 | */ 5 | 6 | /dts-v1/; 7 | /plugin/; 8 | 9 | &{/} { 10 | #address-cells = <2>; 11 | #size-cells = <2>; 12 | 13 | reserved-memory { 14 | #address-cells = <0x02>; 15 | #size-cells = <0x02>; 16 | ranges; 17 | 18 | rproc_0_fw_image: memory@3ed00000 { 19 | no-map; 20 | reg = <0x0 0x3ed00000 0x0 0x40000>; 21 | }; 22 | 23 | rpu0vdev0vring0: vdev0vring0@3ed40000 { 24 | no-map; 25 | reg = <0x00 0x3ed40000 0x00 0x4000>; 26 | }; 27 | 28 | rpu0vdev0vring1: vdev0vring1@3ed44000 { 29 | no-map; 30 | reg = <0x00 0x3ed44000 0x00 0x4000>; 31 | }; 32 | 33 | rpu0vdev0buffer: vdev0buffer@3ed48000 { 34 | no-map; 35 | compatible = "shared-dma-pool"; 36 | reg = <0x00 0x3ed48000 0x00 0x100000>; 37 | }; 38 | 39 | rproc_1_fw_image: memory@3ef00000 { 40 | no-map; 41 | reg = <0x0 0x3ef00000 0x0 0x40000>; 42 | }; 43 | 44 | rpu1vdev0vring0: vdev0vring0@3ef40000 { 45 | no-map; 46 | reg = <0x00 0x3ef40000 0x00 0x4000>; 47 | }; 48 | 49 | rpu1vdev0vring1: vdev0vring1@3ef44000 { 50 | no-map; 51 | reg = <0x00 0x3ef44000 0x00 0x4000>; 52 | }; 53 | 54 | rpu1vdev0buffer: vdev0buffer@3ef48000 { 55 | no-map; 56 | compatible = "shared-dma-pool"; 57 | reg = <0x00 0x3ef48000 0x00 0x100000>; 58 | }; 59 | }; 60 | 61 | zynqmp-ipi { 62 | #address-cells = <2>; 63 | #size-cells = <2>; 64 | ranges; 65 | 66 | ipi_mailbox_rpu0: mailbox@ff990040 { 67 | reg = <0x00 0xff990040 0x00 0x20>, 68 | <0x00 0xff990060 0x00 0x20>, 69 | <0x00 0xff990200 0x00 0x20>, 70 | <0x00 0xff990220 0x00 0x20>; 71 | reg-names = "local_request_region", 72 | "local_response_region", 73 | "remote_request_region", 74 | "remote_response_region"; 75 | #mbox-cells = <0x01>; 76 | xlnx,ipi-id = <0x01>; 77 | }; 78 | 79 | ipi_mailbox_rpu1: mailbox@ff990080 { 80 | reg = <0x00 0xff990420 0x00 0x20>, 81 | <0x00 0xff990440 0x00 0x20>, 82 | <0x00 0xff990260 0x00 0x20>, 83 | <0x00 0xff990280 0x00 0x20>; 84 | reg-names = "local_request_region", 85 | "local_response_region", 86 | "remote_request_region", 87 | "remote_response_region"; 88 | #mbox-cells = <0x01>; 89 | xlnx,ipi-id = <0x02>; 90 | }; 91 | }; 92 | 93 | rproc_lockstep: remoteproc { 94 | status = "disabled"; 95 | r5f@0 { 96 | memory-region = <&rproc_0_fw_image>, <&rpu0vdev0vring0>, 97 | <&rpu0vdev0vring1>, <&rpu0vdev0buffer>; 98 | mboxes = <&ipi_mailbox_rpu0 0>, <&ipi_mailbox_rpu0 1>; 99 | mbox-names = "tx", "rx"; 100 | }; 101 | 102 | r5f@1 { 103 | memory-region = <&rproc_1_fw_image>, <&rpu1vdev0vring0>, 104 | <&rpu1vdev0vring1>, <&rpu1vdev0buffer>; 105 | mboxes = <&ipi_mailbox_rpu1 0>, <&ipi_mailbox_rpu1 1>; 106 | mbox-names = "tx", "rx"; 107 | }; 108 | }; 109 | 110 | rproc_split: remoteproc-split { 111 | status = "okay"; 112 | r5f@0 { 113 | memory-region = <&rproc_0_fw_image>, <&rpu0vdev0vring0>, 114 | <&rpu0vdev0vring1>, <&rpu0vdev0buffer>; 115 | mboxes = <&ipi_mailbox_rpu0 0>, <&ipi_mailbox_rpu0 1>; 116 | mbox-names = "tx", "rx"; 117 | }; 118 | 119 | r5f@1 { 120 | memory-region = <&rproc_1_fw_image>, <&rpu1vdev0vring0>, 121 | <&rpu1vdev0vring1>, <&rpu1vdev0buffer>; 122 | mboxes = <&ipi_mailbox_rpu1 0>, <&ipi_mailbox_rpu1 1>; 123 | mbox-names = "tx", "rx"; 124 | }; 125 | }; 126 | }; 127 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-echo-test/Makefile: -------------------------------------------------------------------------------- 1 | 2 | APP = echo_test 3 | APP_OBJS = echo_test.o ../common/common.o 4 | 5 | # Add any other object files to this list below 6 | 7 | 8 | all: $(APP) 9 | 10 | $(APP): $(APP_OBJS) 11 | $(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS) 12 | 13 | clean: 14 | rm -rf $(APP) $(APP_OBJS) 15 | 16 | %.o: %.c 17 | $(CC) -c $(CFLAGS) -o $@ $< 18 | 19 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-echo-test/README.md: -------------------------------------------------------------------------------- 1 | # Demo: echo_test 2 | 3 | This demo uses the Linux kernel rpmsg framework to send various size of data buffer to remote 4 | processor and validates integrity of received buffer from remote processor. 5 | If buffer data does not match, then number of different bytes are reported on 6 | console. 7 | 8 | Platform: Xilinx Zynq UltraScale+ MPSoC(a.k.a ZynqMP) 9 | 10 | Board: ZynqMP Zcu102 11 | 12 | ## Remote Processor firmware (image_echo_test) 13 | 14 | * Remote processor firmware for Xilinx ZynqMP cortex-r5 platform based on: [rpmsg-echo.c](https://github.com/OpenAMP/open-amp/blob/main/apps/examples/echo/rpmsg-echo.c) 15 | 16 | * Instructions to compile: [ZynqMP r5f generic baremetal](https://github.com/OpenAMP/open-amp/blob/main/README.md#example-to-compile-zynq-ultrascale-mpsoc-r5-genericbaremetal-remote) 17 | 18 | * RPU firmware elf file is expected in sdk at path: /lib/firmware/ 19 | 20 | * Xilinx Vendor specific SDK is required to build RPU firmware: [Xilinx Petalinux](https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools.html) 21 | 22 | * More information is provided here: [Xilinx Wiki page for OpenAMP](https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841718/OpenAMP) 23 | 24 | ## Run the demo 25 | 26 | Assume all the binaries are board specific. 27 | 28 | ``` 29 | # Specify remote processor firmware to be loaded. 30 | echo image_echo_test > /sys/class/remoteproc/remoteproc0/firmware 31 | 32 | # Load and start target firmware onto remote processor 33 | echo start > /sys/class/remoteproc/remoteproc0/state 34 | 35 | # check remote processor state 36 | cat /sys/class/remoteproc/remoteproc0/state 37 | 38 | # load rpmsg_char driver 39 | modprobe rpmsg_char 40 | 41 | # load rpmsg_ctrl driver 42 | modprobe rpmsg_ctrl 43 | 44 | # Run echo_test application on host processor 45 | echo_test 46 | 47 | # unload rpmsg_ctrl driver 48 | modprobe -r rpmsg_ctrl 49 | 50 | #unload rpmsg_char driver 51 | modprobe -r rpmsg_char 52 | 53 | # Stop remote processor 54 | echo stop > /sys/class/remoteproc/remoteproc0/state 55 | ``` 56 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-mat-mul/Makefile: -------------------------------------------------------------------------------- 1 | 2 | APP = mat_mul_demo 3 | APP_OBJS = mat_mul_demo.o ../common/common.o 4 | 5 | # Add any other object files to this list below 6 | 7 | 8 | all: $(APP) 9 | 10 | $(APP): $(APP_OBJS) 11 | $(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS) -lpthread 12 | 13 | clean: 14 | rm -rf $(APP) $(APP_OBJS) 15 | 16 | %.o: %.c 17 | $(CC) -c $(CFLAGS) -o $@ $< 18 | 19 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-mat-mul/README.md: -------------------------------------------------------------------------------- 1 | # Demo: matrix multiply 2 | 3 | This example demonstrate interprocessor communication using rpmsg framework 4 | in the Linux kernelspace. Host (this) application generates two random matrices and send 5 | them to remote processor using rpmsg framework in the Linux kernelspace and waits for 6 | the response. Remote processor firmware receives both matrices and 7 | multiplies them and sends result back to host processor. 8 | Host processor prints the result on console after receiveing it. 9 | If -n option is passed, then above demo runs times. 10 | User can also pass custom endpoint information with -s (source address) 11 | and -e (destination address) options as well. 12 | 13 | Platform: Xilinx Zynq UltraScale+ MPSoC(a.k.a ZynqMP) 14 | 15 | Board: ZynqMP Zcu102 16 | 17 | ## Remote Processor firmware (image_matrix_multiply) 18 | 19 | * Remote processor firmware for Xilinx ZynqMP cortex-r5 platform based on: [matrix_multiply.c](https://github.com/OpenAMP/open-amp/blob/main/apps/examples/matrix_multiply/matrix_multiply.c) 20 | 21 | * Instructions to compile: [ZynqMP r5f generic baremetal](https://github.com/OpenAMP/open-amp/blob/main/README.md#example-to-compile-zynq-ultrascale-mpsoc-r5-genericbaremetal-remote) 22 | 23 | * RPU firmware elf file is expected in sdk at path: /lib/firmware/ 24 | 25 | * Xilinx Vendor specific SDK is required to build RPU firmware: [Xilinx Petalinux](https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools.html) 26 | * More information is provided here: [Xilinx Wiki page for OpenAMP](https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841718/OpenAMP) 27 | 28 | ## Run the demo 29 | 30 | Assume all the binaries are board specific. 31 | 32 | ``` 33 | # Specify remote processor firmware to be loaded. 34 | echo image_matrix_multiply > /sys/class/remoteproc/remoteproc0/firmware 35 | 36 | # Load and start target Firmware onto remote processor 37 | echo start > /sys/class/remoteproc/remoteproc0/state 38 | 39 | # check remote processor state 40 | cat /sys/class/remoteproc/remoteproc0/state 41 | 42 | # load rpmsg_char driver 43 | modprobe rpmsg_char 44 | 45 | # load rpmsg_ctrl driver 46 | modprobe rpmsg_ctrl 47 | 48 | # Run Matrix multiplication application on host processor 49 | mat_mul_demo 50 | 51 | # unload rpmsg_ctrl driver 52 | modprobe -r rpmsg_ctrl 53 | 54 | #unload rpmsg_char driver 55 | modprobe -r rpmsg_char 56 | 57 | # Stop remote processor 58 | echo stop > /sys/class/remoteproc/remoteproc0/state 59 | ``` 60 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-mat-mul/mat_mul_demo.c: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: BSD-3-Clause 2 | 3 | /* 4 | * Sample demo application that showcases inter processor 5 | * communication from linux userspace to a remote software 6 | * context. The application generates random matrices and 7 | * transmits them to the remote context over rpmsg. The 8 | * remote application performs multiplication of matrices 9 | * and transmits the results back to this application. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "../common/common.h" 24 | 25 | #define RPMSG_BUS_SYS "/sys/bus/rpmsg" 26 | 27 | #define SHUTDOWN_MSG 0xEF56A55A 28 | #define MATRIX_SIZE 6 29 | 30 | struct _matrix { 31 | unsigned int size; 32 | unsigned int elements[MATRIX_SIZE][MATRIX_SIZE]; 33 | }; 34 | 35 | static void matrix_print(struct _matrix *m) 36 | { 37 | int i, j; 38 | 39 | for (i = 0; i < m->size; ++i) { 40 | for (j = 0; j < m->size; ++j) 41 | printf(" %3d ", (unsigned int)m->elements[i][j]); 42 | printf("\r\n"); 43 | } 44 | printf("\r\n"); 45 | } 46 | 47 | static void generate_matrices(int num_matrices, 48 | unsigned int matrix_size, void *p_data) 49 | { 50 | int i, j, k; 51 | struct _matrix *p_matrix = p_data; 52 | time_t t; 53 | unsigned long value; 54 | 55 | srand((unsigned) time(&t)); 56 | 57 | for (i = 0; i < num_matrices; i++) { 58 | /* Initialize workload */ 59 | p_matrix[i].size = matrix_size; 60 | 61 | for (j = 0; j < matrix_size; j++) { 62 | for (k = 0; k < matrix_size; k++) { 63 | 64 | value = (rand() & 0x7F); 65 | value = value % 10; 66 | p_matrix[i].elements[j][k] = value; 67 | } 68 | } 69 | 70 | printf(" \r\n Host : Linux : Input matrix %d \r\n", i); 71 | matrix_print(&p_matrix[i]); 72 | } 73 | 74 | } 75 | 76 | void matrix_mult(int fd) 77 | { 78 | struct _matrix i_matrix[2]; 79 | struct _matrix r_matrix; 80 | 81 | /* Generate two random matrices */ 82 | generate_matrices(2, MATRIX_SIZE, i_matrix); 83 | 84 | printf("Sending RPMSG: %lu bytes\n", sizeof(i_matrix)); 85 | ssize_t rc = write(fd, i_matrix, sizeof(i_matrix)); 86 | if (rc < 0) 87 | fprintf(stderr, "write,errno = %ld, %d\n", rc, errno); 88 | 89 | do { 90 | rc = read(fd, &r_matrix, sizeof(r_matrix)); 91 | } while (rc < (int)sizeof(r_matrix)); 92 | printf("Received RPMSG: %lu bytes\n", rc); 93 | 94 | printf(" \r\n Host : Linux : Printing results \r\n"); 95 | matrix_print(&r_matrix); 96 | } 97 | 98 | /* The firmware looks for SHUTDOWN_MSG in the first 32 bits */ 99 | void send_shutdown(int fd) 100 | { 101 | uint32_t msg = SHUTDOWN_MSG; 102 | if (write(fd, &msg, sizeof(msg)) < 0) 103 | perror("write SHUTDOWN_MSG\n"); 104 | } 105 | 106 | void print_help(void) 107 | { 108 | extern char *__progname; 109 | printf("\r\nusage: %s [option: -d, -c, -n, -s, -e]\r\n", __progname); 110 | printf("-d - rpmsg device name\r\n"); 111 | printf("-c - rpmsg control device name\r\n"); 112 | printf("-n - number of times this demo is repeated\r\n"); 113 | printf("-s - source end point address\r\n"); 114 | printf("-e - destination end point address\r\n"); 115 | printf("\r\n"); 116 | } 117 | 118 | int main(int argc, char *argv[]) 119 | { 120 | int ntimes = 1; 121 | int opt, ret, fd, charfd = -1; 122 | char rpmsg_dev[NAME_MAX] = "virtio0.rpmsg-openamp-demo-channel.-1.0"; 123 | char rpmsg_ctrl_dev_name[NAME_MAX] = "virtio0.rpmsg_ctrl.0.0"; 124 | char rpmsg_char_name[16]; 125 | char fpath[2*NAME_MAX]; 126 | struct rpmsg_endpoint_info eptinfo = { 127 | .name = "rpmsg-openamp-demo-channel", .src = 0, .dst = 0 128 | }; 129 | char ept_dev_name[16]; 130 | char ept_dev_path[32]; 131 | 132 | printf("Matrix multiplication demo start\n"); 133 | lookup_channel(rpmsg_dev, &eptinfo); 134 | 135 | while ((opt = getopt(argc, argv, "d:c:n:s:e:")) != -1) { 136 | switch (opt) { 137 | case 'd': 138 | memset(rpmsg_dev, 0, sizeof(rpmsg_dev)); 139 | strncpy(rpmsg_dev, optarg, sizeof(rpmsg_dev)); 140 | break; 141 | case 'c': 142 | memset(rpmsg_ctrl_dev_name, 0, sizeof(rpmsg_ctrl_dev_name)); 143 | strncpy(rpmsg_ctrl_dev_name, optarg, sizeof(rpmsg_ctrl_dev_name)); 144 | break; 145 | case 'n': 146 | ntimes = strtol(optarg, NULL, 10); 147 | break; 148 | case 's': 149 | eptinfo.src = strtol(optarg, NULL, 10); 150 | break; 151 | case 'e': 152 | eptinfo.dst = strtol(optarg, NULL, 10); 153 | break; 154 | default: 155 | print_help(); 156 | return -EINVAL; 157 | } 158 | } 159 | 160 | sprintf(fpath, RPMSG_BUS_SYS "/devices/%s", rpmsg_dev); 161 | if (access(fpath, F_OK)) { 162 | fprintf(stderr, "access(%s): %s\n", fpath, strerror(errno)); 163 | return -EINVAL; 164 | } 165 | ret = bind_rpmsg_chrdev(rpmsg_dev); 166 | if (ret < 0) 167 | return ret; 168 | 169 | /* The Linux kernel >= 6.0 expects rpmsg_ctrl interface under virtio*.rpmsg_ctrl*.* dir */ 170 | charfd = get_rpmsg_chrdev_fd(rpmsg_ctrl_dev_name, rpmsg_char_name); 171 | if (charfd < 0) { 172 | /* look for previous interface */ 173 | charfd = get_rpmsg_chrdev_fd(rpmsg_dev, rpmsg_char_name); 174 | if (charfd < 0) 175 | return charfd; 176 | } 177 | 178 | /* Create endpoint from rpmsg char driver */ 179 | printf("Creating RPMSG endpoint with name: %s, src=%#x, dst=%#x\n", 180 | eptinfo.name, eptinfo.src, eptinfo.dst); 181 | ret = app_rpmsg_create_ept(charfd, &eptinfo); 182 | if (ret) { 183 | fprintf(stderr, "app_rpmsg_create_ept %s\n", strerror(errno)); 184 | return -EINVAL; 185 | } 186 | if (!get_rpmsg_ept_dev_name(rpmsg_char_name, eptinfo.name, 187 | ept_dev_name)) 188 | return -EINVAL; 189 | sprintf(ept_dev_path, "/dev/%s", ept_dev_name); 190 | 191 | printf("open %s\n", ept_dev_path); 192 | fd = open(ept_dev_path, O_RDWR | O_NONBLOCK); 193 | if (fd < 0) { 194 | perror(ept_dev_path); 195 | close(charfd); 196 | return -1; 197 | } 198 | 199 | printf("Start of Matrix multiplication demo with %d rounds\n", ntimes); 200 | for (int i = 0; i < ntimes; i++) { 201 | matrix_mult(fd); 202 | printf("End of Matrix multiplication demo round %d\n", i); 203 | } 204 | 205 | send_shutdown(fd); 206 | close(fd); 207 | if (charfd >= 0) 208 | close(charfd); 209 | 210 | printf("\r\n Quitting application .. \r\n"); 211 | printf(" Matrix multiply application end \r\n"); 212 | 213 | return 0; 214 | } 215 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-proxy-app/Makefile: -------------------------------------------------------------------------------- 1 | 2 | APP = proxy_app 3 | APP_OBJS = proxy_app.o ../common/common.o 4 | 5 | # Add any other object files to this list below 6 | 7 | 8 | all: $(APP) 9 | 10 | $(APP): $(APP_OBJS) 11 | $(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS) 12 | 13 | clean: 14 | rm -rf $(APP) $(APP_OBJS) 15 | 16 | %.o: %.c 17 | $(CC) -c $(CFLAGS) -o $@ $< 18 | 19 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-proxy-app/README.md: -------------------------------------------------------------------------------- 1 | # Demo: proxy_app 2 | 3 | This app demonstrates two functionality 4 | 1) Use of host processor's file system by remote processor 5 | 2) remote processor's standard IO redirection to host processor's standard IO 6 | 7 | 8 | case 1: This app allows remote processor to use file system of host processor. Host 9 | processor file system acts as proxy of remote file system. Remote processor 10 | can use open, read, write, close calls to interact with files on host 11 | processor. 12 | 13 | File "remote.file" is available after app exits on host side that is created by 14 | remote processor that contains string "This is a test string being written to 15 | file.." written by remote firmware. This demonstrates remote firmware can 16 | create and write files on host side. 17 | 18 | case 2: This application also demonstrates redirection of standard IO. 19 | Remote processor can use host processor's stdin and stdout via proxy service 20 | that is implemented on host side. This is achieved with open-amp proxy 21 | service implemented here: [rpmsg_retarget.c](https://github.com/OpenAMP/open-amp/blob/main/lib/proxy/rpmsg_retarget.c) 22 | Remote side firmware uses two types of output functions to print message on 23 | console 1) xil_printf i.e. using same UART console as of APU and 2) Standard 24 | "printf" function that is re-directed to standard output of Host. Both function 25 | uses different ways to output messages, but using same console. 26 | 27 | This is interactive demo: 28 | 1. When the remote application prompts you to Enter name, enter any string without space. 29 | 2. When the remote application prompts you to Enter age , enter any integer. 30 | 3. When the remote application prompts you to Enter value for pi, enter any floating 31 | point number. 32 | After this, remote application will print all the inputs entered by user on console 33 | of host processor. 34 | 35 | Remote firmware's standard IO are redirected to host processor's standard IO. 36 | So, when remote uses "printf" and "scanf" functions actually host processor's 37 | console is used for printing output and scanning inputs. Host communicates with 38 | remote via rpmsg_char driver and Remote communicates to Host via redirected 39 | Standard IO. 40 | 41 | Platform: Xilinx Zynq UltraScale+ MPSoC(a.k.a ZynqMP) 42 | 43 | Board: ZynqMP Zcu102 44 | 45 | ## Remote Processor firmware (image_rpc_demo) 46 | 47 | * Remote processor firmware for Xilinx ZynqMP cortex-r5 platform based on: [rpc_demo.c](https://github.com/OpenAMP/open-amp/blob/main/apps/examples/rpc_demo/rpc_demo.c) 48 | 49 | * Instructions to compile: [ZynqMP r5f generic baremetal](https://github.com/OpenAMP/open-amp/blob/main/README.md#example-to-compile-zynq-ultrascale-mpsoc-r5-genericbaremetal-remote) 50 | 51 | * RPU firmware elf file is expected in sdk at path: /lib/firmware/ 52 | 53 | * Xilinx Vendor specific SDK is required to build RPU firmware: [Xilinx Petalinux](https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools.html) 54 | 55 | * More information is provided here: [Xilinx Wiki page for OpenAMP](https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841718/OpenAMP) 56 | 57 | ## Run the demo 58 | 59 | Assume all the binaries are zcu102 board specific. 60 | 61 | ``` 62 | # Specify remote processor firmware to be loaded. 63 | echo image_rpc_demo > /sys/class/remoteproc/remoteproc0/firmware 64 | 65 | # Load and start target Firmware onto remote processor. 66 | echo start > /sys/class/remoteproc/remoteproc0/state 67 | 68 | # load rpmsg_char driver 69 | modprobe rpmsg_char 70 | 71 | # load rpmsg_ctrl driver 72 | modprobe rpmsg_ctrl 73 | 74 | # Run proxy application. 75 | proxy_app 76 | 77 | # unload rpmsg_ctrl driver 78 | modprobe -r rpmsg_ctrl 79 | 80 | #unload rpmsg_char driver 81 | modprobe -r rpmsg_char 82 | 83 | # Stop target firmware 84 | echo stop > /sys/class/remoteproc/remoteproc0/state 85 | ``` 86 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-proxy-app/proxy_app.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* System call definitions */ 4 | #define OPEN_SYSCALL_ID 1 5 | #define CLOSE_SYSCALL_ID 2 6 | #define WRITE_SYSCALL_ID 3 7 | #define READ_SYSCALL_ID 4 8 | #define ACK_STATUS_ID 5 9 | #define TERM_SYSCALL_ID 6 10 | 11 | 12 | #define FILE_NAME_LEN 50 13 | 14 | struct _rpc_data { 15 | struct rpmsg_channel *rpmsg_chnl; 16 | struct rpmsg_endpoint *rp_ept; 17 | void *rpc_lock; 18 | void *sync_lock; 19 | void *data; 20 | }; 21 | 22 | struct _sys_call_args { 23 | int32_t int_field1; 24 | int32_t int_field2; 25 | uint32_t data_len; 26 | char data[0]; 27 | }; 28 | 29 | /* System call rpc data structure */ 30 | struct _sys_rpc { 31 | uint32_t id; 32 | struct _sys_call_args sys_call_args; 33 | }; 34 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Linaro Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/Makefile: -------------------------------------------------------------------------------- 1 | EPT := rpmsg_export_ept 2 | EPTD = rpmsg_destroy_ept 3 | PING = rpmsg_ping 4 | DEV = rpmsg_export_dev 5 | 6 | CFLAGS := -Wall -g -O2 7 | LDFLAGS := 8 | prefix := /usr/local 9 | 10 | SRCS := rpmsg_export_ept.c 11 | SRCS += rpmsg_destroy_ept.c 12 | SRCS += rpmsg_ping.c 13 | SRCS += rpmsg_export_dev.c 14 | OBJS := $(SRCS:.c=.o) 15 | 16 | all: $(EPT) $(EPTD) $(PING) $(DEV) 17 | .PHONY : all 18 | 19 | $(EPT): rpmsg_export_ept.o 20 | $(CC) $(LDFLAGS) -o $@ $^ 21 | 22 | $(EPTD): rpmsg_destroy_ept.o 23 | $(CC) $(LDFLAGS) -o $@ $^ 24 | 25 | $(PING): rpmsg_ping.o 26 | $(CC) $(LDFLAGS) -o $@ $^ 27 | 28 | 29 | $(DEV): rpmsg_export_dev.o 30 | $(CC) $(LDFLAGS) -o $@ $^ 31 | 32 | install: $(EPT) $(EPTD) $(PING) $(DEV) 33 | install -D -m 755 $(EPT) $(DESTDIR)$(prefix)/bin/$(EPT) 34 | install -D -m 755 $(EPTD) $(DESTDIR)$(prefix)/bin/$(EPTD) 35 | install -D -m 755 $(PING) $(DESTDIR)$(prefix)/bin/$(PING) 36 | install -D -m 755 $(DEV) $(DESTDIR)$(prefix)/bin/$(DEV) 37 | 38 | clean: 39 | rm -f $(EPT) $(EPTD) $(PING) $(OBJS) $(DEV) 40 | 41 | distclean: 42 | rm -f $(DESTDIR)$(prefix)/bin/$(EPT) 43 | rm -f $(DESTDIR)$(prefix)/bin/$(EPTD) 44 | rm -f $(DESTDIR)$(prefix)/bin/$(PING) 45 | rm -f $(DESTDIR)$(prefix)/bin/$(DEV) 46 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/README: -------------------------------------------------------------------------------- 1 | rpmsgexport 2 | =========== 3 | 4 | rpmsg_export_ept implements RPMSG_CREATE_EPT_IOCTL for usage in udev rules to 5 | automatically create endpoint devices as remoteproc devices are booted. 6 | 7 | An example of udev-rule that automatically exposes the APPS_RIVA_CTRL channel 8 | to user space as the pronto core comes up: 9 | 10 | ACTION=="add", SUBSYSTEM=="rpmsg", \ 11 | KERNEL=="rpmsg_ctrl[0-9]*", \ 12 | ATTRS{rpmsg_name}=="pronto", \ 13 | RUN+="rpmsg_export_ept /dev/$name APPS_RIVA_CTRL" 14 | 15 | Which together with the following two udev rules creates a nice directory 16 | structure of rpmsg endpoint devices under /dev/rpmsg: 17 | 18 | SUBSYSTEM=="rpmsg", KERNEL=="rpmsg_ctrl[0-9]*", \ 19 | ATTRS{rpmsg_name}=="?*", \ 20 | SYMLINK+="rpmsg/$attr{rpmsg_name}/ctrl" 21 | SUBSYSTEM=="rpmsg", KERNEL=="rpmsg[0-9]*", \ 22 | ATTR{name}=="?*", \ 23 | ATTRS{rpmsg_name}=="?*", \ 24 | SYMLINK+="rpmsg/$attr{rpmsg_name}/$attr{name}" 25 | 26 | eptdestroy 27 | ==== 28 | "rpmsg_destroy_ept" implements RPMSG_DESTROY_EPT_IOCTL to destroy an endpoint created by the RPMSG_CREATE_EPT_IOCTL. 29 | 30 | ping 31 | ==== 32 | "rpmsg_ping" is a test binary that opens a rpmsg chardev for an echo test (write a pattern and wait an answer) 33 | 34 | rpmsgexportdev 35 | ============== 36 | "rpmsg_export_dev" implements RPMSG_CREATE_DEV_IOCTL to create local RPMsg device 37 | as remoteproc devices are booted. 38 | Adding option -d as first argument release the device using RPMSG_RELEASE_DEV_IOCTL control. -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/rpmsg_destroy_ept.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022, STMicroelectronics 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2) 42 | 43 | static void usage(void) 44 | { 45 | extern char *__progname; 46 | 47 | fprintf(stderr, "%s \n", __progname); 48 | exit(1); 49 | } 50 | 51 | int main(int argc, char **argv) 52 | { 53 | int ret; 54 | int fd; 55 | 56 | if (argc != 2) 57 | usage(); 58 | 59 | fd = open(argv[1], O_RDWR); 60 | if (fd < 0) 61 | err(1, "failed to open %s\n", argv[1]); 62 | 63 | ret = ioctl(fd, RPMSG_DESTROY_EPT_IOCTL, NULL); 64 | if (ret < 0) { 65 | fprintf(stderr, "failed to destroy endpoint"); 66 | exit(1); 67 | } 68 | 69 | close(fd); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/rpmsg_export_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022, STMicroelectronics 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | struct rpmsg_endpoint_info { 42 | char name[32]; 43 | uint32_t src; 44 | uint32_t dst; 45 | }; 46 | 47 | #define RPMSG_CREATE_DEV_IOCTL _IOW(0xb5, 0x3, struct rpmsg_endpoint_info) 48 | #define RPMSG_RELEASE_DEV_IOCTL _IOW(0xb5, 0x4, struct rpmsg_endpoint_info) 49 | 50 | static void usage(void) 51 | { 52 | extern char *__progname; 53 | 54 | fprintf(stderr, "%s [-d] [ ]\n", __progname); 55 | exit(1); 56 | } 57 | 58 | int main(int argc, char **argv) 59 | { 60 | struct rpmsg_endpoint_info ept; 61 | int ret, fd; 62 | int release = 0; 63 | char *endptr; 64 | 65 | if (argv[2][0] == '-') { 66 | if (argv[1][1] == 'd') { 67 | if (argc != 4 && argc != 6) 68 | goto error_usage; 69 | release = 1; 70 | } else if (argv[1][1] == 'h') { 71 | usage(); 72 | return 0; 73 | } else { 74 | printf("Invalid option.\n"); 75 | goto error_usage; 76 | } 77 | } else if (argc != 3 && argc != 5) { 78 | goto error_usage; 79 | } 80 | 81 | fd = open(argv[1], O_RDWR); 82 | if (fd < 0) 83 | err(1, "failed to open %s\n", argv[1]); 84 | 85 | strncpy(ept.name, argv[2 + release], sizeof(ept.name)); 86 | ept.name[sizeof(ept.name) - 1] = '\0'; 87 | 88 | if (argc >= 5) { 89 | ept.src = strtoul(argv[3 + release], &endptr, 10); 90 | 91 | if (*endptr) 92 | usage(); 93 | 94 | ept.dst = strtoul(argv[4 + release], &endptr, 10); 95 | 96 | if (*endptr) 97 | usage(); 98 | } 99 | 100 | if (!release) 101 | ret = ioctl(fd, RPMSG_CREATE_DEV_IOCTL, &ept); 102 | else 103 | ret = ioctl(fd, RPMSG_RELEASE_DEV_IOCTL, &ept); 104 | if (ret < 0) 105 | fprintf(stderr, "failed to %s rpmsg device\n", release ? "release" : "create"); 106 | close(fd); 107 | return ret; 108 | 109 | error_usage: 110 | usage(); 111 | return 2; 112 | } 113 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/rpmsg_export_ept.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Linaro Ltd. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | struct rpmsg_endpoint_info { 42 | char name[32]; 43 | uint32_t src; 44 | uint32_t dst; 45 | }; 46 | 47 | #define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info) 48 | 49 | static void usage(void) 50 | { 51 | extern char *__progname; 52 | 53 | fprintf(stderr, "%s [ ]\n", __progname); 54 | exit(1); 55 | } 56 | 57 | int main(int argc, char **argv) 58 | { 59 | struct rpmsg_endpoint_info ept; 60 | int ret; 61 | int fd; 62 | char *endptr; 63 | 64 | if (argc != 3 && argc != 5) 65 | usage(); 66 | 67 | fd = open(argv[1], O_RDWR); 68 | if (fd < 0) 69 | err(1, "failed to open %s\n", argv[1]); 70 | 71 | strncpy(ept.name, argv[2], sizeof(ept.name)); 72 | ept.name[sizeof(ept.name)-1] = '\0'; 73 | 74 | if (argc == 5) { 75 | ept.src = strtoul(argv[3], &endptr, 10); 76 | 77 | if (*endptr) 78 | usage(); 79 | 80 | ept.dst = strtoul(argv[4], &endptr, 10); 81 | 82 | if (*endptr) 83 | usage(); 84 | } 85 | 86 | ret = ioctl(fd, RPMSG_CREATE_EPT_IOCTL, &ept); 87 | if (ret < 0) { 88 | fprintf(stderr, "failed to create endpoint"); 89 | exit(1); 90 | } 91 | 92 | close(fd); 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /examples/linux/rpmsg-utils/rpmsg_ping.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022, STMicroelectronics 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | static void usage(void) 42 | { 43 | extern char *__progname; 44 | 45 | fprintf(stderr, "%s \n", __progname); 46 | exit(1); 47 | } 48 | 49 | int main(int argc, char **argv) 50 | { 51 | char buffer[256]; 52 | int ret; 53 | int fd; 54 | 55 | if (argc != 2) 56 | usage(); 57 | 58 | fd = open(argv[1], O_RDWR); 59 | if (fd < 0) 60 | err(1, "failed to open %s\n", argv[1]); 61 | 62 | sprintf(buffer, "ping %s", argv[1]); 63 | ret = write(fd, buffer, strlen(buffer)); 64 | if (ret < 0) { 65 | fprintf(stderr, "failed to write endpoint %s", argv[1]); 66 | exit(1); 67 | } 68 | ret = read(fd, buffer, 256); 69 | if (ret < 0) { 70 | fprintf(stderr, "failed to read endpoint %s", argv[1]); 71 | exit(1); 72 | } 73 | fprintf(stderr, "message received: \"%s\"\n", buffer); 74 | 75 | close(fd); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /examples/zephyr/README.md: -------------------------------------------------------------------------------- 1 | # Zephyr Example Application 2 | 3 | This repository contains Zephyr example applications. The main purpose of this 4 | repository is to provide references and demo on the use of OpenAMP on Zephyr based applications. features demonstrated in this example are: 5 | 6 | - [rpmsg multi service][rms_app] application 7 | - [dual qemu ivshmem][dqi_app] application 8 | 9 | 10 | 11 | [rms_app]: #rpmsg_multi_services/README.md 12 | [dqi_app]: #dual_qemu_ivshmem/README.md 13 | 14 | ## Getting Started 15 | 16 | Before getting started, make sure you have a proper Zephyr development 17 | environment. You can follow the official 18 | [Zephyr Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html). 19 | 20 | ### Initialization 21 | 22 | The first step is to initialize the workspace folder (``my-workspace``) where 23 | the examples and all Zephyr modules will be cloned. You can do 24 | that by running: 25 | 26 | ```shell 27 | # initialize my-workspace for the example-application (main branch) 28 | west init -m https://github.com/OpenAMP/openamp-system-reference --mr main my-workspace 29 | # update Zephyr modules 30 | cd my-workspace 31 | west update 32 | ``` 33 | 34 | ### Build and run on a board 35 | 36 | The application can be built by running: 37 | 38 | ```shell 39 | west build -b $BOARD `$ZEPHYR_EXAMPLE` 40 | ``` 41 | 42 | where `$BOARD` is the target board and `$ZEPHYR_EXAMPLE`. 43 | Note that Zephyr sample boards may be used if an appropriate overlay is provided (see `app/boards`). 44 | 45 | A sample debug configuration is also provided. You can apply it by running: 46 | 47 | ```shell 48 | west build -b $BOARD $ZEPHYR_EXAMPLE -- -DOVERLAY_CONFIG=debug.conf 49 | ``` 50 | 51 | Example to compile rpmsg_multi_services on stm32mp157 discovery board: 52 | 53 | ```shell 54 | west build -b stm32mp157c_dk2 openamp-system-reference/examples/zephyr/rpmsg_multi_services 55 | ``` 56 | 57 | ### Running on a board 58 | 59 | We consider here board on which the Zephyr image is running on a coprocessor. 60 | 61 | 1) Once you have built the application copy it on target filesystem. 62 | 2) Load the Zephyr firmware and start the coprocessor depending on the board. 63 | 64 | Example of a Zephyr firmware image loading by the Linux kernel remoteproc framework. 65 | 66 | ```shell 67 | cp $ZEPHYR_EXAMPLE.elf /lib/modules/ 68 | echo $ZEPHYR_EXAMPLE.elf > /sys/class/remoteproc/remoteproc0/firmware 69 | echo start >/sys/class/remoteproc/remoteproc0/state 70 | ``` 71 | 72 | ### Running in an Emulator 73 | 74 | To be described -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/.gitignore: -------------------------------------------------------------------------------- 1 | /host/build/* 2 | /remote/build/* 3 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/host/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Linaro 2 | # SPDX-License-Identifier: Apache-2.0 3 | cmake_minimum_required(VERSION 3.20.0) 4 | 5 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 6 | project(openamp_rpmsg_over_ivshmem_host) 7 | 8 | target_include_directories(app PRIVATE ../rpmsg_ivshmem_backend) 9 | 10 | target_sources(app PRIVATE 11 | src/main.c 12 | ../rpmsg_ivshmem_backend/rpmsg_ivshmem_backend.c) 13 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/host/app.overlay: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Linaro. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include "boards/pcie_ivshmem.dtsi" 7 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/host/boards/pcie_ivshmem.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Linaro. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | 8 | / { 9 | ivhsmem { 10 | ivshmem0: ivshmem { 11 | compatible = "qemu,ivshmem"; 12 | 13 | vendor-id = <0x1af4>; 14 | device-id = <0x1110>; 15 | status = "okay"; 16 | }; 17 | }; 18 | }; 19 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/host/boards/qemu_cortex_a53.conf: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Linaro 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | CONFIG_PCIE_CONTROLLER=y 5 | CONFIG_PCIE_ECAM=y 6 | 7 | # Hungry PCI requires at least 256M of virtual space 8 | CONFIG_KERNEL_VM_SIZE=0x80000000 9 | 10 | # Hungry PCI requires phys addresses with more than 32 bits 11 | CONFIG_ARM64_VA_BITS_40=y 12 | CONFIG_ARM64_PA_BITS_40=y 13 | 14 | # MSI support requires ITS 15 | CONFIG_GIC_V3_ITS=y 16 | 17 | # ITS, in turn, requires dynamic memory (9x64 + alignment constrains) 18 | # Additionally, our test also uses malloc 19 | CONFIG_HEAP_MEM_POOL_SIZE=1048576 20 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/host/prj.conf: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Linaro 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | CONFIG_PCIE=y 5 | # required by doorbell 6 | CONFIG_PCIE_MSI=y 7 | CONFIG_PCIE_MSI_X=y 8 | CONFIG_PCIE_MSI_MULTI_VECTOR=y 9 | CONFIG_POLL=y 10 | 11 | CONFIG_VIRTUALIZATION=y 12 | CONFIG_IVSHMEM=y 13 | CONFIG_IVSHMEM_DOORBELL=y 14 | 15 | CONFIG_SHELL=y 16 | CONFIG_IVSHMEM_SHELL=n 17 | CONFIG_OPENAMP=y 18 | 19 | # Comment this line when building to the slave instance 20 | CONFIG_OPENAMP_SLAVE=n 21 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/host/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Linaro Limited 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include "rpmsg_ivshmem_backend.h" 12 | 13 | static struct rpmsg_endpoint ept; 14 | struct rpmsg_device *rpmsg_dev; 15 | static int number_of_completed_msgs; 16 | K_SEM_DEFINE(rx_sem, 0, 1); 17 | 18 | int endpoint_cb(struct rpmsg_endpoint *ept, void *data, 19 | size_t len, uint32_t src, void *priv) 20 | { 21 | number_of_completed_msgs++; 22 | 23 | printf("Remote side echoed the string back:\n"); 24 | printf("[ %s ]\n", (const char *)data); 25 | printf("at message number %d\n\n", number_of_completed_msgs); 26 | 27 | k_sem_give(&rx_sem); 28 | return RPMSG_SUCCESS; 29 | } 30 | 31 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 32 | { 33 | } 34 | 35 | void main(void) 36 | { 37 | rpmsg_dev = get_rpmsg_ivshmem_device(); 38 | 39 | if (!rpmsg_dev) { 40 | printf("Could not get the RPMsg device for IVSHMEM backend!\n"); 41 | return -1; 42 | } 43 | 44 | /* Creates the RPMSg endpoint to communicate with the remote side. 45 | */ 46 | int status = rpmsg_create_ept(&ept, rpmsg_dev, "k", RPMSG_ADDR_ANY, 47 | get_rpmsg_ivshmem_ept_dest_addr(), 48 | endpoint_cb, rpmsg_service_unbind); 49 | if (status != 0) { 50 | printf("rpmsg_create_ept failed %d\n", status); 51 | return status; 52 | } 53 | 54 | printf("Host Side, the communication over RPMsg is ready to use!\n"); 55 | 56 | return 0; 57 | } 58 | 59 | static int cmd_rpmsg_ivshmem_send(const struct shell *sh, size_t argc, char **argv) 60 | { 61 | char *str = argv[1]; 62 | int noof_messages = strtol(argv[2], NULL, 10); 63 | 64 | if (!rpmsg_dev) { 65 | printf("RPMsg over IVSHMEM backend is not ready yet!\n"); 66 | return -ENODEV; 67 | } 68 | 69 | number_of_completed_msgs = 0; 70 | 71 | do { 72 | int status = rpmsg_send(&ept, str, strlen(str) + 1); 73 | 74 | if (status < 0) { 75 | printf("failed to send message to the Remote side: %d\n", status); 76 | return status; 77 | } 78 | 79 | status = k_sem_take(&rx_sem, K_MSEC(5000)); 80 | if (status) { 81 | printf("Remote side response timed out!\n"); 82 | return status; 83 | } 84 | 85 | noof_messages--; 86 | 87 | } while (noof_messages); 88 | 89 | return 0; 90 | } 91 | 92 | SHELL_STATIC_SUBCMD_SET_CREATE(sub_rpmsg_ivshmem, 93 | SHELL_CMD_ARG(send, NULL, 94 | "Usage: rpmsg_ivshmem send " 95 | "", 96 | cmd_rpmsg_ivshmem_send, 3, 0), 97 | SHELL_SUBCMD_SET_END); 98 | 99 | SHELL_CMD_ARG_REGISTER(rpmsg_ivshmem, &sub_rpmsg_ivshmem, 100 | "Commands to use RPMsg over IVSHMEM", 101 | cmd_rpmsg_ivshmem_send, 3, 0); 102 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/remote/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Linaro 2 | # SPDX-License-Identifier: Apache-2.0 3 | cmake_minimum_required(VERSION 3.20.0) 4 | 5 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 6 | project(openamp_rpmsg_over_ivshmem_remote) 7 | 8 | target_include_directories(app PRIVATE ../rpmsg_ivshmem_backend) 9 | 10 | target_sources(app PRIVATE 11 | src/main.c 12 | ../rpmsg_ivshmem_backend/rpmsg_ivshmem_backend.c) 13 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/remote/app.overlay: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Linaro. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include "boards/pcie_ivshmem.dtsi" 7 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/remote/boards/pcie_ivshmem.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Linaro. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | 8 | / { 9 | ivhsmem { 10 | ivshmem0: ivshmem { 11 | compatible = "qemu,ivshmem"; 12 | 13 | vendor-id = <0x1af4>; 14 | device-id = <0x1110>; 15 | status = "okay"; 16 | }; 17 | }; 18 | }; 19 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/remote/boards/qemu_cortex_a53.conf: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Linaro 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | CONFIG_PCIE_CONTROLLER=y 5 | CONFIG_PCIE_ECAM=y 6 | 7 | # Hungry PCI requires at least 256M of virtual space 8 | CONFIG_KERNEL_VM_SIZE=0x80000000 9 | 10 | # Hungry PCI requires phys addresses with more than 32 bits 11 | CONFIG_ARM64_VA_BITS_40=y 12 | CONFIG_ARM64_PA_BITS_40=y 13 | 14 | # MSI support requires ITS 15 | CONFIG_GIC_V3_ITS=y 16 | 17 | # ITS, in turn, requires dynamic memory (9x64 + alignment constrains) 18 | # Additionally, our test also uses malloc 19 | CONFIG_HEAP_MEM_POOL_SIZE=1048576 20 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/remote/prj.conf: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 Linaro 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | CONFIG_PCIE=y 5 | # required by doorbell 6 | CONFIG_PCIE_MSI=y 7 | CONFIG_PCIE_MSI_X=y 8 | CONFIG_PCIE_MSI_MULTI_VECTOR=y 9 | CONFIG_POLL=y 10 | 11 | CONFIG_VIRTUALIZATION=y 12 | CONFIG_IVSHMEM=y 13 | CONFIG_IVSHMEM_DOORBELL=y 14 | 15 | CONFIG_SHELL=y 16 | CONFIG_IVSHMEM_SHELL=n 17 | CONFIG_OPENAMP=y 18 | CONFIG_OPENAMP_MASTER=n 19 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/remote/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Linaro Limited 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | 8 | #include 9 | #include 10 | #include "rpmsg_ivshmem_backend.h" 11 | 12 | static struct rpmsg_endpoint remote_ept; 13 | static struct rpmsg_device *rpmsg_dev; 14 | 15 | int endpoint_cb(struct rpmsg_endpoint *ept, void *data, 16 | size_t len, uint32_t src, void *priv) 17 | { 18 | printf("Host side sent a string:\n"); 19 | printf("[ %s ]\n", (const char *)data); 20 | printf("Now echoing it back!\n\n"); 21 | 22 | int status = rpmsg_send(&remote_ept, data, len); 23 | 24 | if (status < 0) 25 | printf("failed to send message to the Host side: %d\n", status); 26 | 27 | return RPMSG_SUCCESS; 28 | } 29 | 30 | static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) 31 | { 32 | } 33 | 34 | int main(void) 35 | { 36 | rpmsg_dev = get_rpmsg_ivshmem_device(); 37 | 38 | if (!rpmsg_dev) { 39 | printf("Could not get the RPMsg device for IVSHMEM backend!\n"); 40 | return -1; 41 | } 42 | 43 | /* Setup the endpoint, this will notify the host side and allow it 44 | * to finish the RPMsg communication estabilishement. 45 | */ 46 | int status = rpmsg_create_ept(&remote_ept, rpmsg_dev, "k", RPMSG_ADDR_ANY, 47 | RPMSG_ADDR_ANY, endpoint_cb, rpmsg_service_unbind); 48 | if (status != 0) { 49 | printf("rpmsg_create_ept failed %d\n", status); 50 | return status; 51 | } 52 | 53 | printf("Remote Side, the communication over RPMsg is ready to use!\n"); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/zephyr/dual_qemu_ivshmem/rpmsg_ivshmem_backend/rpmsg_ivshmem_backend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Linaro Limited 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef RPMSG_IVHSMEM_BACKEND_H__ 8 | #define RPMSG_IVHSMEM_BACKEND_H__ 9 | 10 | #include 11 | #include 12 | 13 | /** 14 | * @brief Get RPMsg-IVSHMEM, destination address 15 | * 16 | * @return other side destination address, -1 if none is found; 17 | */ 18 | int get_rpmsg_ivshmem_ept_dest_addr(void); 19 | 20 | /** 21 | * @brief Get RPMsg-IVSHMEM, initialized, backend device for RPMSg endpoint creation 22 | * 23 | * @return pointer to the initialized RPMsg device 24 | */ 25 | struct rpmsg_device *get_rpmsg_ivshmem_device(void); 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20.0) 2 | # Copyright (c) 2020 STMicroelectronics 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | 9 | project(rpmsg_multi_services) 10 | 11 | # METAL_MAX_DEVICE_REGIONS is used to give the number of memory regions shared 12 | # between processors. By default only one region is defined for the vrings 13 | # and rpmsg buffers. The METAL_MAX_DEVICE_REGIONS has to be redefined to add a 14 | # second region for the resource table. 15 | zephyr_compile_definitions(METAL_MAX_DEVICE_REGIONS=2) 16 | 17 | target_include_directories(app PRIVATE ${LIBMETAL_INCLUDE_DIR} ${OPENAMP_INCLUDE_DIR} ${PLATFORM_DIR}) 18 | 19 | target_sources(app PRIVATE src/main_remote.c) 20 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/boards/imx8mp_evk_mimx8ml8_adsp.conf: -------------------------------------------------------------------------------- 1 | CONFIG_IPM_IMX_MAX_DATA_SIZE_16=n 2 | CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y 3 | CONFIG_OPENAMP_WITH_DCACHE=y 4 | CONFIG_IPM_IMX_FW_READY_REPLY=y 5 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/boards/imx8mp_evk_mimx8ml8_adsp.overlay: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 NXP 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | / { 8 | chosen { 9 | /* 10 | * shared memory reserved for the inter-processor communication 11 | */ 12 | zephyr,ipc_shm = &dspsram3; 13 | zephyr,ipc = &mailbox0; 14 | }; 15 | 16 | dspsram3: memory@942f0000 { 17 | compatible = "mmio-sram"; 18 | reg = <0x942f0000 0x110000>; 19 | }; 20 | }; 21 | 22 | &mailbox0 { 23 | status = "okay"; 24 | }; 25 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/boards/kv260_r5.overlay: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "zynqmp_r5_override.dtsi" 8 | 9 | / { 10 | model = "KV260 Cortex-R5"; 11 | compatible = "xlnx,zynqmp-r5"; 12 | 13 | chosen { 14 | zephyr,console = &uart1; 15 | zephyr,shell-uart = &uart1; 16 | zephyr,ipc = &rpu0_apu_mailbox; 17 | zephyr,ipc_shm = &rpu0_ipc_shm; 18 | }; 19 | 20 | reserved-memory { 21 | compatible = "reserved-memory"; 22 | #address-cells = <1>; 23 | #size-cells = <1>; 24 | status = "okay"; 25 | ranges; 26 | 27 | rpu0_ipc_shm: memory@3ed40000 { 28 | reg = <0x3ed40000 DT_SIZE_K(512)>; 29 | }; 30 | }; 31 | }; 32 | 33 | &rpu0_ipi { 34 | status = "okay"; 35 | }; 36 | 37 | &rpu0_apu_mailbox { 38 | status = "okay"; 39 | }; 40 | 41 | /delete-node/ &uart0; 42 | /delete-node/ &gem0; 43 | /delete-node/ &gem1; 44 | /delete-node/ &gem2; 45 | /delete-node/ &gem3; 46 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/boards/stm32mp157c_dk2.overlay: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, STMICROELECTRONICS 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | / { 8 | chosen { 9 | /* 10 | * shared memory reserved for the inter-processor communication 11 | */ 12 | zephyr,ipc_shm = &mcusram3; 13 | zephyr,ipc = &mailbox; 14 | }; 15 | 16 | mcusram3: memory1@10040000 { 17 | compatible = "mmio-sram"; 18 | reg = <0x10040000 DT_SIZE_K(64)>; 19 | }; 20 | }; 21 | 22 | &mcusram { 23 | reg = <0x10000000 DT_SIZE_K(256)>; 24 | }; 25 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/boards/zynqmp_r5_override.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Linaro Limited 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /* This file should do away once Zephyr has been adjusted for better memory 8 | * configuration for zynqmp_r5 9 | */ 10 | 11 | / { 12 | chosen { 13 | /* override zephyr for now until definitions can be fixed upstream */ 14 | zephyr,sram = &tcm_lockstep; 15 | 16 | /* flash0 is QSPI XIP at offset 0 and is unlikely to be appropriate */ 17 | /delete-property/ zephyr,flash; 18 | }; 19 | 20 | soc { 21 | tcm_lockstep: memory@0 { 22 | compatible = "mmio-sram"; 23 | reg = <0 DT_SIZE_K(256)>; 24 | }; 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_KERNEL_BIN_NAME="rpmsg_multi_services" 2 | CONFIG_PRINTK=n 3 | CONFIG_IPM=y 4 | CONFIG_MAIN_STACK_SIZE=1024 5 | CONFIG_HEAP_MEM_POOL_SIZE=1024 6 | CONFIG_OPENAMP=y 7 | CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=8 8 | CONFIG_OPENAMP_RSC_TABLE=y 9 | CONFIG_OPENAMP_MASTER=n 10 | -------------------------------------------------------------------------------- /examples/zephyr/rpmsg_multi_services/sample.yaml: -------------------------------------------------------------------------------- 1 | sample: 2 | description: This app provides an example of how to integrate OpenAMP 3 | with Zephyr including a resource table. 4 | name: OpenAMP with resource table example integration 5 | tests: 6 | sample.subsys.ipc.openamp_rs_table: 7 | build_only: true 8 | platform_allow: stm32mp157c_dk2 9 | platform_allow: kv260_r5 10 | platform_allow: imx8mp_evk/mimx8ml8/adsp 11 | tags: ipm 12 | -------------------------------------------------------------------------------- /west-virtio-exp.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024 Wind River Systems, Inc. 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | manifest: 5 | remotes: 6 | - name: openamp 7 | url-base: https://github.com/OpenAMP 8 | defaults: 9 | remote: openamp 10 | 11 | self: 12 | path: openamp-system-reference 13 | 14 | projects: 15 | - name: zephyr 16 | repo-path: openamp-zephyr-staging 17 | remote: openamp 18 | revision: virtio-exp 19 | import: true 20 | 21 | # as we use the same names as in the zephyr manifest, 22 | # our definitions eclipse their's 23 | - name: libmetal 24 | revision: main 25 | 26 | - name: open-amp 27 | revision: virtio-exp 28 | 29 | # however, our version does not have the zephyr module glue 30 | # so bring in our custom version that integrates both libraries 31 | # as a single zephyr module 32 | - name: openamp-zephyr-modules 33 | revision: main 34 | -------------------------------------------------------------------------------- /west.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022 STMicroelectronics 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | manifest: 5 | remotes: 6 | - name: openamp 7 | url-base: https://github.com/OpenAMP 8 | - name: zephyr 9 | url-base: https://github.com/zephyrproject-rtos 10 | defaults: 11 | remote: openamp 12 | 13 | self: 14 | path: openamp-system-reference 15 | 16 | projects: 17 | - name: zephyr 18 | remote: zephyr 19 | revision: v4.1.0 20 | import: true 21 | 22 | # as we use the same names as in the zephyr manifest, 23 | # our definitions eclipse their's 24 | - name: libmetal 25 | revision: main 26 | 27 | - name: open-amp 28 | revision: main 29 | 30 | # however, our version does not have the zephyr module glue 31 | # so bring in our custom version that integrates both libraries 32 | # as a single zephyr module 33 | - name: openamp-zephyr-modules 34 | revision: main 35 | --------------------------------------------------------------------------------