def flash(self, elf_file): """ Flash firmware """ try: ret_value = 0 elf_path = common.abspath(elf_file) LOGGER.info('Creating hex path from %s', elf_path) hex_file = tempfile.NamedTemporaryFile(suffix='.hex') hex_path = hex_file.name LOGGER.info('Created hex path %s', hex_path) # creating hex file to_hex_command = 'objcopy -I elf32-big -O ihex {elf} {hex}' cmd = to_hex_command.format(elf=elf_path, hex=hex_path) ret_value = self._call_cmd(cmd) LOGGER.info('To hex conversion ret value : %d', ret_value) # getting flash addr address = get_elf_load_addr(elf_path) # Flashing flash_cmd = self.FLASH.format(baudrate=self.baud, hex=hex_path, addr=address) cmd = self.CC2538BSL.format(port=self.port, cmd=flash_cmd) ret_value += self._call_cmd(cmd) LOGGER.info('Flashing ret value : %d', ret_value) # removing temporary hex file hex_file.close() return ret_value except IOError as err: LOGGER.error('%s', err) return 1
def flash(): """ flash node function """ board_cfg = board_config.BoardConfig() firmware = os.getenv('FW') opts = _setup_parser(_FLASH, board_cfg) control_node = opts.cn if hasattr(opts, 'cn') else False node = _get_node(board_cfg, control_node) if firmware is not None and not control_node: if firmware == 'idle': firmware = node.FW_IDLE if firmware == 'autotest': firmware = node.FW_AUTOTEST else: firmware = opts.firmware if firmware is None: ret = -2 _print_result(ret, _FLASH) return ret if node.programmer is None: ret = -1 else: try: firmware_path = common.abspath(firmware) except IOError as err: print(err) return 1 if not opts.quiet: node.programmer.out = None ret = node.flash(firmware_path, opts.bin, opts.offset) _print_result(ret, _FLASH, node.TYPE) return ret
def flash(self, elf_file): """ Flash firmware """ try: ret_value = 0 elf_path = common.abspath(elf_file) LOGGER.info('Creating bin path from %s', elf_path) bin_file = tempfile.NamedTemporaryFile(suffix='.bin') bin_path = bin_file.name LOGGER.info('Created bin path %s', bin_path) # creating hex file to_bin_command = 'objcopy -I elf32-big -O binary {elf} {bin}' cmd = to_bin_command.format(elf=elf_path, bin=bin_path) ret_value = self._call_cmd(cmd) LOGGER.info('To bin conversion ret value : %d', ret_value) # Flashing flash_cmd = self.FLASH.format(bin=bin_path) cmd = self.EDBG.format(cmd=flash_cmd) ret_value += self._call_cmd(cmd) LOGGER.info('Flashing ret value : %d', ret_value) # removing temporary bin file bin_file.close() return ret_value except IOError as err: LOGGER.error('%s', err) return 1
def flash(self, fw_file, binary=False, offset=0): """ Flash firmware """ try: ret_value = 0 fw_path = common.abspath(fw_file) if not binary: LOGGER.info('Creating bin file from %s', fw_path) bin_file = tempfile.NamedTemporaryFile(suffix='.bin') bin_path = bin_file.name LOGGER.info('Created bin file in %s', bin_path) # creating hex file to_bin_command = 'objcopy -I elf32-big -O binary {elf} {bin}' cmd = to_bin_command.format(elf=fw_path, bin=bin_path) ret_value = self._call_cmd(cmd) LOGGER.info('To bin conversion ret value : %d', ret_value) fw_path = bin_path # Ensure offset is 0 with elf firmware offset = 0 # Flashing flash_cmd = self.FLASH.format(bin=fw_path, offset=hex(offset)) cmd = self.EDBG.format(cmd=flash_cmd) ret_value += self._call_cmd(cmd) LOGGER.info('Flashing ret value : %d', ret_value) if not binary: # removing temporary bin file bin_file.close() return ret_value except IOError as err: LOGGER.error('%s', err) return 1
def _check_debug(self, board_class): if (not hasattr(board_class, 'debug_stop') or # no debug # Only openocd debug tested here (arm) not hasattr(board_class, 'OPENOCD_CFG_FILE')): return firmware = abspath(board_class.FW_AUTOTEST) gdb_cmd = [ 'gdb', '-ex', 'set confirm off', '-ex', 'target remote localhost:3333', '-ex', 'monitor reset halt', '-ex', 'monitor flash write_image erase %s' % firmware, '-ex', 'monitor reset init', '-ex', 'monitor reset run', '-ex', 'quit', ] # Flash idle firmware ret = self._flash() self.assertEqual(0, ret.json['ret']) # idle firmware, there should be no reply self._check_node_echo(echo=False) # Start debugger ret = self.server.put('/open/debug/start') self.assertEqual(0, ret.json['ret']) # Flash autotest firmware ret = subprocess.call(gdb_cmd, stderr=subprocess.STDOUT) self.assertEqual(0, ret) time.sleep(1) # Autotest fw should be running self._check_node_echo(echo=True) # Flash idle firmware should fail ret = self._flash() self.assertNotEqual(0, ret.json['ret']) # No flash, Autotest fw should be still running self._check_node_echo(echo=True) # Stop debugger ret = self.server.put('/open/debug/stop') self.assertEqual(0, ret.json['ret']) # Make sure the node can be reflashed after debug session is done time.sleep(1) ret = self._flash() self.assertEqual(0, ret.json['ret'])
def flash(self, hex_file): """ Flash firmware """ try: hex_path = common.abspath(hex_file) return self._call_cmd(self.FLASH.format(hex_path)) except IOError as err: LOGGER.error('%s', err) return 1
def flash(self, fw_file, binary=False, offset=0): """ Flash firmware """ try: path = common.abspath(fw_file) if binary: return self._call_cmd(self.FLASH_BIN.format(path, hex(offset))) return self._call_cmd(self.FLASH.format(path)) except IOError as err: LOGGER.error('%s', err) return 1
def _check_debug(self, board_class): if not hasattr(board_class, 'debug_stop'): return 0 # no debug if not hasattr(board_class, 'OPENOCD_CFG_FILE'): return 0 # Only openocd debug tested here (arm) firmware = abspath(board_class.FW_AUTOTEST) gdb_cmd = [ 'gdb', '-ex', 'set confirm off', '-ex', 'target remote localhost:3333', '-ex', 'monitor reset halt', '-ex', 'monitor flash write_image erase %s' % firmware, '-ex', 'monitor reset init', '-ex', 'monitor reset run', '-ex', 'quit', ] # Flash idle firmware ret = self._flash(board_class.FW_IDLE) self.assertEquals(0, ret.json['ret']) # idle firmware, there should be no reply self._check_node_echo(echo=False) # Start debugger ret = self.server.put('/open/debug/start') self.assertEquals(0, ret.json['ret']) # Flash autotest firmware ret = subprocess.call(gdb_cmd, stderr=subprocess.STDOUT) self.assertEquals(0, ret) time.sleep(1) # Autotest fw should be running self._check_node_echo(echo=True) # Flash idle firmware should fail ret = self._flash(board_class.FW_IDLE) self.assertNotEquals(0, ret.json['ret']) # No flash, Autotest fw should be still be running self._check_node_echo(echo=True) # Stop debugger ret = self.server.put('/open/debug/stop') self.assertEquals(0, ret.json['ret'])
def _config(config_file, opts=()): """Return config options for `config_file` and `opts`. >>> OpenOCD._config('/dev/null') '-f "/dev/null"' >>> OpenOCD._config('/dev/null', ['target/stm32.cfg']) '-f "/dev/null" -f "target/stm32.cfg"' # Abspath >>> OpenOCD._config('gateway_code/static/iot-lab.cfg') ... # doctest: +ELLIPSIS '-f "/.../gateway_code/static/iot-lab.cfg"' """ cfg_file = common.abspath(config_file) opts = [cfg_file] + list(opts) return ' '.join((f'-f "{opt}"' for opt in opts))
def _config(config_file, opts=()): """Return config options for `config_file` and `opts`. >>> OpenOCD._config('/dev/null') '-f "/dev/null"' >>> OpenOCD._config('/dev/null', ['target/stm32.cfg']) '-f "/dev/null" -f "target/stm32.cfg"' # Abspath >>> OpenOCD._config('gateway_code/static/iot-lab-m3.cfg') ... # doctest: +ELLIPSIS '-f "/.../gateway_code/static/iot-lab-m3.cfg"' """ cfg_file = common.abspath(config_file) opts = [cfg_file] + list(opts) opts = ('-f "%s"' % opt for opt in opts) return ' '.join(opts)
def flash(self, elf_file): """ Flash firmware """ try: elf_path = common.abspath(elf_file) LOGGER.info('Creating hex path from %s', elf_path) hex_file = tempfile.NamedTemporaryFile(suffix='.hex') hex_path = hex_file.name LOGGER.info('Created hex path %s', hex_path) # creating hex file to_hex_command = 'objcopy -I elf32-big -O ihex {elf} {hex}' cmd = to_hex_command.format(elf=elf_path, hex=hex_path) ret_value = self._call_cmd(cmd) LOGGER.info('To hex conversion ret value : %d', ret_value) return self._call_cmd(self.FLASH.format(hex_path)) except IOError as err: LOGGER.error('%s', err) return 1