From 9e6c62cb4c95f7e33b880404de9fc5d3ada51056 Mon Sep 17 00:00:00 2001 From: Alessandro Comodi Date: Fri, 11 Jan 2019 12:39:54 +0100 Subject: [PATCH] 005-tilegrid: created a util script There is some shared code between add_tdb.py and generate_full.py. To solve this I have added a util script containing shared code. Moreover, in the case a block has to be overwritten, the add_tile_bits function now checks if the two version of the block contain the same information. If this does not happend the script fails. Signed-off-by: Alessandro Comodi --- fuzzers/005-tilegrid/add_tdb.py | 41 +----------------- fuzzers/005-tilegrid/generate_full.py | 43 ++----------------- fuzzers/005-tilegrid/util.py | 62 +++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 78 deletions(-) create mode 100644 fuzzers/005-tilegrid/util.py diff --git a/fuzzers/005-tilegrid/add_tdb.py b/fuzzers/005-tilegrid/add_tdb.py index d33ffc1d..1e7ba68d 100644 --- a/fuzzers/005-tilegrid/add_tdb.py +++ b/fuzzers/005-tilegrid/add_tdb.py @@ -3,44 +3,7 @@ from prjxray import util import json import os - - -# Copied from generate_full.py -def add_tile_bits(tile_db, baseaddr, offset, frames, words, height=None): - ''' - Record data structure geometry for the given tile baseaddr - For most tiles there is only one baseaddr, but some like BRAM have multiple - Notes on multiple block types: - https://github.com/SymbiFlow/prjxray/issues/145 - ''' - - bits = tile_db['bits'] - block_type = util.addr2btype(baseaddr) - - assert 0 <= offset <= 100, offset - assert 1 <= words <= 101 - assert offset + words <= 101, ( - tile_db, offset + words, offset, words, block_type) - - assert block_type not in bits - block = bits.setdefault(block_type, {}) - - # FDRI address - block["baseaddr"] = '0x%08X' % baseaddr - # Number of frames this entry is sretched across - # that is the following FDRI addresses are used: range(baseaddr, baseaddr + frames) - block["frames"] = frames - - # Index of first word used within each frame - block["offset"] = offset - - # related to words... - # deprecated field? Don't worry about for now - # DSP has some differences between height and words - block["words"] = words - if height is None: - height = words - block["height"] = height +import util as localutil def parse_addr(line): @@ -129,7 +92,7 @@ def run(fn_in, fn_out, verbose=False): bitsj = tilej['bits'] bt = util.addr2btype(frame) verbose and print("Add %s %08X_%03u" % (tile, frame, wordidx)) - add_tile_bits(tilej, frame, wordidx, frames, words) + localutil.add_tile_bits(tile, tilej, frame, wordidx, frames, words) # Save json.dump( diff --git a/fuzzers/005-tilegrid/generate_full.py b/fuzzers/005-tilegrid/generate_full.py index 94cd92aa..aa7da664 100644 --- a/fuzzers/005-tilegrid/generate_full.py +++ b/fuzzers/005-tilegrid/generate_full.py @@ -12,6 +12,7 @@ A post processing step verifies that two tiles don't reference the same bitstrea from generate import load_tiles from prjxray import util +import util as localutil def nolr(tile_type): @@ -494,42 +495,6 @@ def seg_base_addr_up_INT(database, segments, tiles_by_grid, verbose=False): wordbase) -def add_tile_bits(tile_db, baseaddr, offset, frames, words, height=None): - ''' - Record data structure geometry for the given tile baseaddr - For most tiles there is only one baseaddr, but some like BRAM have multiple - Notes on multiple block types: - https://github.com/SymbiFlow/prjxray/issues/145 - ''' - - bits = tile_db['bits'] - block_type = util.addr2btype(baseaddr) - assert 0 <= offset <= 100, offset - assert 1 <= words <= 101 - assert offset + words <= 101, ( - tile_db, offset + words, offset, words, block_type) - - #assert block_type not in bits: - block = bits.setdefault(block_type, {}) - - # FDRI address - block["baseaddr"] = '0x%08X' % baseaddr - # Number of frames this entry is sretched across - # that is the following FDRI addresses are used: range(baseaddr, baseaddr + frames) - block["frames"] = frames - - # Index of first word used within each frame - block["offset"] = offset - - # related to words... - # deprecated field? Don't worry about for now - # DSP has some differences between height and words - block["words"] = words - if height is None: - height = words - block["height"] = height - - def db_add_bits(database, segments): '''Transfer segment data into tiles''' for segment_name in segments.keys(): @@ -597,9 +562,9 @@ def db_add_bits(database, segments): if frames: # if we have a width, we should have a height assert frames and words - add_tile_bits( - database[tile_name], baseaddr, offset, frames, words, - height) + localutil.add_tile_bits( + tile_name, database[tile_name], baseaddr, offset, + frames, words, height) def db_add_segments(database, segments): diff --git a/fuzzers/005-tilegrid/util.py b/fuzzers/005-tilegrid/util.py new file mode 100644 index 00000000..fe1b484d --- /dev/null +++ b/fuzzers/005-tilegrid/util.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +from prjxray import util +''' +Local utils script to hold shared code of the 005-tilegrid fuzzer scripts +''' + +def add_tile_bits( + tile_name, + tile_db, + baseaddr, + offset, + frames, + words, + height=None, + verbose=False): + ''' + Record data structure geometry for the given tile baseaddr + For most tiles there is only one baseaddr, but some like BRAM have multiple + Notes on multiple block types: + https://github.com/SymbiFlow/prjxray/issues/145 + ''' + + bits = tile_db['bits'] + block_type = util.addr2btype(baseaddr) + + assert offset <= 100, (tile_name, offset) + # Few rare cases at X=0 for double width tiles split in half => small negative offset + assert offset >= 0 or "IOB" in tile_name, (tile_name, offset) + assert 1 <= words <= 101 + assert offset + words <= 101, ( + tile_name, offset + words, offset, words, block_type) + + baseaddr_str = '0x%08X' % baseaddr + block = bits.get(block_type, None) + if block is not None: + verbose and print( + "%s: existing defintion for %s" % (tile_name, block_type)) + assert block["baseaddr"] == baseaddr_str + assert block["frames"] == frames + assert block["offset"] == offset, "%s; orig offset %s, new %s" % ( + tile_name, block["offset"], offset) + assert block["words"] == words + + block = bits.setdefault(block_type, {}) + + # FDRI address + block["baseaddr"] = baseaddr_str + # Number of frames this entry is sretched across + # that is the following FDRI addresses are used: range(baseaddr, baseaddr + frames) + block["frames"] = frames + + # Index of first word used within each frame + block["offset"] = offset + + # related to words... + # deprecated field? Don't worry about for now + # DSP has some differences between height and words + block["words"] = words + if height is None: + height = words + block["height"] = height