Merge pull request #1548 from antmicro/add-gtp-common-conf

gtp_common: add conf fuzzer
This commit is contained in:
Alessandro Comodi 2021-01-21 09:47:33 +01:00 committed by GitHub
commit 77afcf8fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 528 additions and 0 deletions

View File

@ -0,0 +1,53 @@
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
SHELL = bash
N ?= 20
BUILD_DIR = build_${XRAY_PART}
SPECIMENS := $(addprefix ${BUILD_DIR}/specimen_,$(shell seq -f '%03.0f' $(N)))
SPECIMENS_OK := $(addsuffix /OK,$(SPECIMENS))
FUZDIR ?= ${PWD}
all: database
# generate.sh / top_generate.sh call make, hence the command must
# have a + before it.
$(SPECIMENS_OK): $(SPECIMENS_DEPS)
mkdir -p ${BUILD_DIR}
bash ${XRAY_DIR}/utils/top_generate.sh $(subst /OK,,$@)
run:
$(MAKE) clean
$(MAKE) database
$(MAKE) pushdb
touch run.${XRAY_PART}.ok
clean:
rm -rf ${BUILD_DIR} run.${XRAY_PART}.ok
.PHONY: all run clean
database: ${BUILD_DIR}/segbits_gtp_common.db
${BUILD_DIR}/segbits_gtp_common.rdb: $(SPECIMENS_OK)
${XRAY_SEGMATCH} -o ${BUILD_DIR}/segbits_gtp_common.rdb $$(find $(SPECIMENS) -name "segdata_gtp_common*")
${BUILD_DIR}/segbits_gtp_common.db: ${BUILD_DIR}/segbits_gtp_common.rdb
${XRAY_DBFIXUP} --db-root ${BUILD_DIR} --zero-db bits.dbf \
--seg-fn-in ${BUILD_DIR}/segbits_gtp_common.rdb \
--seg-fn-out ${BUILD_DIR}/segbits_gtp_common.db
${XRAY_MASKMERGE} ${BUILD_DIR}/mask_gtp_common.db $$(find $(SPECIMENS) -name "segdata_gtp_common*")
pushdb:
BUILD_DIR=$(BUILD_DIR) source pushdb.sh
.PHONY: database pushdb

View File

@ -0,0 +1,103 @@
{
"PLL0_CFG": {
"type": "BIN",
"values": [134150145],
"digits": 27
},
"PLL0_REFCLK_DIV": {
"type": "INT",
"values": [1, 2],
"encoding": [16, 0],
"digits": 5
},
"PLL0_FBDIV_45": {
"type": "INT",
"values": [4, 5],
"encoding": [0, 1],
"digits": 1
},
"PLL0_FBDIV": {
"type": "INT",
"values": [1, 2, 3, 4, 5],
"encoding": [16, 0, 1, 2, 3],
"digits": 6
},
"PLL0_LOCK_CFG": {
"type": "BIN",
"values": [511],
"digits": 9
},
"PLL0_INIT_CFG": {
"type": "BIN",
"values": [16711425],
"digits": 24
},
"RSVD_ATTR0": {
"type": "BIN",
"values": [65535],
"digits": 16
},
"PLL1_DMON_CFG": {
"type": "BIN",
"values": [1],
"digits": 1
},
"PLL0_DMON_CFG": {
"type": "BIN",
"values": [1],
"digits": 1
},
"COMMON_CFG": {
"type": "BIN",
"values": [4294836225],
"digits": 32
},
"PLL_CLKOUT_CFG": {
"type": "BIN",
"values": [255],
"digits": 8
},
"BIAS_CFG": {
"type": "BIN",
"values": [18445618199572250625],
"digits": 64
},
"RSVD_ATTR1": {
"type": "BIN",
"values": [65535],
"digits": 16
},
"PLL1_INIT_CFG": {
"type": "BIN",
"values": [16711425],
"digits": 24
},
"PLL1_LOCK_CFG": {
"type": "BIN",
"values": [511],
"digits": 9
},
"PLL1_REFCLK_DIV": {
"type": "INT",
"values": [1, 2],
"encoding": [16, 0],
"digits": 5
},
"PLL1_FBDIV_45": {
"type": "INT",
"values": [4, 5],
"encoding": [0, 1],
"digits": 1
},
"PLL1_FBDIV": {
"type": "INT",
"values": [1, 2, 3, 4, 5],
"encoding": [16, 0, 1, 2, 3],
"digits": 6
},
"PLL1_CFG": {
"type": "BIN",
"values": [134150145],
"digits": 27
}
}

View File

View File

