Merge pull request #1558 from antmicro/add-gtp-channel-conf

Add GTP_CHANNEL fuzzer
This commit is contained in:
litghost 2021-01-22 12:36:55 -08:00 committed by GitHub
commit 6e3f053701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1632 additions and 0 deletions

View File

@ -0,0 +1,51 @@
# 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 ?= 10
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
$(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_channelx.db
${BUILD_DIR}/segbits_gtp_channelx.rdb: $(SPECIMENS_OK)
${XRAY_SEGMATCH} -c 9 -o ${BUILD_DIR}/segbits_gtp_channelx.rdb $$(find $(SPECIMENS) -name "segdata_gtp_channel_[0123]*")
${BUILD_DIR}/segbits_gtp_channelx.db: ${BUILD_DIR}/segbits_gtp_channelx.rdb
${XRAY_DBFIXUP} --db-root ${BUILD_DIR} --zero-db bits.dbf \
--seg-fn-in ${BUILD_DIR}/segbits_gtp_channelx.rdb \
--seg-fn-out ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MASKMERGE} ${BUILD_DIR}/mask_gtp_channelx.db $$(find $(SPECIMENS) -name "segdata_gtp_channel_[0123]*")
pushdb:
BUILD_DIR=$(BUILD_DIR) source pushdb.sh
.PHONY: database pushdb

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
00_519 01_519
28_519 29_519

View File

@ -0,0 +1,149 @@
#!/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, add_site_group_zero
INT = "INT"
BIN = "BIN"
BOOL = "BOOL"
STR = "STR"
def bitfilter_gtp_channel_x(frame, bit):
# Filter out interconnect bits.
if frame not in [28, 29, 30, 31]:
return False
return True
def bitfilter_gtp_channel_x_mid(frame, bit):
# Filter out interconnect bits.
if frame not in [0, 1, 2, 3]:
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:
primitives_list = json.load(f)
for primitive in primitives_list:
tile_type = primitive["tile_type"]
params_list = primitive["params"]
for params in params_list:
site = params["site"]
if "GTPE2_CHANNEL" 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])
elif 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])
elif param_type == BOOL:
segmk.add_site_tag(site, param, value == "TRUE")
else:
assert param_type == STR
# The RXSLIDE_MODE parameter has overlapping bits
# for its possible values. We need to treat it
# differently
if param == "RXSLIDE_MODE":
add_site_group_zero(
segmk, site, "{}.".format(param), param_values,
"OFF", value)
else:
for param_value in param_values:
segmk.add_site_tag(
site, "{}.{}".format(param, param_value),
value == param_value)
for param in ["TXUSRCLK", "TXUSRCLK2", "TXPHDLYTSTCLK",
"SIGVALIDCLK", "RXUSRCLK", "RXUSRCLK2", "DRPCLK",
"DMONITORCLK", "CLKRSVD0", "CLKRSVD1"]:
segmk.add_site_tag(
site, "ZINV_" + param, 1 ^ params[param])
gtp_channel_x = [
"GTP_CHANNEL_0",
"GTP_CHANNEL_1",
"GTP_CHANNEL_2",
"GTP_CHANNEL_3",
]
gtp_channel_x_mid = [
"GTP_CHANNEL_0_MID_LEFT",
"GTP_CHANNEL_1_MID_LEFT",
"GTP_CHANNEL_2_MID_LEFT",
"GTP_CHANNEL_3_MID_LEFT",
"GTP_CHANNEL_0_MID_RIGHT",
"GTP_CHANNEL_1_MID_RIGHT",
"GTP_CHANNEL_2_MID_RIGHT",
"GTP_CHANNEL_3_MID_RIGHT",
]
if tile_type in gtp_channel_x:
bitfilter = bitfilter_gtp_channel_x
elif tile_type in gtp_channel_x_mid:
bitfilter = bitfilter_gtp_channel_x_mid
else:
assert False, tile_type
segmk.compile(bitfilter=bitfilter)
segmk.write()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,30 @@
# 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-47}]
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,40 @@
#!/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 . -name "segdata_gtp_channel_[0123]_mid_*.txt" | wc -c) -eq 0
then
${XRAY_MERGEDB} gtp_channel_0_mid_left ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_1_mid_left ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_2_mid_left ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_3_mid_left ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_0_mid_left ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_1_mid_left ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_2_mid_left ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_3_mid_left ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_0_mid_right ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_1_mid_right ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_2_mid_right ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_3_mid_right ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_0_mid_right ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_1_mid_right ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_2_mid_right ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_3_mid_right ${BUILD_DIR}/mask_gtp_channelx.db
fi
if ! test $(find . -name "segdata_gtp_channel_[0123].txt" | wc -c) -eq 0
then
${XRAY_MERGEDB} gtp_channel_0 ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_1 ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_2 ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} gtp_channel_3 ${BUILD_DIR}/segbits_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_0 ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_1 ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_2 ${BUILD_DIR}/mask_gtp_channelx.db
${XRAY_MERGEDB} mask_gtp_channel_3 ${BUILD_DIR}/mask_gtp_channelx.db
fi

