porting-smallchip-prepare-building.md 6.2 KB
Newer Older
E
ester.zhou 已提交
1
# Compilation and Building
D
duangavin123 已提交
2

E
ester.zhou 已提交
3 4
## Compilation Environment Setup

E
ester.zhou 已提交
5
Set 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:
D
duangavin123 已提交
6 7 8 9 10 11 12


```
sudo apt-get install gcc-arm-linux-gnueabi
```


E
ester.zhou 已提交
13
## Introduction to the Compilation and Building Subsystem
D
duangavin123 已提交
14

E
ester.zhou 已提交
15
To 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).
D
duangavin123 已提交
16 17


E
ester.zhou 已提交
18
## Adding a Chipset Solution
D
duangavin123 已提交
19

E
ester.zhou 已提交
20
After learning the compilation framework and setting up the compilation environment, perform the following steps to create a chipset solution:
D
duangavin123 已提交
21

E
ester.zhou 已提交
22 23 24 25 26
1. Create a category.
   
   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:
   
   
E
ester.zhou 已提交
27 28 29 30
   ```
   mkdir -p device/hisilicon/hispark_taurus
   ```

E
ester.zhou 已提交
31
   The chipset solution directory tree is as follows:
E
ester.zhou 已提交
32

E
ester.zhou 已提交
33
   
E
ester.zhou 已提交
34 35 36 37 38 39 40 41 42 43 44 45
   ```
   device                                      
   └── company                         # Chipset solution vendor
       └── board                       # Name of the development board
           ├── BUILD.gn                # Build script
           ├── hals                    # OS device API adaptation
           ├── linux                   # (Optional) Linux kernel version
           │   └── config.gni          # Linux build configuration
           └── liteos_a                # (Optional) LiteOS kernel version
               └── config.gni          # LiteOS_A build configuration
   ```

E
ester.zhou 已提交
46 47 48
   For example, if you are porting the Linux kernel to the hispark_taurus development board, the directory tree is as follows:
   
   
E
ester.zhou 已提交
49 50 51 52 53 54 55 56 57 58
   ```
   device                  
   └── hisilicon             
       └── hispark_taurus          
           ├── BUILD.gn    
           ├── hals        
           ├── ......      
           └── linux    
               └── config.gni  
   ```
E
ester.zhou 已提交
59 60 61 62 63 64 65 66
   
   After the directory tree is created, store the source code related to the development board in the **hispark_taurus** directory.
   
2. Configure the build options of the development board.

   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:


E
ester.zhou 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
   ```
   kernel_type: Kernel used by the development board, for example, LiteOS_A, LiteOS_M, or Linux.
   kernel_version: Kernel version used by the development board, for example, 4.19.
   board_cpu: CPU of the development board, for example, Cortex-A7 or RISCV32.
   board_arch: Chipset architecture of the development board, for example, armv7-a or rv32imac.
   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.
   board_toolchain_prefix: Prefix of the toolchain, for example, gcc-arm-none-eabi.
   board_toolchain_type: Toolchain type. Currently, only GCC and clang are supported.
   board_cflags: Build options of the .c file configured for the development board.
   board_cxx_flags: Build options of the .cpp file configured for the development board.
   board_ld_flags: Linking options configured for the development board.
   ```

     For HiSilicon's hispark_taurus development board, the content in **device/hisilicon/hispark_taurus/config.gni** is as follows:
   
   ```
   # Board CPU type, e.g. "cortex-a7", "riscv32".
   board_cpu = "cortex-a7"
   
   # Name of the toolchain used for system building
   # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang,  riscv32-unknown-elf.
   # Note: The "ohos-clang" toolchain is used by default. You can also customize the toolchain.
   board_toolchain = "mips-linux-gnu-gcc"
   
   # Path where the toolchain is installed, which can be left blank if the installation path has been added to ~/.bashrc.
   board_toolchain_path = 
       rebase_path("//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/bin",
                   root_build_dir)
   
   # Prefix of the toolchain
   board_toolchain_prefix = "arm-linux-ohoseabi-"
   
   # Type of the compiler, which can be gcc or clang
   board_toolchain_type = "gcc"
   
   # Build options related to the development board
   board_cflags = [
   ]
   board_cxx_flags = [
   ]
   board_ld_flags = []
   
   # Board related headfiles search path.
   board_include_dirs = []
   board_include_dirs += [ rebase_path(
           "//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/target/usr/include",
           root_build_dir) ]
   
   # Board adapter dir for OHOS components.
   board_adapter_dir = ""
   
   # Sysroot path.
   board_configed_sysroot = ""
   
   # Board storage type, it used for file system generation.
   storage_type = "emmc"
   ```
E
ester.zhou 已提交
124 125 126 127 128 129 130

3. Edit the build script of the development board.

   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.

   For example, edit the **device/hisilicon/hispark_taurus/BUILD.gn** file as follows:

E
ester.zhou 已提交
131 132 133 134 135 136 137 138 139 140
   
   ```
   # It is recommended that the group name be the same as the development board name.
   group("hispark_taurus") {   
     deps = [ "//kernel/linux/patches:linux_kernel" ] # Start kernel compilation.
     deps += [
     ...... # Other compilation units of the development board
     ]
   }
   ```
E
ester.zhou 已提交
141 142 143 144

4. Start building and debugging.

   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.