Ejemplo n.º 1
0
def run_pnr(mod, constr):
    cfg = codegen.DeviceConfig({
        "JTAG regular_io": "true",
        "SSPI regular_io": "true",
        "MSPI regular_io": "true",
        "READY regular_io": "true",
        "DONE regular_io": "true",
        "RECONFIG_N regular_io": "false",  # not recommended
        "MODE regular_io": "true",
        "CRC_check": "true",
        "compress": "false",
        "encryption": "false",
        "security_bit_enable": "true",
        "bsram_init_fuse_print": "true",
        "download_speed": "250/100",
        "spi_flash_address": "0x00FFF000",
        "format": "txt",
        "background_programming": "false",
        "secure_mode": "false"
    })

    opt = codegen.PnrOptions(["posp", "warning_all"])
    #"sdf", "oc", "ibs", "posp", "o",
    #"warning_all", "timing", "reg_not_in_iob"])

    pnr = codegen.Pnr()
    pnr.device = params['device']
    pnr.partnumber = params['partnumber']

    with tempfile.TemporaryDirectory() as tmpdir:
        pnr.outdir = tmpdir
        with open(tmpdir + "/top.v", "w") as f:
            mod.write(f)
        pnr.netlist = tmpdir + "/top.v"
        with open(tmpdir + "/top.cst", "w") as f:
            constr.write(f)
        pnr.cst = tmpdir + "/top.cst"
        with open(tmpdir + "/device.cfg", "w") as f:
            cfg.write(f)
        pnr.cfg = tmpdir + "/device.cfg"
        with open(tmpdir + "/pnr.cfg", "w") as f:
            opt.write(f)
        pnr.opt = tmpdir + "/pnr.cfg"
        with open(tmpdir + "/run.tcl", "w") as f:
            pnr.write(f)
        subprocess.run([gowinhome + "/IDE/bin/gw_sh", tmpdir + "/run.tcl"])
        #print(tmpdir); input()
        try:
            return (*bslib.read_bitstream(tmpdir+"/impl/pnr/top.fs"), \
                   list(read_posp(tmpdir+"/impl/pnr/top.posp")))
        except FileNotFoundError:
            print(tmpdir)
            input()
            return None, None
Ejemplo n.º 2
0
import sys
from bslib import read_bitstream
from PIL import Image

arr = read_bitstream(sys.argv[1])
if len(sys.argv) > 2:
    diff = read_bitstream(sys.argv[2])
    arr ^= diff

size = (arr.shape[1]*8, arr.shape[0])
print(size)
im = Image.frombytes(mode='1', size=size, data=arr)
#im.show()
im.save("bitmap.png","PNG")
Ejemplo n.º 3
0
                    getattr(mod, direction).update(wnames)

            mod.primitives[name] = iob

    gnd = codegen.Primitive("GND", "mygnd")
    gnd.portmap["G"] = "VSS"
    mod.primitives["mygnd"] = gnd
    vcc = codegen.Primitive("VCC", "myvcc")
    vcc.portmap["V"] = "VCC"
    mod.primitives["myvcc"] = vcc


if __name__ == "__main__":
    with open(f"{device}.pickle", 'rb') as f:
        db = pickle.load(f)
    bitmap = read_bitstream(sys.argv[1])[0]
    bm = chipdb.tile_bitmap(db, bitmap)
    mod = codegen.Module()
    for idx, t in bm.items():
        row, col = idx
        dbtile = db.grid[row][col]
        print(idx)
        #for bitrow in t:
        #    print(*bitrow, sep='')
        #if idx == (5, 0):
        #    from fuse_h4x import *
        #    fse = readFse(open("/home/pepijn/bin/gowin/IDE/share/device/GW1N-1/GW1N-1.fse", 'rb'))
        #    breakpoint()
        bels, pips = parse_tile_(dbtile, t)
        print(bels)
        #print(pips)
Ejemplo n.º 4
0
def run_pnr(fuzzers, bits):
    #TODO generalize/parameterize
    mod = codegen.Module()
    constr = codegen.Constraints()
    start = 0
    for fuzzer in fuzzers:
        cb = bits[start:start + fuzzer.cfg_bits]
        start += fuzzer.cfg_bits
        fuzzer.primitives(mod, cb)
        fuzzer.constraints(constr, cb)

    cfg = codegen.DeviceConfig({
        "JTAG regular_io": "false",
        "SSPI regular_io": "false",
        "MSPI regular_io": "false",
        "READY regular_io": "false",
        "DONE regular_io": "false",
        "RECONFIG_N regular_io": "false",
        "MODE regular_io": "false",
        "CRC_check": "true",
        "compress": "false",
        "encryption": "false",
        "security_bit_enable": "true",
        "bsram_init_fuse_print": "true",
        "download_speed": "250/100",
        "spi_flash_address": "0x00FFF000",
        "format": "txt",
        "background_programming": "false",
        "secure_mode": "false"
    })

    opt = codegen.PnrOptions([])
    #"sdf", "oc", "ibs", "posp", "o",
    #"warning_all", "timing", "reg_not_in_iob"])

    pnr = codegen.Pnr()
    pnr.device = "GW1NR-9-QFN88-6"
    pnr.partnumber = "GW1NR-LV9QN88C6/I5"

    with tempfile.TemporaryDirectory() as tmpdir:
        pnr.outdir = tmpdir
        with open(tmpdir + "/top.v", "w") as f:
            mod.write(f)
        pnr.netlist = tmpdir + "/top.v"
        with open(tmpdir + "/top.cst", "w") as f:
            constr.write(f)
        pnr.cst = tmpdir + "/top.cst"
        with open(tmpdir + "/device.cfg", "w") as f:
            cfg.write(f)
        pnr.cfg = tmpdir + "/device.cfg"
        with open(tmpdir + "/pnr.cfg", "w") as f:
            opt.write(f)
        pnr.opt = tmpdir + "/pnr.cfg"
        with open(tmpdir + "/run.tcl", "w") as f:
            pnr.write(f)
        subprocess.run([gowinhome + "/IDE/bin/gw_sh", tmpdir + "/run.tcl"])
        #print(tmpdir); input()
        try:
            return bslib.read_bitstream(tmpdir + "/impl/pnr/top.fs")[0]
        except FileNotFoundError:
            return None