View File

@ -0,0 +1,154 @@
#!/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"
BOOL = "BOOL"
STR = "STR"
def gen_sites(site):
db = Database(util.get_db_root(), util.get_part())
grid = db.grid()
already_used = list()
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_CHANNEL_0",
"GTP_CHANNEL_1",
"GTP_CHANNEL_2",
"GTP_CHANNEL_3",
"GTP_CHANNEL_0_MID_LEFT",
"GTP_CHANNEL_1_MID_LEFT",
"GTP_CHANNEL_2_MID_LEFT",
"GTP_CHANNEL_3_MID_LEFT",
"GTP_CHANNEL_0_MID_RIGHT",
"GTP_CHANNEL_1_MID_RIGHT",
"GTP_CHANNEL_2_MID_RIGHT",
"GTP_CHANNEL_3_MID_RIGHT",
] or gridinfo.tile_type in already_used:
continue
else:
tile_type = gridinfo.tile_type
already_used.append(tile_type)
for site_name, site_type in gridinfo.sites.items():
if site_type != site:
continue
if "RIGHT" in tile_type and "X0" in site_name:
continue
if "LEFT" in tile_type and "X1" in site_name:
continue
yield tile_name, tile_type, site_name, site_type
def main():
print(
'''
module top(
input wire in,
output wire out
);
assign out = in;
''')
primitives_list = list()
for tile_name, tile_type, site_name, site_type in gen_sites(
"GTPE2_CHANNEL"):
params_list = list()
params_dict = dict()
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
elif param_type == BIN:
value = random.randint(0, param_values[0])
value_str = "{digits}'b{value:0{digits}b}".format(
value=value, digits=param_digits)
elif param_type in [BOOL, STR]:
value = random.choice(param_values)
value_str = verilog.quote(value)
params[param] = value
verilog_attr += """
.{}({}),""".format(param, value_str)
for param in ["TXUSRCLK", "TXUSRCLK2", "TXPHDLYTSTCLK",
"SIGVALIDCLK", "RXUSRCLK", "RXUSRCLK2", "DRPCLK",
"DMONITORCLK", "CLKRSVD0", "CLKRSVD1"]:
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_CHANNEL {} {} ();
""".format(verilog_attr, tile_type.lower()))
params_list.append(params)
params_dict["params"] = params_list
primitives_list.append(params_dict)
print("endmodule")
with open('params.json', 'w') as f:
json.dump(primitives_list, f, indent=2)
if __name__ == '__main__':
main()

View File

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

View File

@ -375,6 +375,8 @@ class Segmaker:
tile_type_norm = 'IOI3'
if tile_type_norm in ['CMT_TOP_L_LOWER_B', 'CMT_TOP_R_LOWER_B']:
tile_type_norm = 'CMT_LOWER_B'
if 'GTP_CHANNEL' in tile_type_norm:
tile_type_norm = 'GTP_CHANNEL'
# ignore dummy tiles (ex: VBRK)
if len(tiledata['bits']) == 0:

View File

@ -169,6 +169,42 @@ case "$1" in
gtp_common_mid_right)
cp "$2" "$tmp1" ;;
gtp_channel_0)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_0./' ;;
gtp_channel_1)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_1./' ;;
gtp_channel_2)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_2./' ;;
gtp_channel_3)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_3./' ;;
gtp_channel_0_mid_left)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_0_MID_LEFT./' ;;
gtp_channel_1_mid_left)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_1_MID_LEFT./' ;;
gtp_channel_2_mid_left)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_2_MID_LEFT./' ;;
gtp_channel_3_mid_left)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_3_MID_LEFT./' ;;
gtp_channel_0_mid_right)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_0_MID_RIGHT./' ;;
gtp_channel_1_mid_right)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_1_MID_RIGHT./' ;;
gtp_channel_2_mid_right)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_2_MID_RIGHT./' ;;
gtp_channel_3_mid_right)
sed < "$2" > "$tmp1" -e 's/^GTP_CHANNEL\./GTP_CHANNEL_3_MID_RIGHT./' ;;
mask_*)
db=$XRAY_DATABASE_DIR/$XRAY_DATABASE/$1.db
ismask=true