def program_sam3u(self, port, fw_path=None): """Program the SAM3U Firmware assuming device is in bootloader mode""" fw_data = None print("Opening firmware...") if fw_path is None: print("Firmware not specified. Using firmware/phywhisperer.py") from phywhisperer.firmware.phywhisperer import getsome fw_data = getsome("phywhisperer-SAM3U1C.bin").read() else: if not os.path.isfile(fw_path): raise ValueError("Cannot find specified firmware file {}".format(fw_path)) fw_data = open(fw_path, "rb").read() sam = Samba() print("Opened!\nConnecting...") sam.con(port) print("Connected!\nErasing...") sam.erase() print("Erased!\nProgramming file {}...".format(fw_path)) sam.write(fw_data) print("Programmed!\nVerifying...") if sam.verify(fw_data): print("Verify OK!") sam.flash.setBootFlash(True) print("Bootloader disabled. Please power cycle device.") else: print("Verify FAILED!") sam.ser.close()
def con(self, PID=0xC610, sn=None, program_fpga=True, bitstream_file=None): """Connect to PhyWhisperer-USB. Raises error if multiple detected Args: PID (int, optional): USB PID of PhyWhisperer, defaults to 0xC610 (NewAE standard). sn (int, option): Serial Number of PhyWhisperer, required when multiple PhyWhisperers are connected. program_fpga (bool, option): Specifies whether or not to program the FPGA with the default firmware when we connect. Set to False if using custom bitstream. """ self.usb = NAE.NAEUSB() self.usb.con(idProduct=[PID], serial_number=sn) self._llint = LLINT.PhyWhispererUSB(self.usb) if program_fpga: if bitstream_file is None: with ZipFile(getsome("phywhisperer-firmware.zip")) as myzip: with myzip.open('phywhisperer_top.bit') as bitstream: self._llint.FPGAProgram(bitstream) pass else: print("Programming custom bit stream '%s'" % bitstream_file) with open(bitstream_file,"rb") as bitstream: self._llint.FPGAProgram(bitstream) self.write_reg(self.REG_COUNT_WRITES, [1])
def con(self, PID=0xC521, sn=None, program_fpga=True): """Connect to PhyWhisperer-USB. Raises error if multiple detected PID : int Product ID of PhyWhisperer sn : int Serial Number of PhyWhisperer, required when multiple PhyWhisperers are connected. program_fpga : bool Specifies whether or not to program the FPGA with the default firmware when we connect """ self.usb = NAE.NAEUSB() self.usb.con(idProduct=[PID], serial_number=sn) self._llint = LLINT.PhyWhispererUSB(self.usb) if program_fpga: from phywhisperer.firmware.phywhisperer import getsome with ZipFile(getsome("phywhisperer-firmware.zip")) as myzip: with myzip.open('phywhisperer_top.bit') as bitstream: self._llint.FPGAProgram(bitstream) pass pass
def program_sam3u(self, port, fw_path=None): """Program the SAM3U Firmware assuming device is in bootloader mode. Args: port (str): Serial port name, such as 'COM36' or '/dev/ttyACM0'. fw_path (str): Path to firmware binary to program the sam3u with. If None, use default firmware. Defautls to None. """ fw_data = None print("Opening firmware...") if fw_path is None: print("Firmware not specified. Using firmware/phywhisperer.py") fw_data = getsome("phywhisperer-SAM3U1C.bin").read() else: if not os.path.isfile(fw_path): raise ValueError("Cannot find specified firmware file {}".format(fw_path)) fw_data = open(fw_path, "rb").read() sam = Samba() print("Opened!\nConnecting...") sam.con(port) print("Connected!\nErasing...") sam.erase() print("Erased!\nProgramming file {}...".format(fw_path)) sam.write(fw_data) print("Programmed!\nVerifying...") if sam.verify(fw_data): print("Verify OK!") sam.flash.setBootFlash(True) print("Bootloader disabled. Please power cycle device.") else: print("Verify FAILED!") sam.ser.close()