Using our libraries under Linux aarch64 or arm64

Using our libraries under Linux aarch64 or arm64

A few customers have asked us whether we supported Linux aarch64 or arm64, that is a Linux which uses an 64-bit ARM processor. The answer is yes and no. We don't provide pre-compiled binaries for these platforms, so by default our libraries don't work. But you can recompile our libraries to make them work properly. Explanations...




Update: This post is obsolete. Yoctopuce now officially supports Linux aarch64. The binaries for this platform are available for the VirtualHub, the command line library, Yocto-Visualization, Yocto-Discovery, and Yocto-BridgeCalibration. You can use the C++, C#, Java, and Python programming libraries under Linux aarch64 as they are, without modification, like for the other platforms.

For more details, please read our post : Linux aarch64 support for the VirtualHub and libraries

First of all, let's clarify the aarch64 and arm64 names: some distributions use the arm64 name while others use aarch64, the same happens for compilers. In both cases, it refers to using an ARM processor which works in 64-bit mode. In this post, we'll use the aarch64 name because it's the one used by the Linux kernel itself.

The aarch64 architecture


To execute a aarch64 binary, you must therefore use an ARM processor of the ARMv8 family, supporting 64-bit instructions and a Linux distribution designed to work in 64-bit on this type of processors.

Although ARM processors supporting 64-bit instructions are very widespread on smart phones, most mini-computers still use Linux distributions which work only in 32 bits. The best-known example is the Raspberry Pi 3 and 3+. Their processors support 64-bit instructions but the Raspbian distribution still only supports the 32-bit mode.

The result of the uname command on a Raspberry Pi 3 with the Rasbian distribution:

pi@raspberrypi:~ $ uname -a Linux raspberrypi 4.9.80-v7+ #1098 SMP Fri Mar 9 19:11:42 GMT 2018 armv7l GNU/Linux



You can however use other distributions, for example Ubuntu, and install them on a Raspberry Pi 3 so that it works in aarch64.

The result of the uname command on a Raspberry Pi 3 with the Ubuntu arm64 distribution:

ubuntu@ubuntu:~/yoctolib/v1.0/Public/python/Sources$ uname -a Linux ubuntu 4.14.66-chainsx-cxcore+ #2 SMP PREEMPT Sun Aug 26 03:37:14 EDT 2018 aarch64 aarch64 aarch64 GNU/Linux



In short, the aarch64 architecture is currently rarely used in the IoT domain. This is rather logical, as 64-bit support doesn't bring anything interesting for this type of use.

We however have customers which use Nvidia Jetson boards and which would like to use our modules on these platforms.

Compatible libraries


As said previously, at the moment we don't provide aarch64 binaries, however, as we provide the sources of all our programming libraries, you can recompile them so that they work on this platform.

The libraries which can be used under Linux are the C++, Python, Java, and command line libraries.

The command line library


It's the simplest case, the library completely supports the aarch64 architecture, but the binaries are not included in the archive. To compile aarch64 versions of all the executables, you must simply run the following command at the root of the library:

./build.sh aarch64



The compilation takes rather a long time, but in the end all the executables are located in the Binaries/linux/aarch64 subdirectory.

The C++ library


As for the command line library, you only have to execute on your aarch64 machine the ./build.sh aarch64 command to recompile the C++ library as well as all the examples. If you want to compile only one example, you can run the make aarch64 command in the example you are interested in. All the compiled files end up in a "linux/aarch64" subdirectory.

Note: if you are using your own project, there is nothing specific to do. Simply include the source files in your project and everything should compile without error or warning.

The Python library


For Python, it's a little more complex. The library is composed of two parts:

  • The Python code which implements the objects of our library
  • A yapi dynamic library for each platform (Windows, Linux 32bits, Linux armhf, and so on)


The Python code is compatible with the aarch64 architecture, because it's the Python virtual machine which compiles the code and generates machine code that the processor can interpret.

For the dynamic library, it's different, as it is a binary file already compiled for a specific architecture. When executing, the virtual machine looks for the aarch64 version of the yapi dynamic library. As by default it is not included, an error is returned during the first call to YAPI.RegisterHub().

