• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
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
14#                                    +-----------------+
15#                                    | topographic map |
16#                                    +-----------------+
17# topographic map descripe how to generate write_flash_gui.tar.gz, according to depends rules.
18#
19#                               +-----------------------------+
20#                       +-----> |    copy_${exe_bin}_to_gui   |
21#                       |       +-----------------------------+
22#                       |       +-----------------------------+
23#                       +-----> |   copy_${fs_name}_to_gui    |
24# +---------------+     |       +-----------------------------+
25# | pack_flash_gui|---> +
26# +---------------+     |       +-----------------------------+
27#                       +-----> | copy_${bsp_bin_name}_to_gui |
28#                       |       +-----------------------------+
29#                       |       +-----------------------------+     +-----------------+
30#                       +-----> | update_${product_name}_yaml | --> | init_burn_tools |
31#                               +-----------------------------+     +-----------------+
32#                                                                                             +--------------------+     +---------+
33#                                                                                             | gen_bin_${exe_bin} | --> | exe_bin |
34# excutable bin topographic map:                                                              +--------------------+     +---------+
35#                             +--------+                  +-------------------------------+   /                                |
36#                             | no sig | ---------------> | copy_${exe_bin}_to_relase_bin | -+                                \|/
37#                             +--------+                  +-------------------------------+   \                                V
38# +------------------------+   /                                ^                              +-----------------+  +------------------------+
39# | copy_${exe_bin}_to_gui | -+                                /|\                             | init_burn_tools |  | gen_bsp_lib_${exe_bin} |
40# +------------------------+   \                                |                              +-----------------+  +------------------------+
41#                             +--------+     +--------------------------+                                                       |
42#                             |  sig   | --> | gen_bin_${burn_name}_sig |                                                      \|/
43#                             +--------+     +--------------------------+                                                       V
44#                                                                                                                    +--------------------+
45#                                                                                                                    | build_sdk_into_lib |
46#                                                                                                                    +--------------------+
47#
48# fs bin topographic map:
49#                             +--------+         +------------------+   +-----------------+
50#                             | no sig | ------> | genfs_${fs_name} |-->| init_burn_tools |
51#                             +--------+         +------------------+   +-----------------+
52# +------------------------+   /                         ^
53# | copy_${fs_name}_to_gui | -+                         /|\
54# +------------------------+   \                         |
55#                             +--------+     +----------------------+
56#                             |  sig   | --> | genfs_${fs_name}_sig |
57#                             +--------+     +----------------------+
58#
59# bsp bin topographic map:
60#                                                                                               +--------------------+
61#                                                                                               | build_sdk_into_lib |
62#                                                                                               +--------------------+
63#                                  +--------+         +------------------------------------+   /
64#                                  | no sig | ------> | copy_${bsp_bin_name}_to_relase_bin | -+
65#                                  +--------+         +------------------------------------+   \
66# +------------------------------+   /                         ^                                +-----------------+
67# | copy_${bsp_bin_name}_to_gui  | -+                         /|\                               | init_burn_tools |
68# +------------------------------+   \                         |                                +-----------------+
69#                                  +--------+     +------------------------------+
70#                                  |  sig   | --> | gen_bsp_bin_${burn_name}_sig |
71#                                  +--------+     +------------------------------+
72
73if (ohos_kernel_type == "liteos_m") {
74  import("//build/lite/config/component/lite_component.gni")
75  import("//build/lite/config/subsystem/lite_subsystem.gni")
76  import("//kernel/liteos_m/liteos.gni")
77  module_name = get_path_info(rebase_path("."), "name")
78  module_group(module_name) {
79    modules = [ "liteos_m" ]
80  }
81
82  # global config
83  out_product_path = "${ohos_root_path}out/${board_name}/${product_name}"
84
85  build_ext_component("init_burn_tools") {
86    exec_path = rebase_path("pack_tools")
87    command =
88        "./init_burn_tools.sh ./../../ ${out_product_path} ${product_path}"
89  }
90
91  # config bin from vendor/bestechnic/<product_name>/config.json
92  foreach(bin_file, bin_list) {
93    build_enable = bin_file.enable
94    unstripped_folder = "unstripped/"
95    if (ohos_build_type == "release") {
96      unstripped_folder = ""
97    }
98    out_bin_path = "${out_product_path}/${unstripped_folder}bin/"
99
100    if (build_enable == "true") {
101      exe_bin = "${bin_file.elf_name}_${board_name}"
102      bsp_target_name = bin_file.bsp_target_name
103      print("build", exe_bin, ":", build_enable)
104      copy_lib_name = "gen_bsp_lib_${exe_bin}"
105
106      # generate execute bin
107      executable(exe_bin) {
108        output_name = exe_bin
109        output_extension = "elf"
110        deps = [ "liteos_m/sdk:${copy_lib_name}" ]
111
112        ldflags = [
113          "-Wl,--gc-sections",
114          "-Wl,-Map=bin/$output_name.map",
115        ]
116
117        # force link invisible function ,which ar to lib
118        ldflags += [ "-Wl,--whole-archive" ]
119        foreach(force_link_lib, bin_file.force_link_libs) {
120          ldflags += [ "-l${force_link_lib}" ]
121        }
122        ldflags += [ "-lbsp${bsp_target_name}" ]
123        ldflags += [ "-Wl,--no-whole-archive" ]
124
125        libs = [
126          "c",
127          "m",
128          "stdc++",
129        ]
130
131        deps += [ "//build/lite:ohos" ]
132        deps += [ "//build/lite:product" ]
133        deps += [ "//kernel/liteos_m:kernel" ]
134      }
135
136      # link target lib into bin
137      gen_bin_name = "gen_bin_${exe_bin}"
138      build_ext_component(gen_bin_name) {
139        exec_path = rebase_path(".")
140        src_elf = "${out_bin_path}/${exe_bin}.elf"
141        dest_bin = "${out_bin_path}/${exe_bin}.bin"
142        command = "arm-none-eabi-objcopy -O binary ${src_elf} ${dest_bin}"
143        deps = [ ":${exe_bin}" ]
144      }
145
146      burn_name = bin_file.burn_name
147
148      # copy out/<board_name>/<product_name>/bin/ to release bin
149      copy_burn_bin_name = "copy_${exe_bin}_to_relase_bin"
150      build_ext_component(copy_burn_bin_name) {
151        exec_path = rebase_path("${out_product_path}")
152        copy_dest = "./release_bin"
153        bin_name_ota = burn_name
154        command = "cp -rf ${out_bin_path}/${exe_bin}.bin ${copy_dest}/${bin_name_ota}.bin"
155        deps = [ ":${gen_bin_name}" ]
156        deps += [ ":init_burn_tools" ]
157      }
158
159      # sig exe bin to hash_sig bin
160      bin_sig = bin_file.signature
161      if (bin_sig == "true") {
162        gen_bin_name_sig = "gen_bin_${burn_name}_sig"
163        build_ext_component(gen_bin_name_sig) {
164          exec_path = rebase_path("pack_tools")
165          command = "./sig_bin.sh ${burn_name} ${out_product_path}"
166          deps = [ ":${copy_burn_bin_name}" ]
167        }
168      }
169
170      # if use copy signature bin
171      copy_bin_name = "copy_${exe_bin}_to_gui"
172      build_ext_component(copy_bin_name) {
173        exec_path = rebase_path("${out_product_path}")
174        print(" copy signature bin exec_path", exec_path)
175        deps = []
176        if (bin_sig == "true") {
177          copy_src = "./auto_build_tool/hash_sig"
178          bin_name_ota = "${burn_name}_sig"
179          deps += [ ":${gen_bin_name_sig}" ]
180        } else {
181          copy_src = "./release_bin"
182          bin_name_ota = burn_name
183          deps += [ ":${copy_burn_bin_name}" ]
184        }
185        copy_dst = "./write_flash_gui/ota_bin"
186        command = "cp -rf ${copy_src}/${bin_name_ota}.bin ${copy_dst}/${burn_name}.bin"
187      }
188    }
189  }
190
191  # generate file system bin from resources/ and sig or not sig before copy to write_flash_gui
192  foreach(fs_bin, fs_list) {
193    fs_enable = fs_bin.enable
194
195    if (fs_enable == "true") {
196      fs_name = fs_bin.fs_name
197
198      # generate fs bin to release bin
199      gen_fs_name = "genfs_${fs_name}"
200      fs_size = fs_bin.fs_size
201      fs_src = product_path + "/" + flash_partition_dir + "/" + fs_bin.fs_src
202      block_size = fs_bin.block_size
203      bsp_path = rebase_path("liteos_m") + "/sdk/bsp"
204      print("bsp_path:", bsp_path)
205      build_ext_component(gen_fs_name) {
206        exec_path = rebase_path("pack_tools")
207        command = "./genfs.sh ${block_size} ${fs_size} ${fs_src} ${out_product_path} ${fs_name} ${bsp_path}"
208        deps = [ ":init_burn_tools" ]
209      }
210
211      # sig fs bin to hash_sig bin
212      fs_sig = fs_bin.signature
213      if (fs_sig == "true") {
214        gen_fs_name_sig = "genfs_${fs_name}_sig"
215        build_ext_component(gen_fs_name_sig) {
216          exec_path = rebase_path("pack_tools")
217          command = "./sig_fs.sh ${fs_name} ${out_product_path}"
218          deps = [ ":${gen_fs_name}" ]
219        }
220      }
221
222      # if use copy signature bin
223      copy_fs_name = "copy_${fs_name}_to_gui"
224      build_ext_component(copy_fs_name) {
225        exec_path = rebase_path("${out_product_path}")
226        deps = []
227        if (fs_sig == "true") {
228          copy_src = "auto_build_tool/hash_sig"
229          fs_name_ota = "${fs_name}_sig"
230          deps += [ ":${gen_fs_name_sig}" ]
231        } else {
232          copy_src = "release_bin"
233          fs_name_ota = fs_name
234          deps += [ ":${gen_fs_name}" ]
235        }
236        command = "cp -rf ${copy_src}/${fs_name_ota}.bin ./write_flash_gui/ota_bin/${fs_name}.bin"
237      }
238    }
239  }
240
241  # generate bsp bin from bsp and sig or not sig before copy to write_flash_gui
242  foreach(bsp_bin, bsp_bin_list) {
243    bsp_bin_enable = bsp_bin.enable
244
245    if (bsp_bin_enable == "true") {
246      bsp_bin_name = bsp_bin.bsp_bin_name
247      burn_name = bsp_bin.burn_name
248
249      # copy ./liteos_m/sdk/bsp/out/<bsp_bin_name>/<bsp_bin_name>.bin to release bin
250      copy_burn_bin_name = "copy_${bsp_bin_name}_to_relase_bin"
251      build_ext_component(copy_burn_bin_name) {
252        exec_path = rebase_path(".")
253        bsp_out_bin_path = "liteos_m/sdk/bsp/out/${bsp_bin_name}"
254        copy_dest = "${out_product_path}/release_bin"
255        bin_name_ota = burn_name
256        command = "cp -rf ${bsp_out_bin_path}/${bsp_bin_name}.bin ${copy_dest}/${bin_name_ota}.bin"
257        deps = [ "liteos_m/sdk:build_sdk_into_lib" ]
258        deps += [ ":init_burn_tools" ]
259      }
260
261      # sig exe bin to hash_sig bin
262      bsp_bin_sig = bsp_bin.signature
263      if (bsp_bin_sig == "true") {
264        gen_bsp_bin_name_sig = "gen_bsp_bin_${burn_name}_sig"
265        build_ext_component(gen_bsp_bin_name_sig) {
266          exec_path = rebase_path("pack_tools")
267          command = "./sig_bin.sh ${burn_name} ${out_product_path}"
268          deps = [ ":${copy_burn_bin_name}" ]
269        }
270      }
271
272      # if use copy bsp signature bin
273      copy_bsp_bin_name = "copy_${bsp_bin_name}_to_gui"
274      build_ext_component(copy_bsp_bin_name) {
275        exec_path = rebase_path("${out_product_path}")
276        deps = []
277        if (bsp_bin_sig == "true") {
278          copy_src = "./auto_build_tool/hash_sig"
279          bsp_bin_name_ota = "${burn_name}_sig"
280          deps += [ ":${gen_bsp_bin_name_sig}" ]
281        } else {
282          copy_src = "release_bin"
283          bsp_bin_name_ota = burn_name
284          deps += [ ":${copy_burn_bin_name}" ]
285        }
286        command = "cp -rf ./${copy_src}/${bsp_bin_name_ota}.bin ./write_flash_gui/ota_bin/${bsp_bin_name_ota}.bin"
287      }
288    }
289  }
290
291  # pack write flash gui to write_flash_gui-<time>.tar.gz
292  update_product_yaml = "update_${product_name}_yaml"
293  build_ext_component(update_product_yaml) {
294    exec_path = rebase_path("${ohos_root_path}")
295    command = "cp -rf ${product_path}/${flash_partition_dir}/wifi_Download_cfg.yaml ${out_product_path}/write_flash_gui/"
296    deps = [ ":init_burn_tools" ]
297  }
298
299  # pack write flash gui to write_flash_gui-<time>.tar.gz
300  build_ext_component("pack_flash_gui") {
301    exec_path = rebase_path("pack_tools")
302    command =
303        "./pack_burn_tools.sh ${out_product_path} ${pack_burn} ${product_name}"
304    deps = [ ":${update_product_yaml}" ]
305
306    # bin configed from vendor/bestechnic/<product_name>/config.json
307    foreach(bin_file, bin_list) {
308      build_enable = bin_file.enable
309      if (build_enable == "true") {
310        exe_bin = "${bin_file.elf_name}_${board_name}"
311        copy_bin_name = "copy_${exe_bin}_to_gui"
312        deps += [ ":${copy_bin_name}" ]
313      }
314    }
315
316    # fs bin configed from vendor/bestechnic/<product_name>/config.json
317    foreach(fs_bin, fs_list) {
318      fs_enable = fs_bin.enable
319      if (fs_enable == "true") {
320        fs_name = fs_bin.fs_name
321        copy_fs_name = "copy_${fs_name}_to_gui"
322        if (fs_enable == "true") {
323          deps += [ ":${copy_fs_name}" ]
324        }
325      }
326    }
327
328    # bsp bin configed from vendor/bestechnic/<product_name>/config.json
329    foreach(bsp_bin, bsp_bin_list) {
330      bsp_bin_enable = bsp_bin.enable
331      if (bsp_bin_enable == "true") {
332        bsp_bin_name = bsp_bin.bsp_bin_name
333        copy_bsp_bin_name = "copy_${bsp_bin_name}_to_gui"
334        deps += [ ":${copy_bsp_bin_name}" ]
335      }
336    }
337  }
338}
339