How to use the tockloader.exceptions.TockLoaderException function in tockloader

To help you get started, we’ve selected a few tockloader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tock / tockloader / tockloader / jlinkexe.py View on Github external
print(subp.stdout.decode('utf-8'))
				if subp.stderr:
					print(subp.stderr.decode('utf-8'))

			p = subprocess.run(jlink_command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			if p.returncode != 0:
				print('ERROR: JTAG returned with error code ' + str(p.returncode))
				print_output(p)
				raise TockLoaderException('JTAG error')
			elif self.args.debug:
				print_output(p)

			# check that there was a JTAG programmer and that it found a device
			stdout = p.stdout.decode('utf-8')
			if 'USB...FAILED' in stdout:
				raise TockLoaderException('ERROR: Cannot find JLink hardware. Is USB attached?')
			if 'Can not connect to target.' in stdout:
				raise TockLoaderException('ERROR: Cannot find device. Is JTAG connected?')
			if 'Error while programming flash' in stdout:
				raise TockLoaderException('ERROR: Problem flashing.')

			if write == False:
				# Wanted to read binary, so lets pull that
				temp_bin.seek(0, 0)
				return temp_bin.read()
github tock / tockloader / tockloader / openocd.py View on Github external
def print_output (subp):
			response = ''
			if subp.stdout:
				response += subp.stdout.decode('utf-8')
			if subp.stderr:
				response += subp.stderr.decode('utf-8')
			logging.debug(response)
			return response

		p = subprocess.run(shlex.split(openocd_command), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		if p.returncode != 0:
			logging.error('ERROR: openocd returned with error code ' + str(p.returncode))
			out = print_output(p)
			if 'Can\'t find board/' in out:
				raise TockLoaderException('ERROR: Cannot find the board configuration file. \
You may need to update OpenOCD to the version in latest git master.')
			raise TockLoaderException('openocd error')
		elif self.args.debug:
			print_output(p)

		# check that there was a JTAG programmer and that it found a device
		stdout = p.stdout.decode('utf-8')
		if 'Error: No J-Link device found.' in stdout:
			raise TockLoaderException('ERROR: Cannot find hardware. Is USB attached?')

		if write == False:
			# Wanted to read binary, so lets pull that
			temp_bin.seek(0, 0)
			return temp_bin.read()
github tock / tockloader / tockloader / openocd.py View on Github external
response = ''
			if subp.stdout:
				response += subp.stdout.decode('utf-8')
			if subp.stderr:
				response += subp.stderr.decode('utf-8')
			logging.debug(response)
			return response

		p = subprocess.run(shlex.split(openocd_command), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		if p.returncode != 0:
			logging.error('ERROR: openocd returned with error code ' + str(p.returncode))
			out = print_output(p)
			if 'Can\'t find board/' in out:
				raise TockLoaderException('ERROR: Cannot find the board configuration file. \
You may need to update OpenOCD to the version in latest git master.')
			raise TockLoaderException('openocd error')
		elif self.args.debug:
			print_output(p)

		# check that there was a JTAG programmer and that it found a device
		stdout = p.stdout.decode('utf-8')
		if 'Error: No J-Link device found.' in stdout:
			raise TockLoaderException('ERROR: Cannot find hardware. Is USB attached?')

		if write == False:
			# Wanted to read binary, so lets pull that
			temp_bin.seek(0, 0)
			return temp_bin.read()
github tock / tockloader / tockloader / tockloader.py View on Github external
def set_attribute (self, key, value):
		'''
		Change an attribute stored on the board.
		'''
		# Do some checking
		if len(key.encode('utf-8')) > 8:
			raise TockLoaderException('Key is too long. Must be 8 bytes or fewer.')
		if len(value.encode('utf-8')) > 55:
			raise TockLoaderException('Value is too long. Must be 55 bytes or fewer.')

		# Enter bootloader mode to get things started
		with self._start_communication_with_board():

			if not self._bootloader_is_present():
				raise TockLoaderException('No bootloader found! That means there is nowhere for attributes to go.')

			# Create the buffer to write as the attribute
			out = bytes([])
			# Add key
			out += key.encode('utf-8')
			out += bytes([0] * (8-len(out)))
			# Add length
			out += bytes([len(value.encode('utf-8'))])
			# Add value
			out += value.encode('utf-8')

			# Find if this attribute key already exists
			open_index = -1
			for index, attribute in enumerate(self.channel.get_all_attributes()):
				if attribute:
					if attribute['key'] == key:
github tock / tockloader / tockloader / bootloader_serial.py View on Github external
def get_attribute (self, index):
		message = struct.pack('
github tock / tockloader / tockloader / tab.py View on Github external
binary = self.tab.extractfile(binary_tarinfo).read()

			# First get the TBF header from the correct binary in the TAB
			tbfh = TBFHeader(binary)

			if tbfh.is_valid():
				# Check that total size actually matches the binary that we got.
				if tbfh.get_app_size() < len(binary):
					# It's fine if the binary is smaller, but the binary cannot be
					# longer than the amount of reserved space (`total_size` in the
					# TBF header) for the app.
					raise TockLoaderException('Invalid TAB, the app binary is longer than its defined total_size')

				tbfs.append((tbfh, binary[tbfh.get_size_before_app():]))
			else:
				raise TockLoaderException('Invalid TBF found in app in TAB')

		return TabApp(tbfs)
github tock / tockloader / tockloader / openocd.py View on Github external
for attribute in attributes:
			if attribute and attribute['key'] == 'board' and self.board == None:
				self.board = attribute['value']
			if attribute and attribute['key'] == 'arch' and self.arch == None:
				self.arch = attribute['value']
			if attribute and attribute['key'] == 'openocd':
				self.openocd_board = attribute['value']
			if attribute and attribute['key'] == 'pagesize' and self.page_size == 0:
				self.page_size = attribute['value']

		# We might need to fill in if we only got a "board" attribute.
		self._configure_from_known_boards()

		# Check that we learned what we needed to learn.
		if self.board == None or self.arch == None or self.openocd_board == 'cortex-m0' or self.page_size == 0:
			raise TockLoaderException('Could not determine the current board or arch or openocd board name')
github tock / tockloader / tockloader / bootloader_serial.py View on Github external
'''
		Get the bootloader to compute a CRC.
		'''
		message = struct.pack('
github tock / tockloader / tockloader / tockloader.py View on Github external
def set_attribute (self, key, value):
		'''
		Change an attribute stored on the board.
		'''
		# Do some checking
		if len(key.encode('utf-8')) > 8:
			raise TockLoaderException('Key is too long. Must be 8 bytes or fewer.')
		if len(value.encode('utf-8')) > 55:
			raise TockLoaderException('Value is too long. Must be 55 bytes or fewer.')

		# Enter bootloader mode to get things started
		with self._start_communication_with_board():

			if not self._bootloader_is_present():
				raise TockLoaderException('No bootloader found! That means there is nowhere for attributes to go.')

			# Create the buffer to write as the attribute
			out = bytes([])
			# Add key
			out += key.encode('utf-8')
			out += bytes([0] * (8-len(out)))
			# Add length
			out += bytes([len(value.encode('utf-8'))])