@@ -266,6 +266,10 @@ def parse_int(str_value):
266266 "--meta" ,
267267 action = "store_true" ,
268268 help = "dump out the metadata for all connected boards in JSON" )
269+ parser .add_argument (
270+ "--security" ,
271+ type = str ,
272+ help = "update the security page in the flash at address addr" )
269273 parser .add_argument (
270274 "--update-bootloader" ,
271275 action = "store_true" ,
@@ -372,6 +376,7 @@ def parse_int(str_value):
372376 # program the flash memory
373377 if (args .program is not None ) or (
374378 args .program_userdata is not None ) or (
379+ args .security is not None ) or (
375380 args .program_image is not None ):
376381 boot_fpga = False
377382
@@ -381,6 +386,7 @@ def progress(info):
381386
382387 with active_port :
383388 fpga = TinyProg (active_port , progress )
389+ force = False
384390
385391 if args .program is not None :
386392 print (" Programming %s with %s" % (
@@ -390,6 +396,7 @@ def progress(info):
390396
391397 if args .addr is not None :
392398 addr = parse_int (args .addr )
399+ force = True
393400 else :
394401 addr = fpga .meta .userimage_addr_range ()[0 ]
395402
@@ -400,7 +407,7 @@ def progress(info):
400407 print (" Bootloader not active" )
401408 sys .exit (1 )
402409
403- if check_if_overwrite_bootloader (
410+ if force or check_if_overwrite_bootloader (
404411 addr , len (bitstream ),
405412 fpga .meta .userimage_addr_range ()):
406413 boot_fpga = True
@@ -417,6 +424,7 @@ def progress(info):
417424
418425 if args .addr is not None :
419426 addr = parse_int (args .addr )
427+ force = True
420428 else :
421429 addr = fpga .meta .userdata_addr_range ()[0 ]
422430
@@ -427,7 +435,7 @@ def progress(info):
427435 print (" Bootloader not active" )
428436 sys .exit (1 )
429437
430- if check_if_overwrite_bootloader (
438+ if force or check_if_overwrite_bootloader (
431439 addr , len (bitstream ),
432440 fpga .meta .userdata_addr_range ()):
433441 boot_fpga = True
@@ -444,6 +452,7 @@ def progress(info):
444452
445453 if args .addr is not None :
446454 addr = parse_int (args .addr )
455+ force = True
447456 else :
448457 addr = fpga .meta .userimage_addr_range ()[0 ]
449458
@@ -454,7 +463,7 @@ def progress(info):
454463 print (" Bootloader not active" )
455464 sys .exit (1 )
456465
457- if check_if_overwrite_bootloader (
466+ if force or check_if_overwrite_bootloader (
458467 addr , len (bitstream ),
459468 (fpga .meta .userimage_addr_range ()[0 ],
460469 fpga .meta .userdata_addr_range ()[1 ])):
@@ -463,6 +472,27 @@ def progress(info):
463472 if not fpga .program_bitstream (addr , bitstream ):
464473 sys .exit (1 )
465474
475+ if args .security is not None :
476+ print (" Programming %s security page with %s" % (
477+ active_port , args .security ))
478+
479+ data = open (args .security , 'r' ).read ()
480+
481+ if args .addr is not None :
482+ addr = parse_int (args .addr )
483+ else :
484+ addr = 1
485+
486+ if addr < 0 :
487+ print (" Negative write addr: {}" .format (addr ))
488+ sys .exit (1 )
489+ if not fpga .is_bootloader_active ():
490+ print (" Bootloader not active" )
491+ sys .exit (1 )
492+
493+ if not fpga .program_security_page (addr , data ):
494+ sys .exit (1 )
495+
466496 if boot_fpga :
467497 fpga .boot ()
468498 print ("" )
0 commit comments