@ -0,0 +1,137 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
import json
import os
from enum import Enum
from prjxray.segmaker import Segmaker
INT = "INT"
BIN = "BIN"
def bitfilter_gtp_common_mid(frame, bit):
# Filter out interconnect bits.
if frame not in [0, 1]:
return False
return True
def bitfilter_gtp_common(frame, bit):
# Filter out interconnect bits.
if frame not in [28, 29]:
return False
return True
def main():
segmk = Segmaker("design.bits")
fuz_dir = os.getenv("FUZDIR", None)
assert fuz_dir
with open(os.path.join(fuz_dir, "attrs.json"), "r") as attr_file:
attrs = json.load(attr_file)
print("Loading tags")
with open("params.json") as f:
params_dict = json.load(f)
tile_type = params_dict["tile_type"]
params_list = params_dict["params"]
for params in params_list:
site = params["site"]
if "GTPE2_COMMON" not in site:
continue
in_use = params["IN_USE"]
segmk.add_site_tag(site, "IN_USE", in_use)
if in_use:
for param, param_info in attrs.items():
value = params[param]
param_type = param_info["type"]
param_digits = param_info["digits"]
param_values = param_info["values"]
if param_type == INT:
param_encodings = param_info["encoding"]
param_encoding = param_encodings[param_values.index(value)]
bitstr = [
int(x) for x in "{value:0{digits}b}".format(
value=param_encoding, digits=param_digits)[::-1]
]
for i in range(param_digits):
segmk.add_site_tag(
site, '%s[%u]' % (param, i), bitstr[i])
else:
assert param_type == BIN
bitstr = [
int(x) for x in "{value:0{digits}b}".format(
value=value, digits=param_digits)[::-1]
]
for i in range(param_digits):
segmk.add_site_tag(
site, "%s[%u]" % (param, i), bitstr[i])
for param, invert in [("GTGREFCLK1", 0), ("GTGREFCLK0", 0),
("PLL0LOCKDETCLK", 1), ("PLL1LOCKDETCLK",
1), ("DRPCLK", 1)]:
if invert:
segmk.add_site_tag(
site, "ZINV_" + param, 1 ^ params[param])
else:
segmk.add_site_tag(site, "INV_" + param, params[param])
for params in params_list:
site = params["site"]
if "IBUFDS_GTE2" not in site:
continue
in_use = params["IN_USE"]
segmk.add_site_tag(site, "IN_USE", in_use)
if in_use:
tile = params["tile"]
for param in ["CLKRCV_TRST", "CLKCM_CFG"]:
value = params[param]
segmk.add_site_tag(site, param, "TRUE" in value)
bitstr = [
int(x) for x in "{value:0{digits}b}".format(
value=params["CLKSWING_CFG"], digits=2)[::-1]
]
for i in range(2):
segmk.add_tile_tag(
tile, "IBUFDS_GTE2.%s[%u]" % (param, i), bitstr[i])
if tile_type == "GTP_COMMON":
bitfilter = bitfilter_gtp_common
elif tile_type == "GTP_COMMON_MID_RIGHT":
bitfilter = bitfilter_gtp_common_mid
else:
assert False, tile_type
segmk.compile(bitfilter=bitfilter)
segmk.write()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,29 @@
# Copyright (C) 2017-2020 The Project X-Ray Authors
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
proc run {} {
create_project -force -part $::env(XRAY_PART) design design
read_verilog top.v
synth_design -top top
set_property CFGBVS VCCO [current_design]
set_property CONFIG_VOLTAGE 3.3 [current_design]
set_property BITSTREAM.GENERAL.PERFRAMECRC YES [current_design]
set_property IS_ENABLED 0 [get_drc_checks {NSTD-1}]
set_property IS_ENABLED 0 [get_drc_checks {UCIO-1}]
set_property IS_ENABLED 0 [get_drc_checks {REQP-48}]
set_property IS_ENABLED 0 [get_drc_checks {REQP-1619}]
place_design
route_design
write_checkpoint -force design.dcp
write_bitstream -force design.bit
}
run

View File

@ -0,0 +1,22 @@
#!/bin/bash
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
if ! test $(find ${BUILD_DIR} -name "segdata_gtp_common_mid_right.txt" | wc -c) -eq 0
then
${XRAY_MERGEDB} gtp_common_mid_right ${BUILD_DIR}/segbits_gtp_common.db
${XRAY_MERGEDB} mask_gtp_common_mid_right ${BUILD_DIR}/mask_gtp_common.db
${XRAY_MERGEDB} gtp_common_mid_left ${BUILD_DIR}/segbits_gtp_common.db
${XRAY_MERGEDB} mask_gtp_common_mid_left ${BUILD_DIR}/mask_gtp_common.db
fi
if ! test $(find ${BUILD_DIR} -name "segdata_gtp_common.txt" | wc -c) -eq 0
then
${XRAY_MERGEDB} gtp_common ${BUILD_DIR}/segbits_gtp_common.db
${XRAY_MERGEDB} mask_gtp_common ${BUILD_DIR}/mask_gtp_common.db
fi

View File

