Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / docs / howto / how-to-cross-build-runtime-for-aarch64.md
1 # How to Cross-build Runtime for AARCH64
2
3 In **ONE**, we use `AARCH64` on build files such as Makefile, CMakeLists.txt and so on.
4
5 ## Prepare AARCH64 Ubuntu RootFS
6
7 Install required packages
8
9 ```
10 $ sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
11 ```
12
13 Use `install_rootfs.sh` script to prepare Root File System. You should have `sudo`
14
15 ```
16 $ sudo ./tools/cross/install_rootfs.sh aarch64
17 ```
18 - supports `arm`(default) and `aarch64` architecutre for now
19 - supports `xenial`(default), `trusty` and `bionic` release
20
21 To see the options,
22 ```
23 $ ./tools/cross/install_rootfs.sh -h
24 ```
25
26 RootFS will be prepared at `tools/cross/rootfs/aarch64` folder.
27
28 ***\* CAUTION: The OS version of rootfs must match the OS version of execution target device. On the other hand, you need to match the Ubuntu version of the development PC with the Ubuntu version of rootfs to be used for cross-build. Otherwise, unexpected build errors may occur.***
29
30 If you are using Ubuntu 16.04 LTS, select `xenial`, if you are using Ubuntu 18.04 LTS, select `bionic`. You can check your Ubuntu code name in the following way.
31
32 ```
33 $ cat /etc/lsb-release
34 DISTRIB_ID=Ubuntu
35 DISTRIB_RELEASE=18.04
36 DISTRIB_CODENAME=bionic
37 DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
38 ```
39
40 If a build error occurs because the version of the development system and the target system do not match, and if you can't replace your development system for any reason, you can consider [cross-build using the docker image](how-to-build-runtime-using-prebuilt-docker-image.md).
41
42 ### Prepare RootFS at alternative folder
43
44 Use `ROOTFS_DIR` to a full path to prepare at alternative path.
45
46 ```
47 $ ROOTFS_DIR=/home/user/rootfs/aarch64-xenial sudo -E ./tools/cross/install_rootfs.sh aarch64
48 ```
49
50 ### Using proxy
51
52 If you need to use proxy server while building the rootfs, use `--setproxy` option.
53
54 ```
55 # for example,
56 $ sudo ./tools/cross/install_rootfs.sh aarch64 --setproxy="1.2.3.4:8080"
57 # or
58 $ sudo ./tools/cross/install_rootfs.sh aarch64 --setproxy="proxy.server.com:8888"
59 ```
60
61 This will put `apt` proxy settings in `rootfs/etc/apt/apt.conf.d/90proxy` file
62 for `http`, `https` and `ftp` protocol.
63
64 ## Cross build for AARCH64
65
66 Install cross compilers
67 ```
68 $ sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
69 ```
70
71 Give `TARGET_ARCH` variable to set the target architecture
72 ```
73 $ CROSS_BUILD=1 TARGET_ARCH=aarch64 make
74 $ CROSS_BUILD=1 TARGET_ARCH=aarch64 make install
75 ```
76 - supports `armv7l` and `aarch64` for now
77
78 If you used `ROOTFS_DIR` to prepare in alternative folder,
79 you should also give this to makefile.
80 ```
81 $ CROSS_BUILD=1 ROOTFS_DIR=/home/user/rootfs/aarch64-xenial TARGET_ARCH=aarch64 make
82 $ CROSS_BUILD=1 ROOTFS_DIR=/home/user/rootfs/aarch64-xenial TARGET_ARCH=aarch64 make install
83 ```
84 You can also omit the `CROSS_BUILD=1` option if you explicitly pass `ROOTFS_DIR`. In that case, if
85 the `TARGET_ARCH` are differs from the hostarchitecture, the make script automatically applies
86 `CROSS_BUILD=1`. So, if you set `ROOTFS_DIR` as an environment variable, you can simply perform
87 normal build and cross build as follows.
88
89 ```
90 $ export ROOTFS_DIR=xxx
91 ...
92 $ make all install                        # do normal build
93 $ TARGET_ARCH=aarch64 make all install    # do cross build
94 ```
95
96 ### Run test
97
98 To run and test the cross-compiled runtime, you need to copy the compiled output to the target device of the architecture in which it is executable. Please refer to the following document for details on the test procedure. In the guide, `armv7l-linux.debug` in path should be replaced by referring to your build result.
99
100 - [Testing neural network model inference with a cross-build runtime](./how-to-cross-build-runtime-for-arm.md#run-test)