Added erase mode
This commit is contained in:
+16
-3
@@ -12,7 +12,7 @@ UNISOC_PID = 0x4d00
|
||||
UNISOC_FLASH_BASE_ADDR = 0x10000000
|
||||
MAX_PKT_SIZE = 1024
|
||||
bSize = 512 # read block size
|
||||
genTimeout = 4000
|
||||
genTimeout = 40000
|
||||
|
||||
# all main procedures
|
||||
|
||||
@@ -64,7 +64,7 @@ def handshake(fdlBooted = False):
|
||||
if len(r):
|
||||
print('>', r.decode())
|
||||
|
||||
def send_file_to_addr(fname, faddr, fdlBooted = False, flashMode = False, fbs = 1024):
|
||||
def send_file_to_addr(fname, faddr, fdlBooted = False, flashMode = False, fbs = 1024, forceErase = False):
|
||||
pSize = MAX_PKT_SIZE
|
||||
f = open(fname, 'rb')
|
||||
fdata = f.read()
|
||||
@@ -72,6 +72,8 @@ def send_file_to_addr(fname, faddr, fdlBooted = False, flashMode = False, fbs =
|
||||
flen = len(fdata)
|
||||
print('Initializing data transfer...')
|
||||
if flashMode:
|
||||
if forceErase:
|
||||
erase_flash_mem(flen, UNISOC_FLASH_BASE_ADDR + faddr)
|
||||
pSize = fbs
|
||||
# faddr is our flash offset in this case
|
||||
resp = reqresp(unicmd.cmd_data_start(UNISOC_FLASH_BASE_ADDR + faddr, flen), fdlBooted)
|
||||
@@ -126,6 +128,15 @@ def read_partition(partid, partsize, partoffset, outfile, rbblocksize):
|
||||
outf.flush()
|
||||
print('\nPartition dumped!')
|
||||
|
||||
# memory eraser
|
||||
|
||||
def erase_flash_mem(size, faddr):
|
||||
print('Erasing %d bytes in the flash memory at offset 0x%X...' % (size, faddr - UNISOC_FLASH_BASE_ADDR))
|
||||
resp = reqresp(unicmd.cmd_erase_flash(faddr, size), True)
|
||||
rcode, rlen, r = unicmd.resp_decode(resp, True)
|
||||
assert rcode == unicmd.BSL_REP_ACK, 'Could not erase flash memory, response code is %X' % rcode
|
||||
print('Flash range erased!')
|
||||
|
||||
def auto_int(x):
|
||||
return int(x,0)
|
||||
|
||||
@@ -140,6 +151,7 @@ if __name__ == '__main__': # main app start
|
||||
parser.add_argument('-p','--partid', type=auto_int, default=0x80000003, help='partition ID for readback (defaults to 0x80000003 that can address full flash space on SC6531E/F/M)')
|
||||
parser.add_argument('-s','--start', type=auto_int, default=0, help='start position (in the partition, defaults to 0)')
|
||||
parser.add_argument('-l', '--length', type=auto_int, default=0x400000, help='data length in bytes to read/write, defaults to 0x400000')
|
||||
parser.add_argument('-e','--force-erase', type=bool, default=False, help='Erase target flash memory area before writing')
|
||||
parser.add_argument('-bs','--block-size', type=auto_int, default=4096, help='Readback/write block size (in bytes), defaults to 4096')
|
||||
parser.add_argument('-dv','--device-vid', type=auto_int, default=UNISOC_VID, help='Override device vendor ID')
|
||||
parser.add_argument('-dp','--device-pid', type=auto_int, default=UNISOC_PID, help='Override device product ID')
|
||||
@@ -164,6 +176,7 @@ if __name__ == '__main__': # main app start
|
||||
readbs = args.block_size
|
||||
readoffset = args.start
|
||||
readlen = args.length
|
||||
forceErase = args.force_erase
|
||||
|
||||
print('Using FDL1 %s, loading to 0x%X' % (fdl1Name, fdl1Addr))
|
||||
print('Using FDL2 %s, loading to 0x%X' % (fdl2Name, fdl2Addr))
|
||||
@@ -208,7 +221,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)
|
||||
send_file_to_addr(outfile, readoffset, True, True, readbs, forceErase)
|
||||
print('Flash memory written, disconnect the device!')
|
||||
else:
|
||||
read_partition(partitionId, readlen, readoffset, outfile, readbs)
|
||||
|
||||
Reference in New Issue
Block a user