@@ -73,12 +73,10 @@ def decode_chipdb(argv):
73
73
parser .set_defaults (file_paths = dict ())
74
74
parser .add_argument ("dbfile" , metavar = "<db_file>.db>" , nargs = "?" ,
75
75
help = "Anlogic architecture .db file" )
76
- parser .add_argument ("--tilegrid " , metavar = "<path_to_tilegrid_json >" ,
76
+ parser .add_argument ("--db_dir " , metavar = "<path_to_database_directory >" ,
77
77
action = DictAction , dest = "file_paths" )
78
78
parser .add_argument ("--decrypt" , metavar = "<path_to_decrypted_file>" ,
79
79
action = DictAction , dest = "file_paths" )
80
- parser .add_argument ("--datadir" , metavar = "<path_to_data_directory>" ,
81
- action = DictAction , dest = "file_paths" )
82
80
args = parser .parse_args (argv [1 :])
83
81
dbfile = args .dbfile
84
82
global decrypt
@@ -390,66 +388,61 @@ def decode_chipdb(argv):
390
388
print_decrypt (out )
391
389
global bcc_info
392
390
bcc_name = unk [0 ]
393
- with open (os .path .join (file_paths ["datadir" ],unk [0 ]+ ".json" ), "wt" ) as f :
394
- #print_decrypt_tofile(f, out)
395
- k = int (unk [3 ])
396
- bits = []
397
- for j in range (k ):
398
- unk ,out = decode (fp , [0 ,1 ])
399
- print_decrypt (out )
400
- #print_decrypt_tofile(f, out)
401
- current_item = {
402
- "name" : unk [0 ],
403
- "type" : unk [1 ],
404
- "y" : int (unk [2 ]),
405
- "x" : int (unk [3 ]),
406
- "xoff" : int (unk [4 ]),
407
- "yoff" : int (unk [5 ]),
408
- "flag1" : int (unk [6 ]),
409
- "flag2" : int (unk [7 ]),
410
- "flag3" : int (unk [8 ]),
411
- "cnt" : int (unk [11 ])
412
- }
413
- assert (int (unk [6 ])== 0 or int (unk [6 ])== 1 )
414
- assert (int (unk [7 ])== 0 or int (unk [7 ])== 1 )
415
- assert (int (unk [8 ])== 0 or int (unk [8 ])== 1 )
416
- bits .append (current_item )
417
- n1 = int (unk [9 ])
418
- n2 = int (unk [10 ])
419
- n3 = int (unk [11 ])
420
-
421
- for l in range (n1 ):
422
- unk ,out = decode (fp , [])
423
- if (int (unk [0 ])>= 10 ):
424
- print_decrypt (chr (55 + int (unk [0 ])))
425
- #print_decrypt_tofile(f, chr(55+int(unk[0])))
426
- else :
427
- print_decrypt (mapping [int (unk [0 ])])
428
- #print_decrypt_tofile(f,mapping[int(unk[0])])
429
- empty ,out = decode (fp , [])
430
- print_decrypt (out )
431
- assert len (empty )== 0
432
- for l in range (n2 ):
433
- unk ,out = decode (fp , [])
434
- if (int (unk [0 ])>= 10 ):
435
- print_decrypt (chr (55 + int (unk [0 ])))
436
- #print_decrypt_tofile(f, chr(55+int(unk[0])))
437
- else :
438
- print_decrypt (mapping [int (unk [0 ])])
439
- #print_decrypt_tofile(f,mapping[int(unk[0])])
440
- empty ,out = decode (fp , [])
441
- print_decrypt (out )
442
- assert len (empty )== 0
391
+ k = int (unk [3 ])
392
+ bits = []
393
+ for j in range (k ):
394
+ unk ,out = decode (fp , [0 ,1 ])
395
+ print_decrypt (out )
396
+ current_item = {
397
+ "name" : unk [0 ],
398
+ "type" : unk [1 ],
399
+ "y" : int (unk [2 ]),
400
+ "x" : int (unk [3 ]),
401
+ "xoff" : int (unk [4 ]),
402
+ "yoff" : int (unk [5 ]),
403
+ "flag1" : int (unk [6 ]),
404
+ "flag2" : int (unk [7 ]),
405
+ "flag3" : int (unk [8 ]),
406
+ "cnt" : int (unk [11 ])
407
+ }
408
+ assert (int (unk [6 ])== 0 or int (unk [6 ])== 1 )
409
+ assert (int (unk [7 ])== 0 or int (unk [7 ])== 1 )
410
+ assert (int (unk [8 ])== 0 or int (unk [8 ])== 1 )
411
+ bits .append (current_item )
412
+ n1 = int (unk [9 ])
413
+ n2 = int (unk [10 ])
414
+ n3 = int (unk [11 ])
415
+
416
+ for l in range (n1 ):
417
+ unk ,out = decode (fp , [])
418
+ if (int (unk [0 ])>= 10 ):
419
+ print_decrypt (chr (55 + int (unk [0 ])))
420
+ else :
421
+ print_decrypt (mapping [int (unk [0 ])])
422
+ empty ,out = decode (fp , [])
423
+ print_decrypt (out )
424
+ assert len (empty )== 0
425
+ for l in range (n2 ):
426
+ unk ,out = decode (fp , [])
427
+ if (int (unk [0 ])>= 10 ):
428
+ print_decrypt (chr (55 + int (unk [0 ])))
429
+ else :
430
+ print_decrypt (mapping [int (unk [0 ])])
431
+ empty ,out = decode (fp , [])
432
+ print_decrypt (out )
433
+ assert len (empty )== 0
443
434
444
- for l in range (n3 ):
445
- unk ,out = decode (fp , [1 ])
446
- print_decrypt (chr (55 + int (unk [0 ]))+ " " + unk [1 ])
447
- #print_decrypt_tofile(f, chr(55+int(unk[0]))+ " " + unk[1])
448
- empty ,out = decode (fp , [])
449
- print_decrypt (out )
450
- assert len (empty )== 0
435
+ for l in range (n3 ):
436
+ unk ,out = decode (fp , [1 ])
437
+ print_decrypt (chr (55 + int (unk [0 ]))+ " " + unk [1 ])
438
+ empty ,out = decode (fp , [])
439
+ print_decrypt (out )
440
+ assert len (empty )== 0
451
441
452
- json .dump (bits , f , indent = 4 )
442
+ if "db_dir" in file_paths .keys ():
443
+ json_file = os .path .join (file_paths ["db_dir" ], "bits" , unk [0 ]+ ".json" )
444
+ with open (json_file , "wt" ) as f :
445
+ json .dump (bits , f , indent = 4 )
453
446
454
447
455
448
bcc_info [bcc_name ] = bits
@@ -585,8 +578,9 @@ def decode_chipdb(argv):
585
578
if "decrypt" in file_paths .keys ():
586
579
decrypt .close ()
587
580
588
- if "tilegrid" in file_paths .keys ():
589
- with open (file_paths ["tilegrid" ], "wt" ) as fout :
581
+ if "db_dir" in file_paths .keys ():
582
+ json_file = os .path .join (file_paths ["db_dir" ], "tilegrid.json" )
583
+ with open (json_file , "wt" ) as fout :
590
584
json .dump (tiles , fout , indent = 4 )
591
585
592
586
if __name__ == '__main__' :
0 commit comments