• 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
188build_image_tools_path = [
189  "//out/${device_name}/clang_x64/thirdparty/e2fsprogs",
190  "//out/${device_name}/clang_x64/thirdparty/f2fs-tools",
191  "//third_party/e2fsprogs/prebuilt/host/bin",
192  "//build/ohos/images/mkimage",
193]
194
195base_dir = "//build/ohos/images/mkimage"
196
197foreach(_platform, target_platform_list) {
198  current_platform = _platform
199  current_platform_dir = "${product_output_dir}/$current_platform"
200
201  system_module_info_list = "${current_platform_dir}/system_module_info.json"
202  system_modules_list = "${current_platform_dir}/system_modules_list.txt"
203
204  image_list = [
205    "system",
206    "vendor",
207    "userdata",
208    "sys_prod",
209    "chip_prod",
210    "updater_ramdisk",
211    "eng_system",
212    "eng_chipset",
213  ]
214  if (enable_ramdisk) {
215    image_list += [ "ramdisk" ]
216  }
217  if (enable_adlt) {
218    action("execute_adlt") {
219      if (target_cpu == "arm64" || target_cpu == "x86_64") {
220        module_type = "lib64"
221      } else if (target_cpu == "arm" || target_cpu == "x86") {
222        module_type = "lib"
223      } else {
224        assert(false, "Unsupported target_cpu: $target_cpu")
225      }
226      script = "//build/ohos/images/adlt_wrapper.py"
227      args = [
228        "--allowed-lib-list",
229        rebase_path(allowed_lib_list),
230        "--output-file",
231        rebase_path(
232            "${current_platform_dir}/system/${module_type}/${adlt_lib_name}"),
233        "--adlt-exe",
234        rebase_path(adlt_exe),
235        "--adlt-root-dir",
236        rebase_path("${current_platform_dir}"),
237      ]
238      deps = [ "//build/ohos/packages:${_platform}_install_modules" ]
239      inputs = [
240        allowed_lib_list,
241        adlt_exe,
242      ]
243      outputs =
244          [ "${current_platform_dir}/system/${module_type}/${adlt_lib_name}" ]
245    }
246  }
247
248  foreach(_image_name, image_list) {
249    action_with_pydeps("${_platform}_${_image_name}_image") {
250      script = "//build/ohos/images/build_image.py"
251      depfile = "$target_gen_dir/$target_name.d"
252      deps = [ "//build/ohos/packages:${_platform}_install_modules" ]
253      if (enable_adlt && _image_name == "system") {
254        deps += [ ":execute_adlt" ]
255      }
256      if (!asan_detector) {
257        deps += [ "//build/ohos/packages:process_field_validate" ]
258        if (build_seccomp) {
259          deps += [ "//build/ohos/packages:check_seccomp_filter_name" ]
260        }
261      }
262
263      base_path = base_dir
264      if (is_debug) {
265        base_path = "${base_dir}/debug"
266      }
267      image_config_file = "${base_path}/${_image_name}_image_conf.txt"
268      if (asan_detector) {
269        image_config_file_asan =
270            "${base_path}/asan/${_image_name}_image_conf.txt"
271
272        # Check if asan image file exists
273        _file_exists_script = "//build/ohos/file_exists.py"
274        _process_args = [
275          "--filename",
276          rebase_path(image_config_file_asan, root_build_dir),
277        ]
278        _result = exec_script(_file_exists_script, _process_args, "string")
279        if (_result == "True") {
280          image_config_file = image_config_file_asan
281        }
282      }
283      device_image_config_file =
284          "${product_output_dir}/imagesconf/${_image_name}_image_conf.txt"
285      if (_image_name == "ramdisk" || _image_name == "updater_ramdisk") {
286        output_image_file = "$root_build_dir/${_image_name}.img"
287      } else {
288        output_image_file = "$current_platform_dir/images/${_image_name}.img"
289      }
290      if (_image_name == "updater_ramdisk") {
291        image_input_path = "$current_platform_dir/updater"
292      } else {
293        image_input_path = "$current_platform_dir/${_image_name}"
294      }
295      if (_image_name == "userdata") {
296        image_input_path = "$current_platform_dir/data"
297      }
298
299      sources = [
300        image_config_file,
301        system_module_info_list,
302        system_modules_list,
303      ]
304      outputs = [ output_image_file ]
305      args = [
306        "--depfile",
307        rebase_path(depfile, root_build_dir),
308        "--image-name",
309        _image_name,
310        "--input-path",
311        rebase_path(image_input_path, root_build_dir),
312        "--image-config-file",
313        rebase_path(image_config_file, root_build_dir),
314        "--device-image-config-file",
315        rebase_path(device_image_config_file, root_build_dir),
316        "--output-image",
317        rebase_path(output_image_file, root_build_dir),
318        "--target-cpu",
319        target_cpu,
320        "--build-variant",
321        build_variant,
322        "--build-image-tools-path",
323      ]
324      args += rebase_path(build_image_tools_path, root_build_dir)
325      if (sparse_image) {
326        args += [ "--sparse-image" ]
327      }
328    }
329  }
330
331  # Used to generate chip_prod images of different products
332  foreach(_product, chip_product_list) {
333    _image_name = "chip_prod"
334    action_with_pydeps("${_platform}_${_product}_chip_prod_image") {
335      script = "//build/ohos/images/build_image.py"
336      depfile = "$target_gen_dir/$target_name.d"
337      deps = [ "//build/ohos/packages:${_platform}_install_modules" ]
338
339      image_config_file = "${base_dir}/${_image_name}_image_conf.txt"
340      device_image_config_file =
341          "${product_output_dir}/imagesconf/${_image_name}_image_conf.txt"
342      image_input_path = "${current_platform_dir}/${_image_name}/${_product}"
343      output_image_file =
344          "${current_platform_dir}/images/${_product}/${_image_name}.img"
345
346      sources = [
347        image_config_file,
348        system_module_info_list,
349        system_modules_list,
350      ]
351      outputs = [ output_image_file ]
352
353      args = [
354        "--depfile",
355        rebase_path(depfile, root_build_dir),
356        "--image-name",
357        _image_name,
358        "--input-path",
359        rebase_path(image_input_path, root_build_dir),
360        "--image-config-file",
361        rebase_path(image_config_file, root_build_dir),
362        "--device-image-config-file",
363        rebase_path(device_image_config_file, root_build_dir),
364        "--output-image",
365        rebase_path(output_image_file, root_build_dir),
366        "--target-cpu",
367        target_cpu,
368        "--build-image-tools-path",
369      ]
370      args += rebase_path(build_image_tools_path, root_build_dir)
371      if (sparse_image) {
372        args += [ "--sparse-image" ]
373      }
374    }
375  }
376
377  action("mk_chip_ckm_img") {
378    script = "//build/ohos/images/mkimage/mkchip_ckm.py"
379    device_name = "packages/phone/images/chip_ckm.img"
380    build_image_tool_path = [
381      "$root_build_dir/clang_x64/thirdparty/f2fs-tools",
382      "$root_build_dir/clang_x64/thirdparty/e2fsprogs",
383      "//third_party/e2fsprogs/prebuilt/host/bin",
384    ]
385    config_file_path = "//build/ohos/images/mkimage/chip_ckm.txt"
386    mkextimage_tools_path = "//build/ohos/images/mkimage/mkextimage.py"
387
388    src_dir = "packages/phone/chip_ckm"
389    args = [
390      "--src-dir",
391      src_dir,
392      "--device-name",
393      device_name,
394      "--config-file-path",
395      rebase_path(config_file_path, root_build_dir),
396      "--mkextimage-tools-path",
397      rebase_path(mkextimage_tools_path, root_build_dir),
398      "--build-image-tools-path",
399    ]
400    args += rebase_path(build_image_tool_path, root_build_dir)
401    if (is_standard_system) {
402      deps = [
403        "//base/security/selinux_adapter:build_contexts",
404        "//kernel/linux/common_modules:ko_build",
405        "//third_party/e2fsprogs:e2fsprogs_host_toolchain",
406        "//third_party/f2fs-tools:f2fs-tools_host_toolchain",
407      ]
408    }
409    outputs = [ "$root_out_dir/packages/phone/images/chip_ckm.img" ]
410  }
411}
412