• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Compilation and Building<a name="EN-US_TOPIC_0000001154212512"></a>
2
3-   [Compilation Environment Setup](#section3336103410314)
4-   [Introduction to the Compilation and Building Subsystem](#section354343816319)
5-   [Adding a Chipset Solution](#section18612153175011)
6
7## Compilation Environment Setup<a name="section3336103410314"></a>
8
9Set up the basic environment by following instructions in  [Ubuntu Build Environment](../quick-start/quickstart-lite-env-setup-linux.md). Both the user space and LiteOS Cortex-A kernel space are compiled using the LLVM compiler. If you choose to port the Linux kernel, run the following command to install the gcc-arm-linux-gnueabi cross compiler for compiling the Linux kernel-space image:
10
11```
12sudo apt-get install gcc-arm-linux-gnueabi
13```
14
15## Introduction to the Compilation and Building Subsystem<a name="section354343816319"></a>
16
17To learn more about the compilation and building subsystem, including the compilation and building process, compilation scripts, and building chipset source code or single components, see  [Compilation and Building](../subsystems/subsys-build-mini-lite.md).
18
19## Adding a Chipset Solution<a name="section18612153175011"></a>
20
21After learning the compilation framework and setting up the compilation environment, perform the following steps to create a chipset solution:
22
231.  <a name="li20894101862"></a>Create a category.
24
25    The directory structure is as follows: device/\{_chipset solution vendor_\}/\{_development board_\}. For example, if you are using the hispark\_taurus development board from HiSilicon, create the following directory in the root directory of the code:
26
27    ```
28    mkdir -p device/hisilicon/hispark_taurus
29    ```
30
31    The chipset solution directory tree is as follows:
32
33    ```
34    device
35    └── company                         # Chipset solution vendor
36        └── board                       # Name of the development board
37            ├── BUILD.gn                # Build script
38            ├── hals                    # Southbound APIs for OS adaptation
39            ├── linux                   # Linux kernel version (optional)
40            │   └── config.gni          # Build options for the Linux version
41            └── liteos_a                # LiteOS kernel version (optional)
42                └── config.gni          # Build options for the LiteOS Cortex-A version
43    ```
44
45    For example, if you are porting the Linux kernel to the hispark\_taurus development board, the directory tree is as follows:
46
47    ```
48    device
49    └── hisilicon
50        └── hispark_tautus
51            ├── BUILD.gn
52            ├── hals
53            ├── ......
54            └── linux
55                └── config.gni
56    ```
57
58    After the directory tree is created, store the source code related to the development board in the  **hispark\_taurus**  directory.
59
602.  Configure the build options of the development board.
61
62    You can configure the build options in the  **config.gni**  file described in  [1](#li20894101862). The compilation and building framework will then compile all OS components in the user space based on your configuration. The  **config.gni**  file contains the following key fields:
63
64    ```
65    kernel_type:            kernel used by the development board, for example, liteos_a, liteos_m, or linux.
66    kernel_version:         kernel version used by the development board, for example, 4.19.
67    board_cpu:              CPU of the development board, for example, cortex-a7 or riscv32.
68    board_arch:             chipset architecture of the development board, for example, armv7-a or rv32imac.
69    board_toolchain:        name of the customized compiler used by the development board, for example, gcc-arm-none-eabi. If this field is not specified, ohos-clang will be used by default.
70    board_toolchain_prefix: prefix of the compiler, for example, gcc-arm-none-eabi.
71    board_toolchain_type:  compiler type, for example, gcc or clang. Currently, only GCC and clang are supported.
72    board_cflags:          build options of the .c file configured for the development board.
73    board_cxx_flags:       build options of the .cpp file configured for the development board.
74    board_ld_flags:        link options configured for the development board.
75    ```
76
77    For HiSilicon's hispark\_taurus development board, the content in  **device/hisilicon/hispark\_taurus/config.gni**  is as follows:
78
79    ```
80    # Board CPU type, e.g. "cortex-a7", "riscv32".
81    board_cpu = "cortex-a7"
82
83    # Name of the compiler that is used for system building
84    # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang,  riscv32-unknown-elf.
85    # Note: The "ohos-clang" toolchain is used by default. You can also customize the toolchain.
86    board_toolchain = "mips-linux-gnu-gcc"
87
88    # Path where the toolchain is installed, which can be left blank if the installation path has been added to ~/.bashrc.
89    board_toolchain_path =
90        rebase_path("//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/bin",
91                    root_build_dir)
92
93    # Prefix of the toolchain
94    board_toolchain_prefix = "arm-linux-ohoseabi-"
95
96    # Type of the compiler, which can be gcc or clang
97    board_toolchain_type = "gcc"
98
99    # Building flags related to the board
100    board_cflags = [
101    ]
102    board_cxx_flags = [
103    ]
104    board_ld_flags = []
105
106    # Board related headfiles search path.
107    board_include_dirs = []
108    board_include_dirs += [ rebase_path(
109            "//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/target/usr/include",
110            root_build_dir) ]
111
112    # Board adapter dir for OHOS components.
113    board_adapter_dir = ""
114
115    # Sysroot path.
116    board_configed_sysroot = ""
117
118    # Board storage type, it used for file system generation.
119    storage_type = "emmc"
120    ```
121
1223.  Edit the build script of the development board.
123
124    In the  **BUILD.gn**  file described in step  [1](#li20894101862), build code related to the development board, such as code for the on-device driver, on-device interface adaptation \(media and graphics\), and SDK on the development board.
125
126    For example, edit the  **device/hisilicon/hispark\_taurus/BUILD.gn**  file as follows:
127
128    ```
129    # It is recommended that the group name be the same as the development board name.
130    group("hispark_taurus") {
131      deps = [ "//kernel/linux/patches:linux_kernel" ] # Start kernel compilation.
132      deps += [
133      ...... # Other compilation units of the development board
134      ]
135    }
136    ```
137
1384.  Start building and debugging.
139
140    In the directory of the development board, run the  **hb set**  and  **hb build**  commands to start building the chipset solution. The compilation framework starts the building with the  **BUILD.gn**  file in the directory as the entry.
141
142
143