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 master/Generic(Baremetal) remote
15	b. Generic(Baremetal) master/Linux remote
165. Proxy infrastructure and supplied demos showcase ability of proxy on master
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_MASTER** (default ON): Build with virtio master enabled.
86  This option can be set to OFF if the only the remote mode is implemented.
87* **WITH_VIRTIO_SLAVE** (default ON): Build with virtio slave enabled.
88  This option can be set to OFF if the only the master 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* **RPMSG_BUFFER_SIZE** (default 512): adjust the size of the RPMsg buffers.
94  The default value of the RPMsg size is compatible with the Linux Kernel hard
95  coded value. If you AMP configuration is Linux kernel master/ OpenAMP remote,
96  this option must not be used.
97
98### Example to compile OpenAMP for Zephyr
99The [Zephyr open-amp repo](https://github.com/zephyrproject-rtos/open-amp)
100implements the open-amp library for the Zephyr project. It is mainly a fork of
101this repository, with some add-ons for integration in the Zephyr project.
102The standard way to compile OpenAMP for a Zephyr project is to use Zephyr build
103environment. Please refer to [Zephyr OpenAMP samples](https://github.com/zephyrproject-rtos/zephyr/tree/master/samples/subsys/ipc) for examples.
104
105Nevertheless you can compile the OpenAMP project for Zephyr.
106As OpenAMP uses libmetal, please refer to libmetal README to build libmetal
107for Zephyr before building OpenAMP library for Zephyr.
108As Zephyr uses CMake, we build OpenAMP library as a target of Zephyr CMake
109project. Here is how to build libmetal for Zephyr:
110```
111    $ export ZEPHRY_GCC_VARIANT=zephyr
112    $ export ZEPHRY_SDK_INSTALL_DIR=<where Zephyr SDK is installed>
113    $ source <git_clone_zephyr_project_source_root>/zephyr-env.sh
114
115    $ cmake <OpenAMP_source_root> \
116      -DWITH_ZEPHYR=on -DBOARD=qemu_cortex_m3 \
117      -DCMAKE_INCLUDE_PATH="<libmetal_zephyr_build_dir>/lib/include" \
118      -DCMAKE_LIBRARY_PATH="<libmetal_zephyr_build_dir>/lib" \
119    $ make VERBOSE=1 all
120```
121
122### Example to compile OpenAMP for communication between Linux processes:
123* Install libsysfs devel and libhugetlbfs devel packages on your Linux host.
124* build libmetal library on your host as follows:
125
126    ```
127        $ mkdir -p build-libmetal
128        $ cd build-libmetal
129        $ cmake <libmetal_source>
130        $ make VERBOSE=1 DESTDIR=<libmetal_install> install
131    ```
132
133* build OpenAMP library on your host as follows:
134
135        $ mkdir -p build-openamp
136        $ cd build-openamp
137        $ cmake <openamp_source> -DCMAKE_INCLUDE_PATH=<libmetal_built_include_dir> \
138              -DCMAKE_LIBRARY_PATH=<libmetal_built_lib_dir> [-DWITH_APPS=ON]
139        $ make VERBOSE=1 DESTDIR=$(pwd) install
140
141The OpenAMP library will be generated to `build/usr/local/lib` directory,
142headers will be generated to `build/usr/local/include` directory, and the
143applications executable will be generated to `build/usr/local/bin`
144directory.
145
146* cmake option `-DWITH_APPS=ON` is to build the demonstration applications.
147* If you have used `-DWITH_APPS=ON` to build the demos, you can try them on
148  your Linux host as follows:
149
150  * rpmsg echo demo:
151    ```
152    # Start echo test server to wait for message to echo
153    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
154       build/usr/local/bin/rpmsg-echo-shared
155    # Run echo test to send message to echo test server
156    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
157       build/usr/local/bin/rpmsg-echo-ping-shared 1
158    ```
159
160  * rpmsg echo demo with the nocopy API:
161    ```
162    # Start echo test server to wait for message to echo
163    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
164       build/usr/local/bin/rpmsg-nocopy-echo-shared
165    # Run echo test to send message to echo test server
166    $ sudo LD_LIBRARY_PATH=<openamp_built>/usr/local/lib:<libmetal_built>/usr/local/lib \
167       build/usr/local/bin/rpmsg-nocopy-ping-shared 1
168    ```
169
170###  Example to compile Zynq UltraScale+ MPSoC R5 generic(baremetal) remote:
171* build libmetal library on your host as follows:
172  * Create your on cmake toolchain file to compile libmetal for your generic
173    (baremetal) platform. Here is the example of the toolchain file:
174
175    ```
176        set (CMAKE_SYSTEM_PROCESSOR "arm"              CACHE STRING "")
177        set (MACHINE "zynqmp_r5" CACHE STRING "")
178
179        set (CROSS_PREFIX           "armr5-none-eabi-" CACHE STRING "")
180        set (CMAKE_C_FLAGS          "-mfloat-abi=soft -mcpu=cortex-r5 -Wall -Werror -Wextra \
181           -flto -Os -I/ws/xsdk/r5_0_bsp/psu_cortexr5_0/include" CACHE STRING "")
182
183        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
184        SET(CMAKE_AR  "gcc-ar" CACHE STRING "")
185        SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
186        SET(CMAKE_C_ARCHIVE_FINISH   true)
187
188        include (cross-generic-gcc)
189    ```
190
191  * Compile libmetal library:
192
193    ```
194        $ mkdir -p build-libmetal
195        $ cd build-libmetal
196        $ cmake <libmetal_source> -DCMAKE_TOOLCHAIN_FILE=<toolchain_file>
197        $ make VERBOSE=1 DESTDIR=<libmetal_install> install
198    ```
199
200* build OpenAMP library on your host as follows:
201  * Create your on cmake toolchain file to compile openamp for your generic
202    (baremetal) platform. Here is the example of the toolchain file:
203    ```
204        set (CMAKE_SYSTEM_PROCESSOR "arm" CACHE STRING "")
205        set (MACHINE                "zynqmp_r5" CACHE STRING "")
206        set (CROSS_PREFIX           "armr5-none-eabi-" CACHE STRING "")
207        set (CMAKE_C_FLAGS          "-mfloat-abi=soft -mcpu=cortex-r5 -Os -flto \
208          -I/ws/libmetal-r5-generic/usr/local/include \
209          -I/ws/xsdk/r5_0_bsp/psu_cortexr5_0/include" CACHE STRING "")
210        set (CMAKE_ASM_FLAGS        "-mfloat-abi=soft -mcpu=cortex-r5" CACHE STRING "")
211        set (PLATFORM_LIB_DEPS      "-lxil -lc -lm" CACHE STRING "")
212        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
213        SET(CMAKE_AR  "gcc-ar" CACHE STRING "")
214        SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
215        SET(CMAKE_C_ARCHIVE_FINISH   true)
216        set (CMAKE_FIND_ROOT_PATH /ws/libmetal-r5-generic/usr/local/lib \
217            /ws/xsdk/r5_bsp/psu_cortexr5_0/lib )
218
219        include (cross_generic_gcc)
220    ```
221
222  * We use cmake `find_path` and `find_library` to check if libmetal includes
223    and libmetal library is in the includes and library search paths. However,
224    for non-linux system, it doesn't work with `CMAKE_INCLUDE_PATH` and
225    `CMAKE_LIBRARY_PATH` variables, and thus, we need to specify those paths
226    in the toolchain file with `CMAKE_C_FLAGS` and `CMAKE_FIND_ROOT_PATH`.
227* Compile the OpenAMP library:
228
229    ```
230    $ mkdir -p build-openamp
231    $ cd build-openamp
232    $ cmake <openamp_source> -DCMAKE_TOOLCHAIN_FILE=<toolchain_file>
233    $ make VERBOSE=1 DESTDIR=$(pwd) install
234    ```
235
236The OpenAMP library will be generated to `build/usr/local/lib` directory,
237headers will be generated to `build/usr/local/include` directory, and the
238applications executable will be generated to `build/usr/local/bin`
239directory.
240
241
242### Example to compile OpenAMP Linux Userspace for Zynq UltraScale+ MPSoC
243We can use yocto to build the OpenAMP Linux userspace library and application.
244open-amp and libmetal recipes are in this yocto layer:
245https://github.com/OpenAMP/meta-openamp
246* Add the `meta-openamp` layer to your layers in your yocto build project's `bblayers.conf` file.
247* Add `libmetal` and `open-amp` to your packages list. E.g. add `libmetal` and `open-amp` to the
248  `IMAGE_INSTALL_append` in the `local.conf` file.
249* You can also add OpenAMP demos Linux applications packages to your yocto packages list. OpenAMP
250  demo examples recipes are also in `meta-openamp`:
251  https://github.com/OpenAMP/meta-openamp/tree/master/recipes-openamp/openamp-examples
252
253In order to user OpenAMP(RPMsg) in Linux userspace, you will need to have put the IPI device,
254  vring memory and shared buffer memory to your Linux kernel device tree. The device tree example
255  can be found here:
256  https://github.com/OpenAMP/open-amp/blob/master/apps/machine/zynqmp/openamp-linux-userspace.dtsi
257
258## Version
259The OpenAMP version follows the set of rule proposed in [Semantic Versioning specification](https://semver.org/).
260
261## Supported System and Machines
262For now, it supports:
263* Zynq generic slave
264* Zynq UltraScale+ MPSoC R5 generic slave
265* Linux host OpenAMP between Linux userspace processes
266* Linux userspace OpenAMP RPMsg master
267* Linux userspace OpenAMP RPMsg slave
268* Linux userspace OpenAMP RPMsg and MicroBlaze bare metal remote
269
270## Known Limitations:
2711. In case of OpenAMP on Linux userspace for inter processors communication,
272   it only supports static vrings and shared buffers.
2732. `sudo` is required to run the OpenAMP demos between Linux processes, as
274   it doesn't work on some systems if you are normal users.
275
276## How to contribute:
277As an open-source project, we welcome and encourage the community to submit patches directly to the project. As a contributor you  should be familiar with common developer tools such as Git and CMake, and platforms such as GitHub.
278Then following points should be rescpected to facilitate the review process.
279
280### Licencing
281Code is contributed to the Linux kernel under a number of licenses, but all code must be compatible with version the [BSD License](https://github.com/OpenAMP/open-amp/blob/master/LICENSE.md), which is the license covering the OpenAMP distribution as a whole. In practice, use the following tag instead of the full license text in the individual files:
282
283    ```
284    SPDX-License-Identifier:    BSD-3-Clause
285    SPDX-License-Identifier:    BSD-2-Clause
286    ```
287### Signed-off-by
288Commit message must contain Signed-off-by: line and your email must match the change authorship information. Make sure your .gitconfig is set up correctly:
289
290    ```
291    git config --global user.name "first-name Last-Namer"
292    git config --global user.email "yourmail@company.com"
293    ```
294### gitlint
295Before you submit a pull request to the project, verify your commit messages meet the requirements. The check can be  performed locally using the the gitlint command.
296
297Run gitlint locally in your tree and branch where your patches have been committed:
298
299      ```gitlint```
300Note, gitlint only checks HEAD (the most recent commit), so you should run it after each commit, or use the --commits option to specify a commit range covering all the development patches to be submitted.
301
302### Code style
303In general, follow the Linux kernel coding style, with the following exceptions:
304
305* Use /**  */ for doxygen comments that need to appear in the documentation.
306
307The Linux kernel GPL-licensed tool checkpatch is used to check coding style conformity.Checkpatch is available in the scripts directory.
308
309To check your \<n\> commits in your git branch:
310   ```
311   ./scripts/checkpatch.pl --strict  -g HEAD-<n>
312
313   ```
314### Send a pull request
315We use standard github mechanism for pull request. Please refer to github documentation for help.
316
317## Communication and Collaboration
318[Subscribe](https://lists.openampproject.org/mailman/listinfo/openamp-rp) to the OpenAMP mailing list(openamp-rp@lists.openampproject.org).
319
320For more details on the framework please refer to the the [OpenAMP wiki](https://github.com/OpenAMP/open-amp/wiki).
321