Lines Matching full:self
32 def __init__(self, cfg, pre_init=None, reset_halt_cmd=DEFAULT_OPENOCD_RESET_HALT_CMD, argument
58 self.openocd_config = config
65 if self.openocd_config is not None:
66 for i in self.openocd_config:
74 self.openocd_cmd = [cfg.openocd or 'openocd'] + search_args
77 self.elf_name = Path(cfg.elf_file).as_posix() if cfg.elf_file else None
78 self.pre_init = pre_init or []
79 self.reset_halt_cmd = reset_halt_cmd
80 self.pre_load = pre_load or []
81 self.load_cmd = load_cmd
82 self.verify_cmd = verify_cmd
83 self.post_verify = post_verify or []
84 self.do_verify = do_verify or False
85 self.do_verify_only = do_verify_only or False
86 self.tcl_port = tcl_port
87 self.telnet_port = telnet_port
88 self.gdb_port = gdb_port
89 self.gdb_client_port = gdb_client_port
90 self.gdb_cmd = [cfg.gdb] if cfg.gdb else None
91 self.tui_arg = ['-tui'] if tui else []
92 self.halt_arg = [] if no_halt else ['-c halt']
93 self.init_arg = [] if no_init else ['-c init']
94 self.targets_arg = [] if no_targets else ['-c targets']
95 self.serial = ['-c set _ZEPHYR_BOARD_SERIAL ' + serial] if serial else []
96 self.use_elf = use_elf
97 self.gdb_init = gdb_init
98 self.load_arg = [] if no_load else ['-ex', 'load']
99 self.target_handle = target_handle
185 def print_gdbserver_message(self): argument
186 if not self.thread_info_enabled:
188 elif self.supports_thread_info():
192 self.logger.info('OpenOCD GDB server running on port '
193 f'{self.gdb_port}{thread_msg}')
196 def to_num(self, number): argument
208 def read_version(self): argument
209 self.require(self.openocd_cmd[0])
212 out = self.check_output([self.openocd_cmd[0], '--version'],
218 return [self.to_num(i) for i in version]
220 def supports_thread_info(self): argument
222 (major, minor, rev) = self.read_version()
225 def do_run(self, command, **kwargs): argument
226 self.require(self.openocd_cmd[0])
231 self.cfg_cmd = []
232 if self.openocd_config is not None:
233 for i in self.openocd_config:
234 self.cfg_cmd.append('-f')
235 self.cfg_cmd.append(i)
237 if command == 'flash' and self.use_elf:
238 self.do_flash_elf(**kwargs)
240 self.do_flash(**kwargs)
242 self.do_attach_debug(command, **kwargs)
244 self.do_load(**kwargs)
246 self.do_debugserver(**kwargs)
248 def do_flash(self, **kwargs): argument
249 self.ensure_output('hex')
250 if self.load_cmd is None:
252 if self.verify_cmd is None:
257 hex_name = Path(self.cfg.hex_file).as_posix()
259 self.logger.info('Flashing file: {}'.format(hex_name))
264 for i in self.pre_init:
268 for i in self.pre_load:
272 for i in self.post_verify:
277 if not self.do_verify_only:
278 load_image = ['-c', self.reset_halt_cmd,
279 '-c', self.load_cmd + ' ' + hex_name]
282 if self.do_verify or self.do_verify_only:
283 verify_image = ['-c', self.reset_halt_cmd,
284 '-c', self.verify_cmd + ' ' + hex_name]
286 cmd = (self.openocd_cmd + self.serial + self.cfg_cmd +
287 pre_init_cmd + self.init_arg + self.targets_arg +
293 self.check_call(cmd)
295 def do_flash_elf(self, **kwargs): argument
296 if self.elf_name is None:
301 with open(self.elf_name, 'rb') as f:
305 for i in self.pre_init:
311 if not self.do_verify_only:
312 for i in self.pre_load:
315 load_image = ['-c', 'load_image ' + self.elf_name]
319 if self.do_verify or self.do_verify_only:
320 verify_image = ['-c', 'verify_image ' + self.elf_name]
321 for i in self.post_verify:
328 cmd = (self.openocd_cmd + self.serial + self.cfg_cmd +
329 pre_init_cmd + self.init_arg + self.targets_arg +
330 pre_load_cmd + ['-c', self.reset_halt_cmd] +
335 self.check_call(cmd)
337 def do_attach_debug(self, command, **kwargs): argument
338 if self.gdb_cmd is None:
340 if self.elf_name is None:
344 for i in self.pre_init:
348 if self.thread_info_enabled and self.supports_thread_info():
350 rtos_command = '${} configure -rtos Zephyr'.format(self.target_handle)
353 server_cmd = (self.openocd_cmd + self.serial + self.cfg_cmd +
354 ['-c', 'tcl_port {}'.format(self.tcl_port),
355 '-c', 'telnet_port {}'.format(self.telnet_port),
356 '-c', 'gdb_port {}'.format(self.gdb_port)] +
357 pre_init_cmd + self.init_arg + self.targets_arg +
358 self.halt_arg)
359 gdb_cmd = (self.gdb_cmd + self.tui_arg +
360 ['-ex', 'target extended-remote :{}'.format(self.gdb_client_port),
361 self.elf_name])
363 gdb_cmd.extend(self.load_arg)
364 if self.gdb_init is not None:
365 for i in self.gdb_init:
369 self.require(gdb_cmd[0])
370 self.print_gdbserver_message()
371 self.run_server_and_client(server_cmd, gdb_cmd)
373 def do_debugserver(self, **kwargs): argument
375 for i in self.pre_init:
379 if self.thread_info_enabled and self.supports_thread_info():
381 rtos_command = '${} configure -rtos Zephyr'.format(self.target_handle)
384 cmd = (self.openocd_cmd + self.cfg_cmd +
385 ['-c', 'tcl_port {}'.format(self.tcl_port),
386 '-c', 'telnet_port {}'.format(self.telnet_port),
387 '-c', 'gdb_port {}'.format(self.gdb_port)] +
388 pre_init_cmd + self.init_arg + self.targets_arg +
389 ['-c', self.reset_halt_cmd])
390 self.print_gdbserver_message()
391 self.check_call(cmd)