process_elf.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright 2024 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://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,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import objcopy
  15. import pebble_sdk_gcc
  16. # TODO: PBL-33841 Make this a feature
  17. def generate_bin_file(task_gen, bin_type, elf_file, has_pkjs, has_worker):
  18. """
  19. Generate bin file by injecting metadata from elf file and resources file
  20. :param task_gen: the task generator instance
  21. :param bin_type: the type of binary being built (app, worker, lib)
  22. :param elf_file: the path to the compiled elf file
  23. :param has_pkjs: boolean for whether the build contains PebbleKit JS files
  24. :param has_worker: boolean for whether the build contains a worker binary
  25. :return: the modified binary file with injected metadata
  26. """
  27. platform_build_node = task_gen.bld.path.get_bld().find_node(task_gen.bld.env.BUILD_DIR)
  28. packaged_files = [elf_file]
  29. resources_file = None
  30. if bin_type != 'worker':
  31. resources_file = platform_build_node.find_or_declare('app_resources.pbpack')
  32. packaged_files.append(resources_file)
  33. raw_bin_file = platform_build_node.make_node('pebble-{}.raw.bin'.format(bin_type))
  34. bin_file = platform_build_node.make_node('pebble-{}.bin'.format(bin_type))
  35. task_gen.bld(rule=objcopy.objcopy_bin, source=elf_file, target=raw_bin_file)
  36. pebble_sdk_gcc.gen_inject_metadata_rule(task_gen.bld,
  37. src_bin_file=raw_bin_file,
  38. dst_bin_file=bin_file,
  39. elf_file=elf_file,
  40. resource_file=resources_file,
  41. timestamp=task_gen.bld.env.TIMESTAMP,
  42. has_pkjs=has_pkjs,
  43. has_worker=has_worker)
  44. return bin_file