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