Skip to content

Commit daf0d08

Browse files
committed
allow flash of config only
1 parent 123bc3d commit daf0d08

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

re_programmer.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,32 @@ def Main():
5555
if( not os.path.isdir( SAVE_PATH)):
5656
os.system( 'mkdir ' + SAVE_PATH)
5757

58+
print( "Info:")
59+
if( args.prog_file != ''):
60+
print( "\tFlash program file: " + args.prog_file)
61+
if( args.conf_file != ''):
62+
print( "\tFlash config file: " + args.prog_file)
63+
if( args.prog_file == '' and args.conf_file == ''):
64+
print( "\tRead config from module only")
65+
5866
try:
5967
Init()
6068
Connect()
6169
info = ReadInfo()
6270
old_conf = ReadConfig( info['id'], args.force)
6371

64-
if( args.prog_file != ''):
72+
if( args.prog_file != '' or args.conf_file != ''):
6573
if( args.conf_file == ''):
6674
new_conf = old_conf
6775
else:
6876
new_conf = MergeConfig( old_conf, args.conf_file)
6977
program_size = GetProgSize( new_conf)
70-
new_program = ReadProgram( args.prog_file)
71-
WriteProgArea( new_program, program_size)
72-
WriteConfigArea( new_conf)
78+
if( args.prog_file != ''):
79+
new_program = ReadProgram( args.prog_file)
80+
WriteProgArea( new_program, program_size)
81+
else:
82+
new_program = None
83+
WriteConfigArea( new_conf, True if (args.prog_file != '') else False)
7384
ExecuteBist()
7485
Verify( new_conf, new_program, program_size)
7586
if( args.lock == True):
@@ -145,7 +156,7 @@ def Send( buffer):
145156
#print( 'send' + str(i) + ': ' + List2Hex( send))
146157

147158
if( Ready() != 1):
148-
raise Exception( "Enocean Module not ready")
159+
WaitTillReady( 500)
149160

150161
spi.xfer2( send)
151162
time.sleep( 0.00002)
@@ -274,6 +285,7 @@ def ReadConfig( id = '', force_backup = False, clear_code_protect = True):
274285
conf_hex.tofile( SAVE_PATH + '/' + List2Hex( id, '') + '_cfg.hex', format='hex')
275286
print( "\tloaded config from module:")
276287
DecodeConfig( conf_hex, '\t\t')
288+
print( "\t\tdumped config to: " + SAVE_PATH + '/' + List2Hex( id, '') + '_cfg.hex')
277289

278290
print( "\tDone")
279291
return conf_hex
@@ -344,17 +356,18 @@ def WriteFlashPage( start, write):
344356
data = Receive( 8)
345357
InfoOk( data, 'WriteFlashPage')
346358

347-
def WriteConfigArea( new_conf_hex):
359+
def WriteConfigArea( new_conf_hex, update_prog_size):
348360

349361
print( "Write config area to module")
350362
new_conf = new_conf_hex.tobinarray()
351363
WriteFlashPage( PAGE_CONF, new_conf)
352-
# 1st 4 bytes are only byte access
353-
WriteFlashByte( PAGE_CONF * 256 + 0, new_conf[0])
354-
WriteFlashByte( PAGE_CONF * 256 + 1, new_conf[1])
355-
WriteFlashByte( PAGE_CONF * 256 + 2, new_conf[2])
356-
WriteFlashByte( PAGE_CONF * 256 + 3, new_conf[3])
357364

365+
if( update_prog_size):
366+
# 1st 4 bytes are only byte access
367+
WriteFlashByte( PAGE_CONF * 256 + 0, new_conf[0])
368+
WriteFlashByte( PAGE_CONF * 256 + 1, new_conf[1])
369+
WriteFlashByte( PAGE_CONF * 256 + 2, new_conf[2])
370+
WriteFlashByte( PAGE_CONF * 256 + 3, new_conf[3])
358371

359372
print( "\tDone")
360373

@@ -394,20 +407,21 @@ def Verify( new_conf_hex, new_prog_hex, program_size):
394407
i += 1
395408
print( "\tDone")
396409

397-
print( "Verify program area")
398-
data = [ 0xA5, 0x5A, 0xA5, CMD_RD_PRG_AREA, program_size, 0x00, 0x00, 0x00]
399-
data[7] = CalcChecksum( data)
400-
Send( data)
401-
data = Receive( 8)
402-
InfoOk( data, 'WriteFlashPage')
403-
read_prog = Receive( program_size * 256)
404-
new_prog = new_prog_hex.tobinarray()
405-
i = 0
406-
for p in new_prog:
407-
if( p != read_prog[i]):
408-
raise Exception( "Verify: program area mismatch at: " + ("%X" % i))
409-
i += 1
410-
print( "\tDone")
410+
if( new_prog_hex != None):
411+
print( "Verify program area")
412+
data = [ 0xA5, 0x5A, 0xA5, CMD_RD_PRG_AREA, program_size, 0x00, 0x00, 0x00]
413+
data[7] = CalcChecksum( data)
414+
Send( data)
415+
data = Receive( 8)
416+
InfoOk( data, 'WriteFlashPage')
417+
read_prog = Receive( program_size * 256)
418+
new_prog = new_prog_hex.tobinarray()
419+
i = 0
420+
for p in new_prog:
421+
if( p != read_prog[i]):
422+
raise Exception( "Verify: program area mismatch at: " + ("%X" % i))
423+
i += 1
424+
print( "\tDone")
411425

412426
def CodeProtect():
413427
print( "Set codeprotect bit")

0 commit comments

Comments
 (0)