# upload a file into DIMM memory, and optionally encrypt for the given key.
# note that the re-encryption is obsoleted by just setting a zero-key, which
# is a magic to disable the decryption.
def DIMM_UploadFile(name, key = None):
import zlib
crc = 0
a = open(name, "rb")
addr = 0
if key:
d = DES.new(key[::-1], DES.MODE_ECB)
while True:
sys.stderr.write("%08x\r" % addr)
data = a.read(0x8000)
if not len(data):
break
if key:
data = d.encrypt(data[::-1])[::-1]
DIMM_Upload(addr, data, 0)
crc = zlib.crc32(data, crc)
addr += len(data)
crc = ~crc
DIMM_Upload(addr, "12345678", 1)
DIMM_SetInformation(crc, addr)