1717from apycula import attrids
1818from apycula import bslib
1919from apycula .wirenames import wirenames , wirenumbers
20+ from apycula .family_aliases import replace_family_alias
2021
2122device = ""
2223pnr = None
@@ -1029,12 +1030,25 @@ def route(db, tilemap, pips):
10291030 for row , col in bits :
10301031 tile [row ][col ] = 1
10311032
1032- def header_footer (db , bs , compress ):
1033+ def header_footer (db , bs , compress , family ):
10331034 """
10341035 Generate fs header and footer
10351036 Currently limited to checksum with
10361037 CRC_check and security_bit_enable set
10371038 """
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
10381052 bs = np .fliplr (bs )
10391053 bs = np .packbits (bs )
10401054 # configuration data checksum is computed on all
@@ -1157,7 +1171,7 @@ def main():
11571171 parser .add_argument ('--png' )
11581172
11591173 args = parser .parse_args ()
1160- device = args .device
1174+ device = replace_family_alias ( args .device )
11611175
11621176 with open (args .netlist ) as f :
11631177 pnr = json .load (f )
@@ -1173,7 +1187,9 @@ def main():
11731187 mods = m .group (1 ) or ""
11741188 luts = m .group (3 )
11751189 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 :
11771193 with closing (gzip .open (path , 'rb' )) as f :
11781194 db = pickle .load (f )
11791195
@@ -1206,7 +1222,7 @@ def main():
12061222 tile [row ][col ] = 0
12071223
12081224 res = chipdb .fuse_bitmap (db , tilemap )
1209- header_footer (db , res , args .compress )
1225+ header_footer (db , res , args .compress , device )
12101226 if pil_available and args .png :
12111227 bslib .display (args .png , res )
12121228 bslib .write_bitstream (args .output , res , db .cmd_hdr , db .cmd_ftr , args .compress )
0 commit comments