Compilation Notes
Installing the Compiler
Execute the script in the source code root directory to install the compiler and binary tools.
bash build/prebuilts_download.sh
By default, the downloaded files are stored in the same directory as OpenHarmony, under openharmony_prebuilts.
root@ubuntu:~/WorkSpace$ tree -L 1
.
|-- oh5
`-- openharmony_prebuilts
2 directories, 0 files
The contents of openharmony_prebuilts are as follows:
root@ubuntu:~/WorkSpace/openharmony_prebuilts$ ls -al
total 4970668
drwxr-xr-x 2 root dc-sw-users 4096 Oct 28 08:39 .
drwxr-xr-x 6 root dc-sw-users 4096 Oct 26 18:06 ..
-rw-r--r-- 1 root dc-sw-users 70959548 Sep 27 17:35 015654433b541c15ac605ecb2dd32f11.libcxx-ndk_ohos-arm64-5fbff2-20240727.tar.gz
-rw-r--r-- 1 root dc-sw-users 1151488 Sep 27 17:27 03a7b98353c5261f51bc2e5ec28dfed9.gn-linux-x86-20240510.tar.gz
-rw-r--r-- 1 root dc-sw-users 118696253 Sep 27 17:38 0c65e233a7c5b1ecf6585a38903cc52e.clang-mingw-20240510.tar.gz
-rw-r--r-- 1 root dc-sw-users 70970417 Oct 28 08:40 1822bea68b38ab77f1714d89e8453c34.libcxx-ndk_linux-x86_64-ef33c3-20240828.tar.gz
-rw-r--r-- 1 root dc-sw-users 298786 Sep 27 17:27 1ad55caffc571c067e7748967b86f477.ninja-windows-x86-1.12.0-20240523.tar.gz
-rw-r--r-- 1 root dc-sw-users 530721 Sep 27 17:28 20738011b324e100f6aab09353a7e7fa.bpftool_v5.10.93_20221114.tar.gz
-rw-r--r-- 1 root dc-sw-users 29078522 Sep 27 17:31 44e99f695a2058603263903a1198b79e.rust-std-nightly-x86_64-pc-windows-gnullvm_20240528.tar.gz
-rw-r--r-- 1 root dc-sw-users 35031005 Sep 27 17:32 44f2993d118ed3cefe4792a2fd62547f.node-v14.21.1-linux-x64.tar.gz
-rw-r--r-- 1 root dc-sw-users 31562008 Sep 27 17:32 46e8165e2cfa7799732c23615c5a3fa1.rust-std-nightly-x86_64-unknown-linux-ohos_20240528.tar.gz
-rw-r--r-- 1 root dc-sw-users 620135753 Sep 27 17:46 4fe01b604194d203f0371902cd6b4473.clang_windows-x86_64-5fbff2-20240727.tar.gz
-rw-r--r-- 1 root dc-sw-users 1446576155 Sep 27 17:51 5211242bf5608753c7488874c758dd0f.clang_ohos-arm64-5fbff2-20240727.tar.gz
-rw-r--r-- 1 root dc-sw-users 194623101 Sep 27 17:38 59325cdd5538f70910f66328acedea7d.prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi.tar.gz
-rw-r--r-- 1 root dc-sw-users 329772635 Sep 27 17:41 6a4909fc4262070aea24465c9a3aabc4.ark_js_prebuilts_20230713.tar.gz
-rw-r--r-- 1 root dc-sw-users 70953802 Sep 27 17:35 6be4fdb05760c8b2887f96c08ebff7b8.libcxx-ndk_windows-x86_64-5fbff2-20240727.tar.gz
-rw-r--r-- 1 root dc-sw-users 9048182 Oct 28 08:39 6c3294e4d1c73219c2bed617e6ab9676.python-linux-x86-Ubuntu_18.04-3.11.4_20240823.tar.gz
-rw-r--r-- 1 root dc-sw-users 30678419 Sep 27 17:31 6ea2077dceef4e1f0953819bc7c96e1f.rust-std-nightly-aarch64-unknown-linux-ohos_20240528.tar.gz
-rw-r--r-- 1 root dc-sw-users 9254059 Sep 27 17:29 741544d67d8d0281ba0d670b561b379b.python-linux-x86-Ubuntu_18.04-3.11.4_20240715.tar.gz
-rw-r--r-- 1 root dc-sw-users 27628068 Sep 27 17:32 76a4e507e09cb3693edaa91f5985ab8f.rust-std-nightly-armv7-unknown-linux-ohos_20240528.tar.gz
-rw-r--r-- 1 root dc-sw-users 17297524 Sep 27 17:29 7bcb19ee6150676833e5aa5d6a7bfe03.cmake-ohos-3.28.2.tar.gz
-rw-r--r-- 1 root dc-sw-users 106664705 Sep 27 17:36 8038bbe7160f809232e8df72e3980c92.rust-nightly-x86_64-unknown-linux-gnu_20240528.tar.gz
-rw-r--r-- 1 root dc-sw-users 52840113 Sep 27 17:33 9b1ca53ad98ebfaa0fbfa26d20d534df.cmake-linux-x86-3.28.2.tar.gz
-rw-r--r-- 1 root dc-sw-users 12397424 Sep 27 17:30 ae867132e2a2bdbbae5b58aa89eb883e.pahole_v1.21_20221124.tar.gz
-rw-r--r-- 1 root dc-sw-users 70969730 Oct 28 08:41 c9b9261adf5c264aa35312aeb8261419.libcxx-ndk_ohos-arm64-ef33c3-20240828.tar.gz
-rw-r--r-- 1 root dc-sw-users 117896452 Sep 27 17:36 cd98ff85e2af3869cf318497e6a1d559.gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
-rw-r--r-- 1 root dc-sw-users 15135801 Oct 28 08:39 d699eb29e0a9c9febb2b13bb779c1ebb.cmake-ohos-3.28.2-20240827.tar.gz
-rw-r--r-- 1 root dc-sw-users 70960099 Sep 27 17:35 d991cf9857b70074d0e7981807f280de.libcxx-ndk_linux-x86_64-5fbff2-20240727.tar.gz
-rw-r--r-- 1 root dc-sw-users 128365 Sep 27 17:27 dfcaa71177f12992d9542b6c8e60d363.ninja-linux-x86-1.12.0-20240523.tar.gz
-rw-r--r-- 1 root dc-sw-users 270405 Oct 28 08:39 e0c9e1b221277cd431bc9dcba432c3e1.ninja-ohos-1.12.0-20240827.tar.gz
-rw-r--r-- 1 root dc-sw-users 33784208 Sep 27 17:33 e778f29e95d22f8e3cb6e604936229dc.node-v16.20.2-linux-x64.tar.gz
-rw-r--r-- 1 root dc-sw-users 39492529 Sep 27 17:33 ebe7c49b8fdbb8cebc06adb7fef9cb4b.cmake-windows-x86-3.28.2.tar.gz
-rw-r--r-- 1 root dc-sw-users 2052940 Sep 27 17:28 ecc8770b5ab13932696406bf43a5401b.packing_tool_libs_20240730.zip
-rw-r--r-- 1 root dc-sw-users 462116 Sep 27 17:27 f8dea77cc089365ea9b35880dbc252b3.ninja-ohos-1.12.0-20240527.tar.gz
-rw-r--r-- 1 root dc-sw-users 1452493082 Oct 28 08:52 f997ab75c9658a9e47bb4db7b91b89a3.clang_ohos-arm64-ef33c3-20240828.tar.gz
Full compilation
Enter the source code root directory and execute
cd oh5
./build.sh --product-name smt001 --ccache --prebuilt-sdk
Common build parameter description
–fast-rebuild
./build.sh --product-name smt001 --ccache --no-prebuilt-sdk --fast-rebuild
## 编译流程主要分为:preloader->loader->gn->ninja这四个过程
## 在本地没有修改gn和产品配置相关文件的前提下,--fast-rebuild会直接从ninja编译开始
## 该参数可以减少编译总耗时
–prebuilt-sdk
Before executing the full compilation, compile the SDK first, and copy the SDK to prebuilts/ohos-sdk. build.sh supports specifying the SDK's operating platform through the parameter sdk_platform=xxx, supporting mac/win/linux/
ohos/default, default is {windows,linux,ohos} on a Linux host and {mac} on a Mac host
For example:
./build.sh --product-name smt001 --ccache --prebuilt-sdk sdk_platform=default
Generate burning img
./build/gen_zip.sh smt001
The generated burnable img is in
out/smt001/packages/phone/images/openharmony-spacemit-smt001.zip
Compile the kernel separately
./build.sh -product-name smt001 --ccache --prebuilt-sdk -T build_kernel
The build_kernel above is defined in device/board/spacemit/smt001/kernel/BUILD.gn:
action("build_kernel") {
script = "build_kernel.sh"
sources = [ kernel_source_dir ]
outputs = [ "$root_build_dir/packages/phone/images/Image" ]
args = [
rebase_path(kernel_build_script_dir,root_build_dir),
rebase_path("$root_build_dir/../.."),
rebase_path("$root_build_dir/packages/phone/images"),
rebase_path(kernel_source_dir),
rebase_path(kernel_build_script_dir),
kernel_ramdisk,
product_company,
product_name,
]
}
The kernel source code path is: kernel/linux/spacemit_kernel-6.6
The kernel source code path after patching generated in the out directory is: out/kernel/OBJ/smt001
The compiled kernel image path is: out/kernel/OBJ/smt001/arch/riscv/boot/Image.itb
The compiled dtb file path is: out/kernel/OBJ/smt001/arch/riscv/boot/dts/spacemit/k1-x_smt001.dtb
The generated kernel image and dtb file will be automatically copied to the out/smt001/packages/phone/images/bootfs directory, and the packaging script will package them into img.
Compile the HDF adaptation layer separately
Take display as an example:
./build.sh -product-name smt001 --ccache --prebuilt-sdk -T display_composer_vendor
The display adaptation code is in device/soc/spacemit/k1/hardware/display, and the definition of display_composer_vendor is in device/soc/spacemit/k1/hardware/display/BUILD.gn
ohos_shared_library("display_composer_vendor") {
sources = [
"src/display_device/drm_connector.cpp",
"src/display_device/drm_crtc.cpp",
"src/display_device/drm_device.cpp",
...
]
}
The compiled so is in:
-rwxr-x---+ 1 root root 181000 Jun 7 08:55 ./out/smt001/hdf/spacemit_products/libdisplay_composer_vendor.z.so
The so in the folder below has not been updated. You need to pay attention to the update time and md5 value
-rwxr-x---+ 1 root root 180968 Jun 6 16:02 ./out/smt001/packages/phone/vendor/lib64/libdisplay_composer_vendor.z.so
The generated dynamic library can be pushed to the machine through hdc to facilitate debugging and avoid re-burning the firmware. The command is as follows:
D:\>hdc shell
# mount -o remount,rw / #system分区可读写
# mount -o remount,rw /vendor #vendor分区可读写
# exit
D:\>hdc file send libdisplay_composer_vendor.z.so /vendor/lib64/
D:\>hdc shell
# reboot
Compile SDK separately
./build.py --product-name ohos-sdk --ccache=true --xcache=false --load-test-config=false --get-warning-list=false --stat-ccache=false --compute-overlap-rate=false --deps-guard=false --generate-ninja-trace=false --gn-args skip_generate_module_list_file=true use_cfi=false use_thin_lto=false enable_lto_O0=true sdk_check_flag=false enable_ndk_doxygen=false archive_ndk=false sdk_for_hap_build=true enable_archive_sdk=false enable_notice_collection=false enable_process_notice=false
By changing the sdk_platform and ndk_platform parameters, you can compile SDKs running on different OSes. The NDK output is located in out/sdk/sdk-native
Fast Compile
Compiling the target module is faster with the following command:
ninja -w dupbuild=warn -C out/xxx yyy -j8
xxx represents the solution name yyy represents the build target
For example, to compile the libomxvpu_dec target of the smt001 solution, the command is as follows:
ninja -w dupbuild=warn -C out/smt001 libomxvpu_dec -j8