1# open-amp
2This repository is the home for the Open Asymmetric Multi Processing (OpenAMP)
3framework project. The OpenAMP framework provides software components that
4enable development of software applications for Asymmetric Multiprocessing
5(AMP) systems. The framework provides the following key capabilities.
6
71. Provides Life Cycle Management, and Inter Processor Communication
8   capabilities for management of remote compute resources and their associated
9   software contexts.
102. Provides a stand alone library usable with RTOS and Baremetal software
11   environments
123. Compatibility with upstream Linux remoteproc and rpmsg components
134. Following AMP configurations supported
14	a. Linux host/Generic(Baremetal) remote
15	b. Generic(Baremetal) host/Linux remote
165. Proxy infrastructure and supplied demos showcase ability of proxy on host
17   to handle printf, scanf, open, close, read, write calls from Bare metal
18   based remote contexts.
19
20## OpenAMP Source Structure
21```
22|- lib/
23|  |- virtio/     # virtio implementation
24|  |- rpmsg/      # rpmsg implementation
25|  |- remoteproc/ # remoteproc implementation
26|  |- proxy/      # implement one processor access device on the
27|  |              # other processor with file operations
28|- apps/        # demonstration/testing applications
29|  |- examples/ # Application samples using the OpenAMP framework.
30|  |- machine/  # common files for machine can be shared by applications
31|  |            # It is up to each app to decide whether to use these files.
32|  |- system/   # common files for system can be shared by applications
33|               # It is up to each app to decide whether to use these files.
34|- cmake        # CMake files
35|- script       # helper scripts (such as checkpatch) for contributors.
36```
37
38OpenAMP library libopen_amp is composed of the following directories in `lib/`:
39*   `virtio/`
40*   `rpmsg/`
41*   `remoteproc/`
42*   `proxy/`
43
44OpenAMP system/machine support has been moved to libmetal, the system/machine
45layer in the `apps/` directory is for system application initialization, and
46resource table definition.
47
48### libmetal APIs used in OpenAMP
49Here are the libmetal APIs used by OpenAMP, if you want to port OpenAMP for your
50system, you will need to implement the following libmetal APIs in the libmetal's
51`lib/system/<SYS>` directory:
52* alloc, for memory allocation and memory free
53* cache, for flushing cache and invalidating cache
54* io, for memory mapping. OpenAMP required memory mapping in order to access
55  vrings and carved out memory.
56* irq, for IRQ handler registration, IRQ disable/enable and global IRQ handling.
57* mutex
58* shmem (For RTOS, you can usually use the implementation from
59  `lib/system/generic/`)
60* sleep, at the moment, OpenAMP only requires microseconds sleep as when OpenAMP
61  fails to get a buffer to send messages, it will call this function to sleep and
62  then try again.
63* time, for timestamp
64* init, for libmetal initialization.
65* atomic
66
67Please refer to `lib/system/generic` when you port libmetal for your system.
68
69If you a different compiler to GNU gcc, please refer to `lib/compiler/gcc/` to
70port libmetal for your compiler. At the moment, OpenAMP needs the atomic
71operations defined in `lib/compiler/gcc/atomic.h`.
72
73## OpenAMP Compilation
74OpenAMP uses CMake for library and demonstration application compilation.
75OpenAMP requires libmetal library. For now, you will need to download and
76compile libmetal library separately before you compiling OpenAMP library.
77In future, we will try to make libmetal as a submodule to OpenAMP to make this
78flow easier.
79
80Some Cmake options are available to allow user to customize to the OpenAMP
81library for it project:
82* **WITH_PROXY** (default OFF): Include proxy support in the library.
83* **WITH APPS** (default OFF): Build with sample applications.
84* **WITH_PROXY_APPS** (default OFF):Build with proxy sample applications.
85* **WITH_VIRTIO_DRIVER** (default ON): Build with virtio driver enabled.
86  This option can be set to OFF if the only the remote mode is implemented.
87* **WITH_VIRTIO_DEVICE** (default ON): Build with virtio device enabled.
88  This option can be set to OFF if the only the driver mode is implemented.
89* **WITH_STATIC_LIB** (default ON): Build with a static library.
90* **WITH_SHARED_LIB** (default ON): Build with a shared library.
91* **WITH_ZEPHYR** (default OFF): Build open-amp as a zephyr library. This option
92  is mandatory in a Zephyr environment.
93* **WITH_DCACHE_VRINGS** (default OFF): Build with data cache operations
94  enabled on vrings.
95* **WITH_DCACHE_BUFFERS** (default OFF): Build with data cache operations
96  enabled on buffers.
97* **WITH_DCACHE_RSC_TABLE** (default OFF): Build with data cache operations
98  enabled on resource table.
99* **WITH_DCACHE** (default OFF): Build with all cache operations
100  enabled. When set to ON, cache operations for vrings, buffers and resource
101  table are enabled.
102* **RPMSG_BUFFER_SIZE** (default 512): adjust the size of the RPMsg buffers.
103  The default value of the RPMsg size is compatible with the Linux Kernel hard
104  coded value. If you AMP configuration is Linux kernel host/ OpenAMP remote,
105  this option must not be used.
106
107### Example to compile OpenAMP for Zephyr
108The [Zephyr open-amp repo](https://github.com/zephyrproject-rtos/open-amp)
109implements the open-amp library for the Zephyr project. It is mainly a fork of
110this repository, with some add-ons for integration in the Zephyr project.
111The standard way to compile OpenAMP for a Zephyr project is to use Zephyr build
112environment. Please refer to
113[Zephyr OpenAMP samples](https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/ipc)
114for examples and [Zephyr documentation](https://docs.zephyrproject.org/latest/) for the build
115process.
116
117### Example to compile OpenAMP for communication between Linux processes:
118* Install libsysfs devel and libhugetlbfs devel packages on your Linux host.
119* build libmetal library on your host as follows:
120
121    ```
122        $ mkdir -p build-libmetal
123        $ cd build-libmetal
124        $ cmake <libmetal_source>
125        $ make VERBOSE=1 DESTDIR=<libmetal_install> install
126    ```
127
128* build OpenAMP library on your host as follows:
129
130        $ mkdir -p build-openamp
131        $ cd build-openamp
132        $ cmake <openamp_source> -DCMAKE_INCLUDE_PATH=<libmetal_built_include_dir> \
133              -DCMAKE_LIBRARY_PATH=<libmetal_built_lib_dir> [-DWITH_APPS=ON]
134        $ make VERBOSE=1 DESTDIR=$(pwd) install
135
136The OpenAMP library will be generated to `build/usr/local/lib` directory,
137headers will be generated to `build/usr/local/include` directory, and the
138applications executable will be generated to `build/usr/local/bin`
139directory.
140
141* cmake option `-DWITH_APPS=ON` is to build the demonstration applications.
142* If you have used `-DWITH_APPS=ON` to build the demos, you can try them on
143  your Linux host as follows:
144
145  * rpmsg echo demo:
146    ```
147    # Start echo test server to wait for message to echo
148    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
149       build/usr/local/bin/rpmsg-echo-shared
150    # Run echo test to send message to echo test server
151    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
152       build/usr/local/bin/rpmsg-echo-ping-shared 1
153    ```
154
155  * rpmsg echo demo with the nocopy API:
156    ```
157    # Start echo test server to wait for message to echo
158    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
159       build/usr/local/bin/rpmsg-nocopy-echo-shared
160    # Run echo test to send message to echo test server
161    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
162       build/usr/local/bin/rpmsg-nocopy-ping-shared 1
163    ```
164
165###  Example to compile Zynq UltraScale+ MPSoC R5 generic(baremetal) remote:
166* build libmetal library on your host as follows:
167  * Create your on cmake toolchain file to compile libmetal for your generic
168    (baremetal) platform. Here is the example of the toolchain file:
169
170    ```
171        set (CMAKE_SYSTEM_PROCESSOR "arm"              CACHE STRING "")
172        set (MACHINE "zynqmp_r5" CACHE STRING "")
173
174        set (CROSS_PREFIX           "armr5-none-eabi-" CACHE STRING "")
175        set (CMAKE_C_FLAGS          "-mfloat-abi=soft -mcpu=cortex-r5 -Wall -Werror -Wextra \
176           -flto -Os -I/ws/xsdk/r5_0_bsp/psu_cortexr5_0/include" CACHE STRING "")
177
178        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
179        SET(CMAKE_AR  "gcc-ar" CACHE STRING "")
180        SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
181        SET(CMAKE_C_ARCHIVE_FINISH   true)
182
183        include (cross-generic-gcc)
184    ```
185
186  * Compile libmetal library:
187
188    ```
189        $ mkdir -p build-libmetal
190        $ cd build-libmetal
191        $ cmake <libmetal_source> -DCMAKE_TOOLCHAIN_FILE=<toolchain_file>
192        $ make VERBOSE=1 DESTDIR=<libmetal_install> install
193    ```
194
195* build OpenAMP library on your host as follows:
196  * Create your on cmake toolchain file to compile openamp for your generic
197    (baremetal) platform. Here is the example of the toolchain file:
198    ```
199        set (CMAKE_SYSTEM_PROCESSOR "arm" CACHE STRING "")
200        set (MACHINE                "zynqmp_r5" CACHE STRING "")
201        set (CROSS_PREFIX           "armr5-none-eabi-" CACHE STRING "")
202        set (CMAKE_C_FLAGS          "-mfloat-abi=soft -mcpu=cortex-r5 -Os -flto \
203          -I/ws/libmetal-r5-generic/usr/local/include \
204          -I/ws/xsdk/r5_0_bsp/psu_cortexr5_0/include" CACHE STRING "")
205        set (CMAKE_ASM_FLAGS        "-mfloat-abi=soft -mcpu=cortex-r5" CACHE STRING "")
206        set (PLATFORM_LIB_DEPS      "-lxil -lc -lm" CACHE STRING "")
207        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
208        SET(CMAKE_AR  "gcc-ar" CACHE STRING "")
209        SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
210        SET(CMAKE_C_ARCHIVE_FINISH   true)
211        set (CMAKE_FIND_ROOT_PATH /ws/libmetal-r5-generic/usr/local/lib \
212            /ws/xsdk/r5_bsp/psu_cortexr5_0/lib )
213
214        include (cross_generic_gcc)
215    ```
216
217  * We use cmake `find_path` and `find_library` to check if libmetal includes
218    and libmetal library is in the includes and library search paths. However,
219    for non-linux system, it doesn't work with `CMAKE_INCLUDE_PATH` and
220    `CMAKE_LIBRARY_PATH` variables, and thus, we need to specify those paths
221    in the toolchain file with `CMAKE_C_FLAGS` and `CMAKE_FIND_ROOT_PATH`.
222* Compile the OpenAMP library:
223
224    ```
225    $ mkdir -p build-openamp
226    $ cd build-openamp
227    $ cmake <openamp_source> -DCMAKE_TOOLCHAIN_FILE=<toolchain_file>
228    $ make VERBOSE=1 DESTDIR=$(pwd) install
229    ```
230
231The OpenAMP library will be generated to `build/usr/local/lib` directory,
232headers will be generated to `build/usr/local/include` directory, and the
233applications executable will be generated to `build/usr/local/bin`
234directory.
235
236
237### Example to compile OpenAMP Linux Userspace for Zynq UltraScale+ MPSoC
238We can use yocto to build the OpenAMP Linux userspace library and application.
239open-amp and libmetal recipes are in this yocto layer:
240https://github.com/OpenAMP/meta-openamp
241* Add the `meta-openamp` layer to your layers in your yocto build project's `bblayers.conf` file.
242* Add `libmetal` and `open-amp` to your packages list. E.g. add `libmetal` and `open-amp` to the
243  `IMAGE_INSTALL_append` in the `local.conf` file.
244* You can also add OpenAMP demos Linux applications packages to your yocto packages list. OpenAMP
245  demo examples recipes are also in `meta-openamp`:
246  https://github.com/OpenAMP/meta-openamp/tree/master/recipes-openamp/rpmsg-examples
247
248In order to user OpenAMP(RPMsg) in Linux userspace, you will need to have put the IPI device,
249  vring memory and shared buffer memory to your Linux kernel device tree. The device tree example
250  can be found here:
251  https://github.com/OpenAMP/open-amp/blob/main/apps/machine/zynqmp/openamp-linux-userspace.dtsi
252
253## Version
254The OpenAMP version follows the set of rule proposed in
255[Semantic Versioning specification](https://semver.org/).
256
257## Supported System and Machines
258For now, it supports:
259* Zynq generic remote
260* Zynq UltraScale+ MPSoC R5 generic remote
261* Linux host OpenAMP between Linux userspace processes
262* Linux userspace OpenAMP RPMsg host
263* Linux userspace OpenAMP RPMsg remote
264* Linux userspace OpenAMP RPMsg and MicroBlaze bare metal remote
265
266## Known Limitations:
2671. In case of OpenAMP on Linux userspace for inter processors communication,
268   it only supports static vrings and shared buffers.
2692. `sudo` is required to run the OpenAMP demos between Linux processes, as
270   it doesn't work on some systems if you are normal users.
271
272## How to contribute:
273As an open-source project, we welcome and encourage the community to submit patches directly to the
274project. As a contributor you  should be familiar with common developer tools such as Git and CMake,
275and platforms such as GitHub.
276Then following points should be rescpected to facilitate the review process.
277
278### Licencing
279Code is contributed to the Linux kernel under a number of licenses, but all code must be compatible
280with version the [BSD License](https://github.com/OpenAMP/open-amp/blob/main/LICENSE.md), which is
281the license covering the OpenAMP distribution as a whole. In practice, use the following tag
282instead of the full license text in the individual files:
283
284    ```
285    SPDX-License-Identifier:    BSD-3-Clause
286    SPDX-License-Identifier:    BSD-2-Clause
287    ```
288### Signed-off-by
289Commit message must contain Signed-off-by: line and your email must match the change authorship
290information. Make sure your .gitconfig is set up correctly:
291
292    ```
293    git config --global user.name "first-name Last-Namer"
294    git config --global user.email "yourmail@company.com"
295    ```
296### gitlint
297Before you submit a pull request to the project, verify your commit messages meet the requirements.
298The check can be  performed locally using the the gitlint command.
299
300Run gitlint locally in your tree and branch where your patches have been committed:
301
302      ```gitlint```
303Note, gitlint only checks HEAD (the most recent commit), so you should run it after each commit, or
304use the --commits option to specify a commit range covering all the development patches to be
305submitted.
306
307### Code style
308In general, follow the Linux kernel coding style, with the following exceptions:
309
310* Use /**  */ for doxygen comments that need to appear in the documentation.
311
312The Linux kernel GPL-licensed tool checkpatch is used to check coding style conformity.Checkpatch is
313available in the scripts directory.
314
315To check your \<n\> commits in your git branch:
316   ```
317   ./scripts/checkpatch.pl --strict  -g HEAD-<n>
318
319   ```
320### Send a pull request
321We use standard github mechanism for pull request. Please refer to github documentation for help.
322
323## Communication and Collaboration
324[Subscribe](https://lists.openampproject.org/mailman3/lists/openamp-rp.lists.openampproject.org/) to
325the OpenAMP mailing list(openamp-rp@lists.openampproject.org).
326
327For more details on the framework please refer to the
328[OpenAMP Docs](https://openamp.readthedocs.io/en/latest/).
329