Skip to content

Commit

Permalink
Update minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
ChipWhisperer-Bot committed Dec 3, 2024
1 parent d24b650 commit 55b3206
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 105 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ Stuck? If you need a hand, there are a few places you can ask for help:
---

ChipWhisperer is a trademark of NewAE Technology Inc., registered in the US, Europe, and China.

27 changes: 7 additions & 20 deletions chipwhisperer/capture/scopes/cwhardware/ChipWhispererSAM3Update.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,12 @@ def program(self, port, fw_path=None, hardware_type=None, bypass_warning=False):
'cwlite',
'cwnano',
'cw305',
'cw310',
'cw340',
'cw1200',
'cwbergen',
'cwhusky'
'cwhusky',
'cwhuskyplus'
]


Expand All @@ -241,26 +244,10 @@ def program(self, port, fw_path=None, hardware_type=None, bypass_warning=False):
message = 'Invalid hardware type {}, needs to be one of: ({})'
raise TypeError(message.format(hardware_type, ', '.join(type_whitelist)))
else:
if hardware_type == 'cwlite':
from ....hardware.firmware.cwlite import getsome
name = 'SAM3U_CW1173.bin'
elif hardware_type == 'cwnano':
from ....hardware.firmware.cwnano import getsome
name = 'SAM3U_CWNANO.bin'
elif hardware_type == 'cw305':
from ....hardware.firmware.cw305 import getsome
name = 'SAM3U_CW305.bin'
elif hardware_type == 'cw1200':
from ....hardware.firmware.cw1200 import getsome
name = 'CW1200_SAM3UFW.bin'
elif hardware_type == 'cwbergen':
from ....hardware.firmware.cwbergen import getsome
name = 'CW310.bin'
elif hardware_type == 'cwhusky':
from ....hardware.firmware.cwhusky import getsome
name = 'Husky.bin'
from ....hardware.firmware.open_fw import mcufw
self.logfunc('Loading {} firmware...'.format(hardware_type))
fw_data = getsome(name).read()
fw_data = mcufw(hardware_type, False)
name = "{}/mcufw.bin".format(hardware_type)

if fw_path:
self.logfunc("Opening firmware...")
Expand Down
15 changes: 9 additions & 6 deletions chipwhisperer/capture/targets/CW305.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class CW305(TargetTemplate, ChipWhispererCommonInterface):


def _getFWPy(self):
from ...hardware.firmware.cw305 import fwver
return fwver
from ...hardware.firmware.open_fw import fwver
return fwver("cw305")