ubuntu@ubuntu:~/python/Examples/Doc-Inventory$ python inventory.py Traceback (most recent call last): File "inventory.py", line 25, in <module> if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS: File "../../Sources/yocto_api.py", line 2368, in RegisterHub res = YAPI.InitAPI(0, errmsg) File "../../Sources/yocto_api.py", line 2257, in InitAPI YAPI.yloadYapiCDLL() File "../../Sources/yocto_api.py", line 1008, in yloadYapiCDLL "), make sure it is available and accessible.") ImportError: YAPI shared library is missing (../../Sources/cdll/libyapi-aarch64.so), make sure it is available and accessible.



But as we provide the source code of all of programming libraries, you can compile this dynamic library for the aarch64 platform and add it to the Python library.

Compiling the yapi dynamic library for aarch64


The source code of the yapi dynamic library is not included in the Python library, it is located in the C++ library. You must therefore download the C++ library and unzip it on the aarch64 machine.

You must then compile the library with the make libyapi-aarch64.so command into the "Binaries" directory:

ubuntu@ubuntu:~/cpp/Binaries$ make libyapi-aarch64.so compiling linux/aarch64/objs/yapi_dyn.o compiling linux/aarch64/objs/ystream_dyn.o compiling linux/aarch64/objs/yprog_dyn.o compiling linux/aarch64/objs/yfifo_dyn.o compiling linux/aarch64/objs/ykey_dyn.o compiling linux/aarch64/objs/yhash_dyn.o compiling linux/aarch64/objs/yjson_dyn.o compiling linux/aarch64/objs/ytcp_dyn.o compiling linux/aarch64/objs/ymemory_dyn.o compiling linux/aarch64/objs/ythread_dyn.o compiling linux/aarch64/objs/yjni_dyn.o compiling linux/aarch64/objs/ypkt_lin_dyn.o linking linux/aarch64/yapi/libyapi.so.1.0.1 cp linux/aarch64/yapi/libyapi.so.1.0.1 libyapi-aarch64.so



In the end, you get a libyapi-aarch64.so file which is the yapi dynamic library for the aarch64 architecture.

Copying the libyapi-aarch64.so library into the Python library


The final step is to copy the libyapi-aarch64.so file into the cdll subdirectory of the sources of the Python library.

Finally, you get the following tree structure:

  • yocto_accelerometer.py
  • yocto_altitude.py
  • yocto_api.py
  • ...
  • cdll/

    • libyapi-aarch64.so
    • libyapi-amd64.so
    • libyapi-armel.so
    • libyapi-armhf.so
    • libyapi-i386.so
    • libyapi.dylib
    • yapi.dll
    • yapi64.dll


You can now use the Python library under Linux aarch64:

ubuntu@ubuntu:~/python/Examples/Doc-Inventory$ python inventory.py Device list RELAYLO1-27EAB (Yocto-Relay) YPWMRX01-AE391 (Yocto-PWM-Rx) YBUTTON1-2072D (Yocto-Knob) YPWMTX01-B9625 (Yocto-PWM-Tx)



Note: If you have obtained our Python library with PyPI, it's possible that the pip installer becomes confused by this modification and that it refuses to update the library in the future.

The Java library


The Java library is in the same situation as the Python library, but only if you use Yoctopuce modules directly connected to a USB port. Indeed, you don't have to compile the yapi dynamic library if you use a YoctoHub which you can access through the network.

To access USB module, however, you imperatively have to compile the libyapi-aarch64.so file as we have seen it above for Python.

You must then copy this file in the directory listed in the java.library.path property of the JVM. This property is a list of directories in which the JVM looks for dynamic libraries. Under Linux, this property is initialized with the content of the environment variable LD_LIBRARY_PATH, but if case of doubt, you can obtain the exact value of this property with the following code:

public static void main(String[] args)
{
    String prop = System.getProperty("java.library.path");
    System.out.println("Install libyapi-aarch64.so in " + prop);
}



Conclusion


As we have just seen it, the process to support Linux aarch64 is not very complex. This also highlights the advantage of having the sources of a programming library: you can always adapt the library to your needs.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.