diff --git a/libs/libfpgabitstream/src/bitstream_manager_utils.cpp b/libs/libfpgabitstream/src/bitstream_manager_utils.cpp index 9a2ef1277..d6575327f 100644 --- a/libs/libfpgabitstream/src/bitstream_manager_utils.cpp +++ b/libs/libfpgabitstream/src/bitstream_manager_utils.cpp @@ -81,6 +81,28 @@ size_t find_bitstream_manager_config_bit_index_in_parent_block( return curr_index; } +/******************************************************************** + * Find the index of a configuration bit in the children bits of its grandparent + *block. We count the index from the parent of current parent block + *******************************************************************/ +size_t find_bitstream_manager_config_bit_index_in_grandparent_block( + const BitstreamManager& bitstream_manager, const ConfigBitId& bit_id) { + size_t curr_index = 0; + ConfigBlockId parent_blk = bitstream_manager.bit_parent_block(bit_id); + ConfigBlockId grandparent_blk = bitstream_manager.block_parent(parent_blk); + for (const ConfigBlockId& cand_blk : bitstream_manager.block_children(grandparent_blk)) { + if (cand_blk != parent_blk) { + curr_index += bitstream_manager.block_bits(cand_blk).size(); + } else { + curr_index += find_bitstream_manager_config_bit_index_in_parent_block(bitstream_manager, bit_id); + break; + } + } + + return curr_index; +} + + /******************************************************************** * Find the total number of configuration bits under a block * As configuration bits are stored only under the leaf blocks, diff --git a/libs/libfpgabitstream/src/bitstream_manager_utils.h b/libs/libfpgabitstream/src/bitstream_manager_utils.h index e427f834c..26d6f35b8 100644 --- a/libs/libfpgabitstream/src/bitstream_manager_utils.h +++ b/libs/libfpgabitstream/src/bitstream_manager_utils.h @@ -25,6 +25,9 @@ std::vector find_bitstream_manager_top_blocks( size_t find_bitstream_manager_config_bit_index_in_parent_block( const BitstreamManager& bitstream_manager, const ConfigBitId& bit_id); +size_t find_bitstream_manager_config_bit_index_in_grandparent_block( + const BitstreamManager& bitstream_manager, const ConfigBitId& bit_id); + size_t rec_find_bitstream_manager_block_sum_of_bits( const BitstreamManager& bitstream_manager, const ConfigBlockId& block); diff --git a/openfpga/src/fpga_bitstream/write_xml_fabric_bitstream.cpp b/openfpga/src/fpga_bitstream/write_xml_fabric_bitstream.cpp index 5e554bb31..4bc60ea42 100644 --- a/openfpga/src/fpga_bitstream/write_xml_fabric_bitstream.cpp +++ b/openfpga/src/fpga_bitstream/write_xml_fabric_bitstream.cpp @@ -72,36 +72,51 @@ static int write_fabric_config_bit_to_xml_file( std::fstream& fp, const BitstreamManager& bitstream_manager, const FabricBitstream& fabric_bitstream, const FabricBitId& fabric_bit, const e_config_protocol_type& config_type, bool fast_xml, - const int& xml_hierarchy_depth, std::string& bl_addr, std::string& wl_addr) { + const int& xml_hierarchy_depth, std::string& bl_addr, std::string& wl_addr, + const BitstreamWriterOption& options) { if (false == valid_file_stream(fp)) { return 1; } write_tab_to_file(fp, xml_hierarchy_depth); fp << " block_hierarchy = - find_bitstream_manager_block_hierarchy(bitstream_manager, config_block); - std::string hie_path; - for (const ConfigBlockId& temp_block : block_hierarchy) { - hie_path += bitstream_manager.block_name(temp_block); - hie_path += std::string("."); - } - hie_path += generate_configurable_memory_data_out_name(); - hie_path += std::string("["); - hie_path += - std::to_string(find_bitstream_manager_config_bit_index_in_parent_block( - bitstream_manager, config_bit)); - hie_path += std::string("]"); - fp << " path=\"" << hie_path << "\">\n"; + if (options.output_path()) { + std::vector block_hierarchy = + find_bitstream_manager_block_hierarchy(bitstream_manager, config_block); + std::string hie_path; + for (size_t iblk = 0; iblk < block_hierarchy.size(); ++iblk) { + /* If enabled, pop the last block name */ + if (options.trim_path() && iblk == block_hierarchy.size() - 1) { + break; + } + hie_path += bitstream_manager.block_name(block_hierarchy[iblk]); + hie_path += std::string("."); + } + hie_path += generate_configurable_memory_data_out_name(); + hie_path += std::string("["); + size_t bit_idx_in_parent_block = find_bitstream_manager_config_bit_index_in_parent_block( + bitstream_manager, config_bit); + if (options.trim_path()) { + bit_idx_in_parent_block = find_bitstream_manager_config_bit_index_in_grandparent_block( + bitstream_manager, config_bit); + } + hie_path += + std::to_string(bit_idx_in_parent_block); + hie_path += std::string("]"); + + fp << " path=\"" << hie_path << "\">\n"; + } switch (config_type) { case CONFIG_MEM_STANDALONE: @@ -196,7 +211,8 @@ static int write_fabric_regional_config_bit_to_xml_file( const FabricBitstream& fabric_bitstream, const FabricBitRegionId& fabric_region, const e_config_protocol_type& config_type, bool fast_xml, - const int& xml_hierarchy_depth) { + const int& xml_hierarchy_depth, + const BitstreamWriterOption& options) { if (false == valid_file_stream(fp)) { return 1; } @@ -228,7 +244,7 @@ static int write_fabric_regional_config_bit_to_xml_file( fabric_bitstream.region_bits(fabric_region)) { status = write_fabric_config_bit_to_xml_file( fp, bitstream_manager, fabric_bitstream, fabric_bit, config_type, - fast_xml, xml_hierarchy_depth + 1, bl_addr, wl_addr); + fast_xml, xml_hierarchy_depth + 1, bl_addr, wl_addr, options); if (1 == status) { return status; } @@ -296,7 +312,7 @@ int write_fabric_bitstream_to_xml_file( fp, bitstream_manager, fabric_bitstream, region, config_protocol.type(), BLWL_PROTOCOL_FLATTEN == config_protocol.bl_protocol_type() && BLWL_PROTOCOL_FLATTEN == config_protocol.wl_protocol_type(), - xml_hierarchy_depth + 1); + xml_hierarchy_depth + 1, options); if (1 == status) { break; }