Started working on internal checksum transfers
This commit is contained in:
+34
-14
@@ -12,7 +12,7 @@ UNISOC_PID = 0x4d00
|
||||
UNISOC_FLASH_BASE_ADDR = 0x10000000
|
||||
MAX_PKT_SIZE = 1024
|
||||
bSize = 512 # read block size
|
||||
genTimeout = 40000
|
||||
genTimeout = 120000
|
||||
|
||||
# all main procedures
|
||||
|
||||
@@ -64,21 +64,22 @@ def handshake(fdlBooted = False):
|
||||
if len(r):
|
||||
print('>', r.decode())
|
||||
|
||||
def send_file_to_addr(fname, faddr, fdlBooted = False, flashMode = False, fbs = 1024, forceErase = False):
|
||||
def send_file_to_addr(fname, faddr, fdlBooted = False, flashMode = False, fbs = 1024):
|
||||
pSize = MAX_PKT_SIZE
|
||||
f = open(fname, 'rb')
|
||||
fdata = f.read()
|
||||
f.close()
|
||||
flen = len(fdata)
|
||||
print('Initializing data transfer...')
|
||||
dataCrc = 0
|
||||
if flashMode:
|
||||
if forceErase:
|
||||
erase_flash_mem(flen, UNISOC_FLASH_BASE_ADDR + faddr)
|
||||
# faddr is our flash offset in this case, and we directly pass the data buffer to the function
|
||||
pSize = fbs
|
||||
# faddr is our flash offset in this case
|
||||
resp = reqresp(unicmd.cmd_data_start(UNISOC_FLASH_BASE_ADDR + faddr, flen), fdlBooted)
|
||||
fdata = fname
|
||||
flen = len(fdata)
|
||||
else:
|
||||
resp = reqresp(unicmd.cmd_data_start(faddr, flen), fdlBooted)
|
||||
f = open(fname, 'rb')
|
||||
fdata = f.read()
|
||||
f.close()
|
||||
flen = len(fdata)
|
||||
dataCrc = unicmd.chksum32(fdata)
|
||||
resp = reqresp(unicmd.cmd_data_start(faddr, flen, dataCrc), fdlBooted)
|
||||
rcode, rlen, r = unicmd.resp_decode(resp, fdlBooted)
|
||||
assert rcode == unicmd.BSL_REP_ACK, 'Could not start data transfer, response code is %X' % rcode
|
||||
print('Starting data transfer...')
|
||||
@@ -93,7 +94,7 @@ def send_file_to_addr(fname, faddr, fdlBooted = False, flashMode = False, fbs =
|
||||
print('\nEnding data transfer...')
|
||||
resp = reqresp(unicmd.cmd_data_end(), fdlBooted)
|
||||
rcode, rlen, r = unicmd.resp_decode(resp, fdlBooted)
|
||||
if not flashMode or rcode != unicmd.BSL_FLASH_CFG_ERROR: # on flashing, ignore 0xA4 error
|
||||
if not flashMode or (rcode != unicmd.BSL_FLASH_CFG_ERROR and rcode != unicmd.BSL_WRITE_ERROR): # on flashing, ignore 0xA2 and 0xA4 errors
|
||||
assert rcode == unicmd.BSL_REP_ACK, 'Could not finalize data transfer, response code is %X' % rcode
|
||||
print('Data transfer successful')
|
||||
|
||||
@@ -128,7 +129,7 @@ def read_partition(partid, partsize, partoffset, outfile, rbblocksize):
|
||||
outf.flush()
|
||||
print('\nPartition dumped!')
|
||||
|
||||
# memory eraser
|
||||
# memory eraser and writer
|
||||
|
||||
def erase_flash_mem(size, faddr):
|
||||
print('Erasing %d bytes in the flash memory at offset 0x%X...' % (size, faddr - UNISOC_FLASH_BASE_ADDR))
|
||||
@@ -137,6 +138,25 @@ def erase_flash_mem(size, faddr):
|
||||
assert rcode == unicmd.BSL_REP_ACK, 'Could not erase flash memory, response code is %X' % rcode
|
||||
print('Flash range erased!')
|
||||
|
||||
def write_flash_mem(infile, offset, blocksize, forceErase):
|
||||
startAddr = UNISOC_FLASH_BASE_ADDR + offset
|
||||
f = open(infile, 'rb')
|
||||
fdata = f.read()
|
||||
f.close()
|
||||
flen = len(fdata)
|
||||
if forceErase:
|
||||
erase_flash_mem(flen, startAddr)
|
||||
send_file_to_addr(fdata, startAddr, True, True, blocksize)
|
||||
'''
|
||||
UNISOC_MAX_DL_CHUNK = 0x300000
|
||||
curAddr = startAddr
|
||||
while fdata:
|
||||
fchunk = fdata[:UNISOC_MAX_DL_CHUNK]
|
||||
send_file_to_addr(fchunk, curAddr, True, True, blocksize)
|
||||
curAddr += len(fchunk)
|
||||
fdata = fdata[UNISOC_MAX_DL_CHUNK:]
|
||||
'''
|
||||
|
||||
def auto_int(x):
|
||||
return int(x,0)
|
||||
|
||||
@@ -221,7 +241,7 @@ if __name__ == '__main__': # main app start
|
||||
|
||||
if is_flash:
|
||||
print('Writing flash at offset 0x%X from %s...' % (readoffset, outfile))
|
||||
send_file_to_addr(outfile, readoffset, True, True, readbs, forceErase)
|
||||
write_flash_mem(outfile, readoffset, readbs, forceErase)
|
||||
print('Flash memory written, disconnect the device!')
|
||||
else:
|
||||
read_partition(partitionId, readlen, readoffset, outfile, readbs)
|
||||
|
||||
Reference in New Issue
Block a user