Skip to content

Commit

Permalink
Finish moving over to new binary file sys
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dewar committed Dec 3, 2024
1 parent b881d34 commit ed7632b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
11 changes: 1 addition & 10 deletions software/chipwhisperer/capture/scopes/OpenADC.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,7 @@ def __init__(self):
def _getFWPy(self):
from ...hardware.firmware.open_fw import fwver
cw_type = self._getCWType()
fwver = fwver(cw_type)
# if cw_type == "cwlite":
# from ...hardware.firmware.cwlite import fwver
# elif cw_type == "cw1200":
# from ...hardware.firmware.cw1200 import fwver # type: ignore
# elif cw_type in ["cwhusky", "cwhuskyplus"]:
# from ...hardware.firmware.cwhusky import fwver # type: ignore
# else:
# raise ValueError('Unknown cw_type: %s' % cw_type)
return fwver
return fwver(cw_type)

def reload_fpga(self, bitstream=None, reconnect=True, prog_speed=1E6):
"""(Re)loads a FPGA bitstream (even if already configured).
Expand Down
15 changes: 9 additions & 6 deletions software/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 software/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
4 changes: 2 additions & 2 deletions software/chipwhisperer/capture/targets/CW340.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,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
Binary file not shown.
9 changes: 9 additions & 0 deletions software/chipwhisperer/hardware/firmware/open_fw.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def registers(dev_name, filelike=True):
return data
pass

def getsome_generator(dev_name):
def getsome(item, filelike=True):
with open(res_file_path(dev_name, item), "rb") as f:
data = f.read()
if filelike:
data = io.BytesIO(data)
return data
return getsome

def _extract_file(getsome, item):
data = getsome(item).read()
with open(item, "wb") as f:
Expand Down
6 changes: 4 additions & 2 deletions software/chipwhisperer/hardware/naeusb/programmer_neorv32.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ def load_ice40(self, bsfile=None, force_ice40type=None):
devtype = devtype[0].lower()

if devtype == "ice40up5k":
from chipwhisperer.hardware.firmware.cwtargetice40 import getsome
# from chipwhisperer.hardware.firmware.cwtargetice40 import getsome
from ..firmware.open_fw import res_file_path
else:
raise ValueError("Device type: %s. I don't have a pre-built FPGA bitstream for you (or connection bad)."%devtype)

bsdata = getsome("neorv32_iCE40CW312_MinimalBoot_directclk_7370KHz.bit").read()
# bsdata = getsome("neorv32_iCE40CW312_MinimalBoot_directclk_7370KHz.bit").read()
bsdata = open(res_file_path("neorv32_iCE40CW312_MinimalBoot_directclk_7370KHz.bit"), "rb").read()
else:
target_logger.info("ice40: Loading bitstream from %s"%bsfile)
f = open(bsfile, "rb")
Expand Down

0 comments on commit ed7632b

Please sign in to comment.