File tree Expand file tree Collapse file tree 15 files changed +229
-0
lines changed Expand file tree Collapse file tree 15 files changed +229
-0
lines changed Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+ from crcmod .predefined import mkPredefinedCrcFun
3
+
4
+ crc16arc = mkPredefinedCrcFun ('crc-16' )
5
+
6
+ def chunks (l , n ):
7
+ """Yield successive n-sized chunks from l."""
8
+ for i in range (0 , len (l ), n ):
9
+ yield l [i :i + n ]
10
+
11
+ def bytearr (frame ):
12
+ "array of all bytes of the frame"
13
+ return bytearray ([int (n , base = 2 ) for n in chunks (frame .strip (), 8 )])
14
+
15
+ def crc (frame ):
16
+ bs = bytearr (frame )
17
+ data = bs [- 6 :] + bs [:- 8 ]
18
+ crc = (bs [- 7 ] << 8 ) + bs [- 8 ]
19
+ #print(data)
20
+ return crc , crc16arc (data )
21
+
22
+ def bitarr (frame ):
23
+ "Array of *content* bits"
24
+ data = frame .strip ()[4 :- 64 ]
25
+ return [int (n , base = 2 ) for n in data ]
26
+
27
+
28
+ def read_bitstream (fname ):
29
+ bitmap = []
30
+ with open (fname ) as inp :
31
+ for line in inp :
32
+ if line .startswith ("//" ) or len (line ) < 1000 : continue
33
+ crc1 , crc2 = crc (line )
34
+ #if crc1 != crc2: print(crc1, crc2)
35
+ bitmap .append (bytearr (line )[:- 8 ])
36
+
37
+ return np .array (bitmap )
38
+
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from bslib import read_bitstream
3
+ from PIL import Image
4
+
5
+ arr = read_bitstream (sys .argv [1 ])
6
+ if len (sys .argv ) > 2 :
7
+ diff = read_bitstream (sys .argv [2 ])
8
+ arr ^= diff
9
+
10
+ size = (arr .shape [1 ]* 8 , arr .shape [0 ])
11
+ print (size )
12
+ im = Image .frombytes (mode = '1' , size = size , data = arr )
13
+ #im.show()
14
+ im .save ("bitmap.png" ,"PNG" )
Original file line number Diff line number Diff line change
1
+ set JTAG regular_io = false
2
+ set SSPI regular_io = false
3
+ set MSPI regular_io = false
4
+ set READY regular_io = false
5
+ set DONE regular_io = false
6
+ set RECONFIG_N regular_io = false
7
+ set MODE regular_io = false
8
+ set CRC_check = true
9
+ set compress = false
10
+ set encryption = false
11
+ set security_bit_enable = true
12
+ set bsram_init_fuse_print = true
13
+ set download_speed = 250/100
14
+ set spi_flash_address = 0x00FFF000
15
+ set format = txt
16
+ set background_programming = false
17
+ set secure_mode = false
Original file line number Diff line number Diff line change
1
+ module top ();
2
+ endmodule
Original file line number Diff line number Diff line change
1
+ -sdf
2
+ -oc
3
+ -ibs
4
+ -posp
5
+ -o
6
+ -warning_all
7
+ -timing
Original file line number Diff line number Diff line change
1
+ # gw_sh run.tcl
2
+ add_file -vm empty.v
3
+ add_file -cfg device.cfg
4
+ set_option -device GW1NR-9-QFN88-6
5
+ set_option -pn GW1NR-LV9QN88C6/I5
6
+ run_pnr -opt pnr.cfg
Original file line number Diff line number Diff line change
1
+ import json
2
+ import sys
3
+ import numpy as np
4
+ from bslib import read_bitstream
5
+
6
+ arr = read_bitstream (sys .argv [1 ])
7
+ diff = read_bitstream (sys .argv [2 ])
8
+ arr ^= diff
9
+ arr = np .unpackbits (arr , axis = 1 )
10
+
11
+ indices = np .transpose (np .nonzero (arr )).astype (int )
12
+ print (json .dumps (indices .tolist ()))
Original file line number Diff line number Diff line change
1
+ import sys
2
+ import json
3
+ import numpy as np
4
+ from bslib import read_bitstream
5
+ from PIL import Image
6
+
7
+ image = np .zeros ([712 , 2840 ], dtype = "byte" )
8
+ for fname in sys .argv [1 :]:
9
+ print (fname )
10
+ with open (fname ) as f :
11
+ try :
12
+ data = json .load (f )
13
+ except json .decoder .JSONDecodeError :
14
+ continue
15
+ for x , y in data :
16
+ image [x ][y ] += 1
17
+
18
+ print (np .nonzero (image > 1 ))
19
+ im = Image .frombytes (mode = '1' , size = image .shape [::- 1 ], data = np .packbits (image ))
20
+ #im.show()
21
+ im .save ("bitmap.png" ,"PNG" )
Original file line number Diff line number Diff line change
1
+ function loop {
2
+ cp -r lut4 lut4_$1
3
+ cd lut4_$1
4
+ for row in $1 $2
5
+ do
6
+ for col in {2..46}
7
+ do
8
+ for cls in {0..3}
9
+ do
10
+ for lut in A B
11
+ do
12
+ location=" R${row} C${col} [${cls} ][${lut} ]"
13
+ if [[ ! -f " ../data/fs/$location .fs" ]]; then
14
+ sed s/LOCATION/$location / lut4.cst.mk > lut4.cst
15
+ ~ /bin/gowin/IDE/bin/gw_sh run.tcl
16
+ mv impl/pnr/lut4.fs ../data/fs/$location .fs
17
+ fi
18
+ if [[ ! -f " ../data/bits/$location .json" ]]; then
19
+ python ../indices.py ../empty.fs ../data/fs/$location .fs > ../data/bits/$location .json
20
+ fi
21
+ done
22
+ done
23
+ done
24
+ done
25
+ }
26
+
27
+ set -x
28
+ cd empty
29
+ ~ /bin/gowin/IDE/bin/gw_sh run.tcl
30
+ cd ..
31
+ cp empty/impl/pnr/empty.fs .
32
+
33
+ mkdir -p data/fs
34
+ mkdir -p data/bits
35
+ # R2C2
36
+ # R27C46
37
+ loop 2 3 &
38
+ loop 4 5 &
39
+ loop 6 7 &
40
+ loop 8 9 &
41
+ loop 10 11 &
42
+ loop 12 13 &
43
+ loop 14 15 &
44
+ loop 16 17 &
45
+ loop 18 19 &
46
+ loop 20 21 &
47
+ loop 22 23 &
48
+ loop 24 25 &
49
+ loop 26 27 &
50
+ cd ..
51
+
Original file line number Diff line number Diff line change
1
+ set JTAG regular_io = false
2
+ set SSPI regular_io = false
3
+ set MSPI regular_io = false
4
+ set READY regular_io = false
5
+ set DONE regular_io = false
6
+ set RECONFIG_N regular_io = false
7
+ set MODE regular_io = false
8
+ set CRC_check = true
9
+ set compress = false
10
+ set encryption = false
11
+ set security_bit_enable = true
12
+ set bsram_init_fuse_print = true
13
+ set download_speed = 250/100
14
+ set spi_flash_address = 0x00FFF000
15
+ set format = txt
16
+ set background_programming = false
17
+ set secure_mode = false
Original file line number Diff line number Diff line change
1
+ //Copyright (C)2014-2019 Gowin Semiconductor Corporation.
2
+ //All rights reserved.
3
+ //File Title : Physical Constraints file
4
+ //GOWIN Version : V1.9.1.01Beta
5
+ //Part Number : GW1NR-LV9QN88C6/I5
6
+ //Created Time : Mon Sep 9 11:16:22 2019
7
+
8
+ INS_LOC "mylut" LOCATION;
Original file line number Diff line number Diff line change
1
+ //Copyright (C)2014-2019 GOWIN Semiconductor Corporation.
2
+ //All rights reserved.
3
+ //File Title: Timing Constraints file
4
+ //GOWIN Version: 1.9.1.01 Beta
5
+ //Created Time: 2019-08-06 14:29:38
6
+ create_clock -name clock -period 10 -waveform {0 5} [get_ports {clk}]
Original file line number Diff line number Diff line change
1
+ module top ();
2
+ wire gen_000_;
3
+ wire gen_001_;
4
+ wire gen_002_;
5
+ wire gen_003_;
6
+ wire gen_004_;
7
+ LUT4 mylut (
8
+ .F(gen_000_),
9
+ .I0(gen_001_),
10
+ .I1(gen_002_),
11
+ .I2(gen_003_),
12
+ .I3(gen_004_ )
13
+ );
14
+ defparam mylut.INIT = 16'h0000 ;
15
+ endmodule
Original file line number Diff line number Diff line change
1
+ -sdf
2
+ -oc
3
+ -ibs
4
+ -posp
5
+ -o
6
+ -warning_all
7
+ -timing
Original file line number Diff line number Diff line change
1
+ # gw_sh run.tcl
2
+ add_file -cst lut4.cst
3
+ add_file -sdc lut4.sdc
4
+ add_file -vm lut4.v
5
+ add_file -cfg device.cfg
6
+ set_option -device GW1NR-9-QFN88-6
7
+ set_option -pn GW1NR-LV9QN88C6/I5
8
+ run_pnr -opt pnr.cfg
You can’t perform that action at this time.
0 commit comments