Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'''
Select and then open the correct channel to talk to the board.
For the bootloader, this means opening a serial port. For JTAG, not much
needs to be done.
'''
# Verify both openocd and jlink are not set.
if getattr(self.args, 'jlink', False) and getattr(self.args, 'openocd', False):
raise TockLoaderException('Cannot use both --jlink and --openocd options')
# Get an object that allows talking to the board.
if hasattr(self.args, 'jlink') and self.args.jlink:
self.channel = JLinkExe(self.args)
elif hasattr(self.args, 'openocd') and self.args.openocd:
self.channel = OpenOCD(self.args)
else:
self.channel = BootloaderSerial(self.args)
# And make sure the channel is open (e.g. open a serial port).
self.channel.open_link_to_board()