def __init__(self):
import chipwhisperer as cw
Expand Down Expand Up @@ -477,7 +477,8 @@ def _con(self, scope=None, bsfile=None, force=False, fpga_id=None, defines_files
if self.fpga.isFPGAProgrammed() == False or force:
if bsfile is None:
if not fpga_id is None:
from chipwhisperer.hardware.firmware.cw305 import getsome
from ...hardware.firmware.open_fw import getsome_generator
getsome = getsome_generator("cw305")
if self.target_name == 'AES':
bsdata = getsome(f"AES_{fpga_id}.bit")
elif self.target_name == 'Cryptech ecdsa256-v1 pmul':
Expand Down Expand Up @@ -505,7 +506,7 @@ def _con(self, scope=None, bsfile=None, force=False, fpga_id=None, defines_files
target_logger.warning(("FPGA Bitstream not configured or '%s' not a file." % str(bsfile)))
else:
starttime = datetime.now()
status = self.fpga.FPGAProgram(open(bsfile, "rb"), exceptOnDoneFailure=False, prog_speed=prog_speed)
status = self.fpga.FPGAProgram(bsfile, exceptOnDoneFailure=False, prog_speed=prog_speed)
stoptime = datetime.now()
if status:
target_logger.info('FPGA Config OK, time: %s' % str(stoptime - starttime))
Expand Down Expand Up @@ -533,13 +534,15 @@ def _con(self, scope=None, bsfile=None, force=False, fpga_id=None, defines_files

if bsfile is None:
if self.platform == 'ss2_ice40':
from chipwhisperer.hardware.firmware.cwtargetice40 import getsome
from ...hardware.firmware.open_fw import getsome_generator
getsome = getsome_generator("cwtargetice40")
if self.target_name == 'AES':
bsfile = getsome(f"iCE40UP5K_SS2.bin")
else:
raise ValueError('Unknown target!')
else:
from chipwhisperer.hardware.firmware.xc7a35 import getsome
from ...hardware.firmware.open_fw import getsome_generator
getsome = getsome_generator("xc7a35")
if self.target_name == 'AES':
bsfile = getsome(f"AES_cw312t_a35.bit")
elif self.target_name == 'Cryptech ecdsa256-v1 pmul':
Expand Down
4 changes: 2 additions & 2 deletions chipwhisperer/capture/targets/CW310.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def _con(self, scope=None, bsfile=None, force=False, fpga_id=None, defines_files
if fpga_id is None:
verilog_defines = [self.default_verilog_defines_full_path]
else:
from ...hardware.firmware.cw305 import getsome
verilog_defines = [getsome(self.default_verilog_defines)]
from ...hardware.firmware.open_fw import registers
verilog_defines = [registers("cw305")]
else:
verilog_defines = defines_files
if slurp:
Expand Down
64 changes: 64 additions & 0 deletions chipwhisperer/capture/targets/SimpleSerial2.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,34 @@ def write(self, data, timeout=0):
data = bytearray(data)
self.ser.write(data, timeout)

@property
def parity(self):
if hasattr(self.ser, 'parity') and callable(self.ser.parity):
return self.ser.parity()
else:
raise AttributeError("Can't access parity")

@parity.setter
def parity(self, parity):
if hasattr(self.ser, 'parity') and callable(self.ser.parity):
return self.ser.setParity(parity)
else:
raise AttributeError("Can't access parity")

@property
def stop_bits(self):
if hasattr(self.ser, 'stopBits') and callable(self.ser.stopBits):
return self.ser.stopBits()
else:
raise AttributeError("Can't access parity")

@stop_bits.setter
def stop_bits(self, stop_bits):
if hasattr(self.ser, 'stopBits') and callable(self.ser.stopBits):
return self.ser.setStopBits(stop_bits)
else:
raise AttributeError("Can't access parity")

@property
def baud(self):
"""The current baud rate of the serial connection.
Expand Down Expand Up @@ -705,6 +733,42 @@ def in_waiting_tx(self):
"""
return self.ser.inWaitingTX()

@property
def xonxoff(self):
# TODO: check version to make sure fw has this
return self.ser.xonxoff

@xonxoff.setter
def xonxoff(self, enable):
self.ser.xonxoff = enable

@property
def currently_xoff(self):
return self.ser.currently_xoff

def __repr__(self):
ret = "SimpleSerial Settings ="
for line in dict_to_str(self._dict_repr()).split("\n"):
ret += "\n\t" + line
return ret

def __str__(self):
return self.__repr__()

def _dict_repr(self):
rtn = OrderedDict()
rtn['output_len'] = self.output_len

rtn['baud'] = self.baud
rtn['simpleserial_last_read'] = self.simpleserial_last_read
rtn['simpleserial_last_sent'] = self.simpleserial_last_sent
rtn['xonxoff'] = self.xonxoff
rtn['currently_xoff'] = self.currently_xoff
rtn['parity'] = self.parity
rtn['stop_bits'] = self.stop_bits
#rtn['protver'] = self.protver
return rtn

class SimpleSerial2_CDC(SimpleSerial2):
"""Target Option for Using SSV2 with a CDC Port
Expand Down
52 changes: 49 additions & 3 deletions chipwhisperer/capture/targets/simpleserial_readers/cwlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class SimpleSerial_ChipWhispererLite(SimpleSerialTemplate):
def __init__(self):
SimpleSerialTemplate.__init__(self)
self._baud = 38400
self._parity = "none"
self._stopbits = 1
self.cwlite_usart = None
self._buf_size = None

Expand All @@ -43,17 +45,48 @@ def close(self):
def setBaud(self, baud):
self._baud = baud
if self.cwlite_usart:
self.cwlite_usart.init(baud)
self.cwlite_usart.init(self._baud, self._stopbits, self._parity)
else:
logging.error('Baud rate not set, need to connect first')

def baud(self):
return self._baud

def setParity(self, parity):
old = self._parity
try:
self._parity = parity
if self.cwlite_usart:
self.cwlite_usart.init(self._baud, self._stopbits, self._parity)
else:
logging.error('Baud rate not set, need to connect first')
except ValueError as e:
self._parity = old
raise e

def parity(self):
return self._parity

def setStopBits(self, stopbits):
old = self._stopbits
try:
self._stopbits = stopbits
if self.cwlite_usart:
self.cwlite_usart.init(self._baud, self._stopbits, self._parity)
else:
logging.error('Baud rate not set, need to connect first')
except ValueError as e:
self._stopbits = old
raise e

def stopBits(self):
return self._stopbits


def con(self, scope): # remove typing here to avoid pulling in OpenADC/CWNano
if not scope is None:
self.cwlite_usart = scope._get_usart()
self.cwlite_usart.init(baud=self._baud)
self.cwlite_usart.init(baud=self._baud, stopbits=self._stopbits, parity=self._parity)
self._buf_size = 128
if self.cwlite_usart._usb.check_feature("SERIAL_200_BUFFER"):
self._buf_size = 200
Expand All @@ -73,4 +106,17 @@ def hardware_write(self, string):
self.cwlite_usart.write(string)

def hardware_read(self, num, timeout=250):
return self.cwlite_usart.read(num, timeout)
return self.cwlite_usart.read(num, timeout)

@property
def xonxoff(self):
# TODO: check version to make sure fw has this
return self.cwlite_usart.xonxoff

@xonxoff.setter
def xonxoff(self, enable):
self.cwlite_usart.xonxoff = enable

@property
def currently_xoff(self):
return self.cwlite_usart.currently_xoff
14 changes: 7 additions & 7 deletions chipwhisperer/common/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from functools import wraps
import warnings
from ...logging import *
from typing import List
from typing import List, Union, Type

BYTE_ARRAY_TYPES = (bytes, bytearray, memoryview)

Expand Down Expand Up @@ -559,27 +559,27 @@ def wrapper(*args, **kwargs):
return wrapper



def get_cw_type(sn=None, idProduct=None, hw_location=None, **kwargs) -> type:
def get_cw_type(sn=None, idProduct=None, hw_location=None, **kwargs):
""" Gets the scope type of the connected ChipWhisperer
If multiple connected, sn must be specified
"""
from chipwhisperer.hardware.naeusb.naeusb import NAEUSB, NAEUSB_Backend
from chipwhisperer.capture import scopes
from ...hardware.naeusb.naeusb import NAEUSB, NAEUSB_Backend
from ...capture import scopes
# from chipwhisperer.capture import scopes
# from ...capture.scopes import ScopeTypes
# todo: pyusb as well

if idProduct:
possible_ids = [idProduct]
else:
possible_ids = [0xace0, 0xace2, 0xace3, 0xace5]
possible_ids = [0xace0, 0xace2, 0xace3, 0xace5, 0xace6]

cwusb = NAEUSB_Backend()
device = cwusb.find(serial_number=sn, idProduct=possible_ids, hw_location=hw_location)
name = device.getProduct()
cwusb.usb_ctx.close()

if (name == "ChipWhisperer Lite") or (name == "ChipWhisperer CW1200") or (name == "ChipWhisperer Husky"):
if (name == "ChipWhisperer Lite") or (name == "ChipWhisperer CW1200") or (name == "ChipWhisperer Husky") or (name == "ChipWhisperer Husky Plus"):
return scopes.OpenADC
elif name == "ChipWhisperer Nano":
return scopes.CWNano
Expand Down
10 changes: 5 additions & 5 deletions chipwhisperer/hardware/firmware/cw1200.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions chipwhisperer/hardware/firmware/cwhusky.py

Large diffs are not rendered by default.

30 changes: 7 additions & 23 deletions chipwhisperer/hardware/firmware/cwlite.py

Large diffs are not rendered by default.

Loading

0 comments on commit 55b3206

Please sign in to comment.