コード例 #1
0
ファイル: deploy.py プロジェクト: makerdiary/OpenSK
 def install_tab_file(self, tab_filename):
   assert self.args.application
   info("Installing Tock application {}".format(self.args.application))
   board_props = SUPPORTED_BOARDS[self.args.board]
   args = copy.copy(self.tockloader_default_args)
   setattr(args, "app_address", board_props.app_address)
   setattr(args, "erase", self.args.clear_apps)
   setattr(args, "make", False)
   setattr(args, "no_replace", False)
   tock = loader.TockLoader(args)
   tock.open()
   tabs = [tab.TAB(tab_filename)]
   try:
     tock.install(tabs, replace="yes", erase=args.erase)
   except TockLoaderException as e:
     fatal("Couldn't install Tock application {}: {}".format(
         self.args.application, str(e)))
コード例 #2
0
ファイル: deploy.py プロジェクト: makerdiary/OpenSK
  def create_hex_file(self, dest_file):
    # We produce an intelhex file with everything in it
    # https://en.wikipedia.org/wiki/Intel_HEX
    # pylint: disable=g-import-not-at-top,import-outside-toplevel
    import intelhex
    board_props = SUPPORTED_BOARDS[self.args.board]
    final_hex = intelhex.IntelHex()

    if self.args.tockos:
      # Process kernel
      kernel_path = os.path.join("third_party", "tock", "target",
                                 board_props.arch, "release",
                                 "{}.bin".format(self.args.board))
      with open(kernel_path, "rb") as kernel:
        kern_hex = intelhex.IntelHex()
        kern_hex.frombytes(kernel.read(), offset=board_props.kernel_address)
        final_hex.merge(kern_hex, overlap="error")

    if self.args.application:
      # Add padding
      if board_props.padding_address:
        padding_hex = intelhex.IntelHex()
        padding_hex.frombytes(
            self.get_padding(), offset=board_props.padding_address)
        final_hex.merge(padding_hex, overlap="error")

      # Now we can add the application from the TAB file
      app_tab_path = "target/tab/{}.tab".format(self.args.application)
      assert os.path.exists(app_tab_path)
      app_tab = tab.TAB(app_tab_path)
      if board_props.arch not in app_tab.get_supported_architectures():
        fatal(("It seems that the TAB file was not produced for the "
               "architecture {}".format(board_props.arch)))
      app_hex = intelhex.IntelHex()
      app_hex.frombytes(
          app_tab.extract_app(board_props.arch).get_binary(
              board_props.app_address),
          offset=board_props.app_address)
      final_hex.merge(app_hex)
    info("Generating all-merged HEX file: {}".format(dest_file))
    final_hex.tofile(dest_file, format="hex")
コード例 #3
0
 def install_elf_file(self, elf_path):
     assert self.args.application
     package_parameter = "-n"
     elf2tab_ver = self.checked_command_output(["elf2tab", "--version"
                                                ]).split(' ', maxsplit=1)[1]
     # Starting from v0.5.0-dev the parameter changed.
     # Current pyblished crate is 0.4.0 but we don't want developers
     # running the HEAD from github to be stuck
     if "0.5.0-dev" in elf2tab_ver:
         package_parameter = "--package-name"
     os.makedirs(self.tab_folder, exist_ok=True)
     tab_filename = os.path.join(self.tab_folder,
                                 "{}.tab".format(self.args.application))
     shutil.copyfile(elf_path, self.target_elf_filename)
     self.checked_command_output([
         "elf2tab", package_parameter, self.args.application, "-o",
         tab_filename, self.target_elf_filename,
         "--stack={}".format(STACK_SIZE),
         "--app-heap={}".format(APP_HEAP_SIZE), "--kernel-heap=1024",
         "--protected-region-size=64"
     ])
     self.install_padding()
     if not self.args.dfu:
         info("Installing Tock application {}".format(
             self.args.application))
         args = copy.copy(self.tockloader_default_args)
         setattr(args, "app_address", 0x40000)
         setattr(args, "erase", self.args.clear_apps)
         setattr(args, "make", False)
         setattr(args, "no_replace", False)
         tock = tockloader.TockLoader(args)
         tock.open(args)
         tabs = [tab.TAB(tab_filename)]
         try:
             tock.install(tabs, replace="yes", erase=args.erase)
         except TockLoaderException as e:
             fatal("Couldn't install Tock application {}: {}".format(
                 self.args.application, str(e)))
     else:
         self.padding_to_hex()
         self.app_to_hex()