• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/exec.gni")
18
19# Executable wrapper that allows the 2nd stage bootloader to strip link deps.
20template("pico_executable") {
21  if (defined(invoker.is_boot_stage2) && invoker.is_boot_stage2) {
22    executable(target_name) {
23      forward_variables_from(invoker, "*")
24
25      # Link deps pulls in Pigweed things that don't fit in the 2nd stage
26      # bootloader.
27      deps -= [ "$dir_pw_build:link_deps" ]
28    }
29  } else {
30    _uf2_name = "${target_name}.uf2"
31    _elf_name = "${target_name}.elf"
32    executable(_elf_name) {
33      forward_variables_from(invoker, "*")
34    }
35
36    pw_exec(_uf2_name) {
37      _elf2uf2_target = "$dir_pw_third_party/pico_sdk/src:elf2uf2($dir_pigweed/targets/host:host_clang_debug)"
38      _uf2_out_path = "${target_out_dir}/${_uf2_name}"
39      deps = [
40        ":${_elf_name}",
41        _elf2uf2_target,
42      ]
43      program = "<TARGET_FILE(${_elf2uf2_target})>"
44      args = [
45        "<TARGET_FILE(:${_elf_name})>",
46        rebase_path(_uf2_out_path, root_build_dir),
47      ]
48      outputs = [ _uf2_out_path ]
49    }
50    group(target_name) {
51      deps = [ ":${_uf2_name}" ]
52    }
53  }
54}
55