Skip to content

Commit 68af501

Browse files
committed
Cleanup
1 parent 8e6c2b9 commit 68af501

File tree

4 files changed

+65
-90
lines changed

4 files changed

+65
-90
lines changed

devices.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,23 +235,6 @@
235235
"gap": 64
236236
}
237237
}
238-
},
239-
"ph1": {
240-
"devices": {
241-
"ph1": {
242-
"packages": {
243-
"PH1A100SFG676": { "part": "PH1A100SFG676", "idcode": "0x00000000" },
244-
"PH1A100CGC324": { "part": "PH1A100CGC324", "idcode": "0x00000000" }
245-
},
246-
"max_col": 80,
247-
"max_row": 160,
248-
"frames": 3058,
249-
"bits_per_frame": 10368,
250-
"db_bits_per_frame": 10368,
251-
"bram_bits_per_frame": 9216,
252-
"gap": 64
253-
}
254-
}
255238
}
256239
}
257240
}

tools/create_database.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
def main():
1515
devices = database.get_devices()
1616
tang_root = database.get_tangdinasty_root()
17-
if not path.exists(database.get_db_root()):
18-
os.mkdir(database.get_db_root())
19-
shutil.rmtree("work_decrypt", ignore_errors=True)
20-
os.mkdir("work_decrypt")
17+
shutil.rmtree(database.get_db_root(), ignore_errors=True)
18+
os.mkdir(database.get_db_root())
2119

2220
shutil.copy(path.join(database.get_tang_root(), "devices.json"), path.join(database.get_db_root(), "devices.json"))
2321

@@ -26,11 +24,12 @@ def main():
2624
for device in devices["families"][family]["devices"].keys():
2725
print("Device: " + device)
2826
selected_device = devices["families"][family]["devices"][device]
29-
os.mkdir(path.join("work_decrypt",device))
3027

31-
json_file = path.join(database.get_db_subdir(family, device), "tilegrid.json")
32-
chipdb = path.join(tang_root, "arch", device + ".db")
33-
unlogic.decode_chipdb(["create_database", chipdb, "--tilegrid", json_file, "--datadir", path.join("work_decrypt",device)])
28+
database_dir = database.get_db_subdir(family, device)
29+
if not path.exists(path.join(database_dir,"bits")):
30+
os.mkdir(path.join(database_dir,"bits"))
31+
chipdb = path.join(tang_root, "arch", device + ".db")
32+
unlogic.decode_chipdb(["create_database", chipdb, "--db_dir", database_dir])
3433

3534
if __name__ == "__main__":
3635
main()

tools/decrypt_all.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ def main():
2222
for device in devices["families"][family]["devices"].keys():
2323
print("Device: " + device)
2424
selected_device = devices["families"][family]["devices"][device]
25-
os.mkdir(path.join("work_decrypt",device))
2625
unc_file = path.join("work_decrypt", device + ".unc")
2726
chipdb = path.join(tang_root, "arch", device + ".db")
28-
unlogic.decode_chipdb(["decrypt_all", chipdb, "--decrypt", unc_file, "--datadir", path.join("work_decrypt",device)])
27+
unlogic.decode_chipdb(["decrypt_all", chipdb, "--decrypt", unc_file])
2928

3029
if __name__ == "__main__":
3130
main()

tools/unlogic.py

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,10 @@ def decode_chipdb(argv):
7373
parser.set_defaults(file_paths=dict())
7474
parser.add_argument("dbfile", metavar="<db_file>.db>", nargs="?",
7575
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>",
7777
action=DictAction, dest="file_paths")
7878
parser.add_argument("--decrypt", metavar="<path_to_decrypted_file>",
7979
action=DictAction, dest="file_paths")
80-
parser.add_argument("--datadir", metavar="<path_to_data_directory>",
81-
action=DictAction, dest="file_paths")
8280
args = parser.parse_args(argv[1:])
8381
dbfile = args.dbfile
8482
global decrypt
@@ -390,66 +388,61 @@ def decode_chipdb(argv):
390388
print_decrypt(out)
391389
global bcc_info
392390
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
443434

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
451441

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)
453446

454447

455448
bcc_info[bcc_name] = bits
@@ -585,8 +578,9 @@ def decode_chipdb(argv):
585578
if "decrypt" in file_paths.keys():
586579
decrypt.close()
587580

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:
590584
json.dump(tiles, fout, indent=4)
591585

592586
if __name__ == '__main__':

0 commit comments

Comments
 (0)