@ -0,0 +1,173 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
import json
import os
import random
from collections import namedtuple
random.seed(int(os.getenv("SEED"), 16))
from prjxray import util
from prjxray import verilog
from prjxray.db import Database
INT = "INT"
BIN = "BIN"
def gen_sites(site):
db = Database(util.get_db_root(), util.get_part())
grid = db.grid()
for tile_name in sorted(grid.tiles()):
loc = grid.loc_of_tilename(tile_name)
gridinfo = grid.gridinfo_at_loc(loc)
if gridinfo.tile_type not in [
"GTP_COMMON",
"GTP_COMMON_MID_RIGHT",
]:
continue
else:
tile_type = gridinfo.tile_type
for site_name, site_type in gridinfo.sites.items():
if site_type != site:
continue
yield tile_name, tile_type, site_name, site_type
def main():
print(
'''
module top(
input wire in,
output wire out
);
assign out = in;
''')
params_dict = {"tile_type": None}
params_list = list()
for tile_name, tile_type, site_name, site_type in gen_sites(
"GTPE2_COMMON"):
if params_dict["tile_type"]:
assert tile_type == params_dict["tile_type"]
else:
params_dict["tile_type"] = tile_type
params = dict()
params['site'] = site_name
verilog_attr = ""
verilog_attr = "#("
fuz_dir = os.getenv("FUZDIR", None)
assert fuz_dir
with open(os.path.join(fuz_dir, "attrs.json"), "r") as attrs_file:
attrs = json.load(attrs_file)
in_use = bool(random.randint(0, 9))
params["IN_USE"] = in_use
if in_use:
for param, param_info in attrs.items():
param_type = param_info["type"]
param_values = param_info["values"]
param_digits = param_info["digits"]
if param_type == INT:
value = random.choice(param_values)
value_str = value
else:
assert param_type == BIN
value = random.randint(0, param_values[0])
value_str = "{digits}'b{value:0{digits}b}".format(
value=value, digits=param_digits)
params[param] = value
verilog_attr += """
.{}({}),""".format(param, value_str)
for param in ["GTGREFCLK1", "GTGREFCLK0", "PLL0LOCKDETCLK",
"PLL1LOCKDETCLK", "DRPCLK"]:
is_inverted = random.randint(0, 1)
params[param] = is_inverted
verilog_attr += """
.IS_{}_INVERTED({}),""".format(param, is_inverted)
verilog_attr = verilog_attr.rstrip(",")
verilog_attr += "\n)"
print("(* KEEP, DONT_TOUCH, LOC=\"{}\" *)".format(site_name))
print(
"""GTPE2_COMMON {attrs} {site} (
.GTREFCLK0(1'b0),
.GTREFCLK1(1'b0)
);""".format(attrs=verilog_attr, site=site_name))
params_list.append(params)
clkswing_cfg_tiles = dict()
for tile_name, _, site_name, site_type in gen_sites("IBUFDS_GTE2"):
# Both the IBUFDS_GTE2 in the same tile need to have
# the same CLKSWING_CFG parameter
if tile_name not in clkswing_cfg_tiles:
clkswing_cfg = random.randint(0, 3)
clkswing_cfg_tiles[tile_name] = clkswing_cfg
else:
clkswing_cfg = clkswing_cfg_tiles[tile_name]
in_use = bool(random.randint(0, 9))
params = {
"site":
site_name,
"tile":
tile_name,
"IN_USE":
in_use,
"CLKRCV_TRST":
verilog.quote("TRUE" if random.randint(0, 1) else "FALSE"),
"CLKCM_CFG":
verilog.quote("TRUE" if random.randint(0, 1) else "FALSE"),
"CLKSWING_CFG":
clkswing_cfg,
}
if in_use:
print("(* KEEP, DONT_TOUCH, LOC=\"{}\" *)".format(site_name))
print(
"""
IBUFDS_GTE2 #(
.CLKRCV_TRST({CLKRCV_TRST}),
.CLKCM_CFG({CLKCM_CFG}),
.CLKSWING_CFG({CLKSWING_CFG})
) {site} (
);""".format(**params))
params_list.append(params)
print("endmodule")
params_dict["params"] = params_list
with open('params.json', 'w') as f:
json.dump(params_dict, f, indent=2)
if __name__ == '__main__':
main()

View File

@ -158,6 +158,7 @@ $(eval $(call fuzzer,076-ps7,,all))
endif
ifeq ($(XRAY_DATABASE),artix7)
$(eval $(call fuzzer,061-pcie-conf,005-tilegrid,all))
$(eval $(call fuzzer,063-gtp-common-conf,005-tilegrid,part))
endif
endif
endif

View File

@ -331,6 +331,7 @@ class Segmaker:
'IDELAY': name_y0y1,
'ILOGIC': name_y0y1,
'OLOGIC': name_y0y1,
'IBUFDS': name_y0y1,
}.get(site_prefix, name_default)()
self.verbose and print(
'site %s w/ %s prefix => tag %s' %

View File

@ -160,6 +160,15 @@ case "$1" in
pcie_bot)
cp "$2" "$tmp1" ;;
gtp_common)
cp "$2" "$tmp1" ;;
gtp_common_mid_left)
sed < "$2" > "$tmp1" -e 's/^GTP_COMMON_MID_RIGHT\./GTP_COMMON_MID_LEFT./' ;;
gtp_common_mid_right)
cp "$2" "$tmp1" ;;
mask_*)
db=$XRAY_DATABASE_DIR/$XRAY_DATABASE/$1.db
ismask=true