• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/config/python.gni")
15import("//build/ohos.gni")
16import("//build/ohos/build_var.gni")
17
18# import target_platform_list
19import("${build_configs_path}/platforms_list.gni")
20group("make_images") {
21  deps = []
22  if (is_standard_system) {
23    deps = [
24      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
25      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
26    ]
27    foreach(_platform, target_platform_list) {
28      deps += [
29        ":${_platform}_eng_chipset_image",
30        ":${_platform}_eng_system_image",
31        ":${_platform}_sys_prod_image",
32        ":${_platform}_system_image",
33        ":${_platform}_updater_ramdisk_image",
34        ":${_platform}_userdata_image",
35        ":${_platform}_vendor_image",
36      ]
37      if (enable_ramdisk) {
38        deps += [ ":${_platform}_ramdisk_image" ]
39      }
40    }
41    deps += [ ":chip_prod_image" ]
42    if (is_standard_system && device_name == "rk3568") {
43      deps += [ ":mk_chip_ckm_img" ]
44    }
45  } else {
46    deps += [ "//build/ohos/packages:packer" ]
47  }
48}
49
50group("eng_system_image") {
51  deps = []
52  if (is_standard_system) {
53    deps += [
54      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
55      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
56    ]
57  }
58  foreach(_platform, target_platform_list) {
59    deps += [ ":${_platform}_eng_system_image" ]
60  }
61}
62
63group("eng_chipset_image") {
64  deps = []
65  if (is_standard_system) {
66    deps += [
67      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
68      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
69    ]
70  }
71  foreach(_platform, target_platform_list) {
72    deps += [ ":${_platform}_eng_chipset_image" ]
73  }
74}
75
76group("chip_prod_image") {
77  deps = []
78  if (is_standard_system) {
79    deps += [
80      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
81      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
82    ]
83  }
84  foreach(_platform, target_platform_list) {
85    if (chip_product_list == []) {
86      deps += [ ":${_platform}_chip_prod_image" ]
87    } else {
88      foreach(_product, chip_product_list) {
89        deps += [ ":${_platform}_${_product}_chip_prod_image" ]
90      }
91    }
92  }
93}
94
95group("sys_prod_image") {
96  deps = []
97  if (is_standard_system) {
98    deps += [
99      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
100      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
101    ]
102  }
103  foreach(_platform, target_platform_list) {
104    deps += [ ":${_platform}_sys_prod_image" ]
105  }
106}
107
108group("system_image") {
109  deps = []
110  if (is_standard_system) {
111    deps += [
112      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
113      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
114    ]
115  }
116  foreach(_platform, target_platform_list) {
117    deps += [ ":${_platform}_system_image" ]
118  }
119}
120
121group("userdata_image") {
122  deps = []
123  if (is_standard_system) {
124    deps += [
125      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
126      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
127    ]
128  }
129  foreach(_platform, target_platform_list) {
130    deps += [ ":${_platform}_userdata_image" ]
131  }
132}
133
134group("vendor_image") {
135  deps = []
136  if (is_standard_system) {
137    deps += [
138      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
139      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
140    ]
141  }
142  foreach(_platform, target_platform_list) {
143    deps += [ ":${_platform}_vendor_image" ]
144  }
145}
146
147group("ramdisk_image") {
148  deps = []
149  if (is_standard_system) {
150    deps += [
151      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
152      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
153    ]
154  }
155  foreach(_platform, target_platform_list) {
156    if (enable_ramdisk) {
157      deps += [ ":${_platform}_ramdisk_image" ]
158    }
159  }
160}
161
162group("updater_ramdisk_image") {
163  deps = []
164  if (is_standard_system) {
165    deps += [
166      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
167      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
168    ]
169  }
170  foreach(_platform, target_platform_list) {
171    deps += [ ":${_platform}_updater_ramdisk_image" ]
172  }
173}
174
175group("updater_image") {
176  deps = []
177  if (is_standard_system) {
178    deps += [
179      "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
180      "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
181    ]
182  }
183  foreach(_platform, target_platform_list) {
184    deps += [ ":${_platform}_updater_ramdisk_image" ]
185  }
186}
187
188if (host_cpu == "arm64") {
189  build_image_tools_path = [
190    "//out/${device_name}/clang_arm64/thirdparty/e2fsprogs",
191    "//out/${device_name}/clang_arm64/thirdparty/f2fs-tools",
192  ]
193} else {
194  build_image_tools_path = [
195    "//out/${device_name}/clang_x64/thirdparty/e2fsprogs",
196    "//out/${device_name}/clang_x64/thirdparty/f2fs-tools",
197  ]
198}
199
200build_image_tools_path += [
201  "//third_party/e2fsprogs/prebuilt/host/bin",
202  "//build/ohos/images/mkimage",
203]
204
205base_dir = "//build/ohos/images/mkimage"
206
207foreach(_platform, target_platform_list) {
208  current_platform = _platform
209  current_platform_dir = "${product_output_dir}/$current_platform"
210
211  system_module_info_list = "${current_platform_dir}/system_module_info.json"
212  system_modules_list = "${current_platform_dir}/system_modules_list.txt"
213
214  image_list = [
215    "system",
216    "vendor",
217    "userdata",
218    "sys_prod",
219    "chip_prod",
220    "updater_ramdisk",
221    "eng_system",
222    "eng_chipset",
223  ]
224  if (enable_ramdisk) {
225    image_list += [ "ramdisk" ]
226  }
227  if (enable_adlt) {
228    action("execute_adlt") {
229      if (target_cpu == "arm64" || target_cpu == "x86_64") {
230        module_type = "lib64"
231      } else if (target_cpu == "arm" || target_cpu == "x86") {
232        module_type = "lib"
233      } else {
234        assert(false, "Unsupported target_cpu: $target_cpu")
235      }
236      script = "//build/ohos/images/adlt_wrapper.py"
237      args = [
238        "--allowed-lib-list",
239        rebase_path(allowed_lib_list),
240        "--output-file",
241        rebase_path(
242            "${current_platform_dir}/system/${module_type}/${adlt_lib_name}"),
243        "--adlt-exe",
244        rebase_path(adlt_exe),
245        "--adlt-root-dir",
246        rebase_path("${current_platform_dir}"),
247      ]
248      deps = [ "//build/ohos/packages:${_platform}_install_modules" ]
249      inputs = [
250        allowed_lib_list,
251        adlt_exe,
252      ]
253      outputs =
254          [ "${current_platform_dir}/system/${module_type}/${adlt_lib_name}" ]
255    }
256  }
257
258  foreach(_image_name, image_list) {
259    action_with_pydeps("${_platform}_${_image_name}_image") {
260      script = "//build/ohos/images/build_image.py"
261      depfile = "$target_gen_dir/$target_name.d"
262      deps = [ "//build/ohos/packages:${_platform}_install_modules" ]
263      if (enable_adlt && _image_name == "system") {
264        deps += [ ":execute_adlt" ]
265      }
266      if (!asan_detector) {
267        deps += [ "//build/ohos/packages:process_field_validate" ]
268        if (build_seccomp) {
269          deps += [ "//build/ohos/packages:check_seccomp_filter_name" ]
270        }
271      }
272
273      base_path = base_dir
274      if (is_debug) {
275        base_path = "${base_dir}/debug"
276      }
277      image_config_file = "${base_path}/${_image_name}_image_conf.txt"
278      if (asan_detector) {
279        image_config_file_asan =
280            "${base_path}/asan/${_image_name}_image_conf.txt"
281
282        # Check if asan image file exists
283        _file_exists_script = "//build/ohos/file_exists.py"
284        _process_args = [
285          "--filename",
286          rebase_path(image_config_file_asan, root_build_dir),
287        ]
288        _result = exec_script(_file_exists_script, _process_args, "string")
289        if (_result == "True") {
290          image_config_file = image_config_file_asan
291        }
292      }
293      device_image_config_file =
294          "${product_output_dir}/imagesconf/${_image_name}_image_conf.txt"
295      if (_image_name == "ramdisk" || _image_name == "updater_ramdisk") {
296        output_image_file = "$root_build_dir/${_image_name}.img"
297      } else {
298        output_image_file = "$current_platform_dir/images/${_image_name}.img"
299      }
300      if (_image_name == "updater_ramdisk") {
301        image_input_path = "$current_platform_dir/updater"
302      } else {
303        image_input_path = "$current_platform_dir/${_image_name}"
304      }
305      if (_image_name == "userdata") {
306        image_input_path = "$current_platform_dir/data"
307      }
308
309      sources = [
310        image_config_file,
311        system_module_info_list,
312        system_modules_list,
313      ]
314      outputs = [ output_image_file ]
315      args = [
316        "--depfile",
317        rebase_path(depfile, root_build_dir),
318        "--image-name",
319        _image_name,
320        "--input-path",
321        rebase_path(image_input_path, root_build_dir),
322        "--image-config-file",
323        rebase_path(image_config_file, root_build_dir),
324        "--device-image-config-file",
325        rebase_path(device_image_config_file, root_build_dir),
326        "--output-image",
327        rebase_path(output_image_file, root_build_dir),
328        "--target-cpu",
329        target_cpu,
330        "--build-variant",
331        build_variant,
332        "--build-image-tools-path",
333      ]
334      args += rebase_path(build_image_tools_path, root_build_dir)
335      if (sparse_image) {
336        args += [ "--sparse-image" ]
337      }
338    }
339  }
340
341  # Used to generate chip_prod images of different products
342  foreach(_product, chip_product_list) {
343    _image_name = "chip_prod"
344    action_with_pydeps("${_platform}_${_product}_chip_prod_image") {
345      script = "//build/ohos/images/build_image.py"
346      depfile = "$target_gen_dir/$target_name.d"
347      deps = [ "//build/ohos/packages:${_platform}_install_modules" ]
348
349      image_config_file = "${base_dir}/${_image_name}_image_conf.txt"
350      device_image_config_file =
351          "${product_output_dir}/imagesconf/${_image_name}_image_conf.txt"
352      image_input_path = "${current_platform_dir}/${_image_name}/${_product}"
353      output_image_file =
354          "${current_platform_dir}/images/${_product}/${_image_name}.img"
355
356      sources = [
357        image_config_file,
358        system_module_info_list,
359        system_modules_list,
360      ]
361      outputs = [ output_image_file ]
362
363      args = [
364        "--depfile",
365        rebase_path(depfile, root_build_dir),
366        "--image-name",
367        _image_name,
368        "--input-path",
369        rebase_path(image_input_path, root_build_dir),
370        "--image-config-file",
371        rebase_path(image_config_file, root_build_dir),
372        "--device-image-config-file",
373        rebase_path(device_image_config_file, root_build_dir),
374        "--output-image",
375        rebase_path(output_image_file, root_build_dir),
376        "--target-cpu",
377        target_cpu,
378        "--build-image-tools-path",
379      ]
380      args += rebase_path(build_image_tools_path, root_build_dir)
381      if (sparse_image) {
382        args += [ "--sparse-image" ]
383      }
384    }
385  }
386
387  action("mk_chip_ckm_img") {
388    script = "//build/ohos/images/mkimage/mkchip_ckm.py"
389    device_name = "packages/phone/images/chip_ckm.img"
390
391    if (host_cpu == "arm64") {
392      build_image_tool_path = [
393        "$root_build_dir/clang_arm64/thirdparty/f2fs-tools",
394        "$root_build_dir/clang_arm64/thirdparty/e2fsprogs",
395      ]
396    } else {
397      build_image_tool_path = [
398        "$root_build_dir/clang_x64/thirdparty/f2fs-tools",
399        "$root_build_dir/clang_x64/thirdparty/e2fsprogs",
400      ]
401    }
402    build_image_tool_path += [ "//third_party/e2fsprogs/prebuilt/host/bin" ]
403
404    config_file_path = "//build/ohos/images/mkimage/chip_ckm.txt"
405    mkextimage_tools_path = "//build/ohos/images/mkimage/mkextimage.py"
406
407    src_dir = "packages/phone/chip_ckm"
408    args = [
409      "--src-dir",
410      src_dir,
411      "--device-name",
412      device_name,
413      "--config-file-path",
414      rebase_path(config_file_path, root_build_dir),
415      "--mkextimage-tools-path",
416      rebase_path(mkextimage_tools_path, root_build_dir),
417      "--build-image-tools-path",
418    ]
419    args += rebase_path(build_image_tool_path, root_build_dir)
420    if (is_standard_system) {
421      deps = [
422        "//base/security/selinux_adapter:build_contexts",
423        "//kernel/linux/common_modules:ko_build",
424        "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
425        "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
426      ]
427    }
428    outputs = [ "$root_out_dir/packages/phone/images/chip_ckm.img" ]
429  }
430}
431