1# Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 2# All rights reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import("//build/lite/config/component/lite_component.gni") 17 18declare_args() { 19 disasm_unstripped_version = false 20} 21 22template("binary") { 23 assert(defined(invoker.deps), 24 "Need sources in $target_name listing the idl files.") 25 26 build_ext_component(target_name) { 27 deps = invoker.deps 28 29 if (defined(invoker.source)) { 30 source = invoker.source 31 } else { 32 source = deps[0] 33 } 34 35 print("ohos_build_type=${ohos_build_type}") 36 print("target_name = ${target_name}") 37 print(source) 38 print(compile_prefix) 39 40 41 elf = get_label_info(source, "name") 42 print("elf: ${elf} ") 43 print("target_out_dir: ${target_out_dir}") 44 print("root_out_dir: ${root_out_dir}") 45 print("name: ${name}") 46 out_dir = get_path_info(target_out_dir, "out_dir") 47 print("out_dir: ${out_dir}") 48 print("ohos_current_strip_command: ${ohos_current_strip_command}") 49 50 if (defined(invoker.output)) { 51 bin = invoker.output 52 } else { 53 bin = elf + ".bin" 54 } 55 56 print("bin: ${bin}") 57 58 exec_path = rebase_path(root_out_dir + "/bin") 59 print("root_out_dir: ${root_out_dir}") 60 print("exec_path: ${exec_path}") 61 62 if (disasm_unstripped_version && defined(ohos_current_strip_command) && ("" != ohos_current_strip_command)) { 63 unstripped_prefix = "/unstripped" 64 } else { 65 unstripped_prefix = "" 66 } 67 unstripped_prefix = rebase_path(root_out_dir + unstripped_prefix + "/bin", exec_path) 68 print("unstripped_prefix: ${unstripped_prefix}") 69 70 objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix" 71 objdump = "${compile_prefix}objdump$toolchain_cmd_suffix" 72 73 command = "$objcopy -O binary ${elf} ${bin}" 74 command += " && sh -c '$objdump -t $unstripped_prefix/$elf | sort > $elf.sym.sorted'" 75 command += " && sh -c '$objdump -xdSC $unstripped_prefix/$elf > $elf.S'" 76 print("command: \"$command\"") 77 } 78} 79 80template("b91_firmware") { 81 executable("${target_name}_elf") { 82 forward_variables_from(invoker, "*") 83 84 explicit_libs_full = [] 85 if (defined(explicit_libs)) { 86 foreach(lib, explicit_libs) { 87 explicit_libs_full += ["-l$lib"] 88 } 89 } 90 91 if (!defined(ldflags)) { 92 ldflags = [] 93 } 94 95 ldflags += [ 96 "-z","muldefs", 97 "-Wl,-Map=" + rebase_path("$root_out_dir/$target_name.map"), 98 "-L" + rebase_path("$root_out_dir/libs"), 99 ] 100 101 ldflags += ["-Wl,--whole-archive"] + explicit_libs_full + ["-Wl,--no-whole-archive"] 102 103 configs += [ 104 "//kernel/liteos_m:public", 105 "//kernel/liteos_m:los_config", 106 ] 107 108 output_name = invoker.target_name 109 } 110 111 binary("${target_name}_bin") { 112 deps = [":${invoker.target_name}_elf"] 113 source = invoker.target_name 114 } 115 116 group(target_name) { 117 deps = [":${invoker.target_name}_bin"] 118 } 119} 120