17
17
from apycula import attrids
18
18
from apycula import bslib
19
19
from apycula .wirenames import wirenames , wirenumbers
20
+ from apycula .family_aliases import replace_family_alias
20
21
21
22
device = ""
22
23
pnr = None
@@ -1029,12 +1030,25 @@ def route(db, tilemap, pips):
1029
1030
for row , col in bits :
1030
1031
tile [row ][col ] = 1
1031
1032
1032
- def header_footer (db , bs , compress ):
1033
+ def header_footer (db , bs , compress , family ):
1033
1034
"""
1034
1035
Generate fs header and footer
1035
1036
Currently limited to checksum with
1036
1037
CRC_check and security_bit_enable set
1037
1038
"""
1039
+ # override part IDCODE in header
1040
+ assert db .cmd_hdr [3 ][0 ] == 0x06 # IDCODE data
1041
+
1042
+ with importlib .resources .path ('apycula' , f'family_info.json' ) as path :
1043
+ with open (path , 'r' ) as f :
1044
+ family_info = json .load (f )
1045
+
1046
+ if family in family_info and "idcode" in family_info [family ]:
1047
+ db .cmd_hdr [3 ][- 4 :] = bytes .fromhex (family_info [family ]["idcode" ])
1048
+ else :
1049
+ print ("Not overriding IDCODE as it is not present in family_info.json" )
1050
+
1051
+ # calculate checksum
1038
1052
bs = np .fliplr (bs )
1039
1053
bs = np .packbits (bs )
1040
1054
# configuration data checksum is computed on all
@@ -1157,7 +1171,7 @@ def main():
1157
1171
parser .add_argument ('--png' )
1158
1172
1159
1173
args = parser .parse_args ()
1160
- device = args .device
1174
+ device = replace_family_alias ( args .device )
1161
1175
1162
1176
with open (args .netlist ) as f :
1163
1177
pnr = json .load (f )
@@ -1173,7 +1187,9 @@ def main():
1173
1187
mods = m .group (1 ) or ""
1174
1188
luts = m .group (3 )
1175
1189
device = f"GW1N{ mods } -{ luts } "
1176
- with importlib .resources .path ('apycula' , f'{ args .device } .pickle' ) as path :
1190
+ device = replace_family_alias (device )
1191
+
1192
+ with importlib .resources .path ('apycula' , f'{ device } .pickle' ) as path :
1177
1193
with closing (gzip .open (path , 'rb' )) as f :
1178
1194
db = pickle .load (f )
1179
1195
@@ -1206,7 +1222,7 @@ def main():
1206
1222
tile [row ][col ] = 0
1207
1223
1208
1224
res = chipdb .fuse_bitmap (db , tilemap )
1209
- header_footer (db , res , args .compress )
1225
+ header_footer (db , res , args .compress , device )
1210
1226
if pil_available and args .png :
1211
1227
bslib .display (args .png , res )
1212
1228
bslib .write_bitstream (args .output , res , db .cmd_hdr , db .cmd_ftr , args .compress )
0 commit comments