diff --git a/flow/platforms/asap7/config.mk b/flow/platforms/asap7/config.mk index 873d5dedf1..d61901351a 100644 --- a/flow/platforms/asap7/config.mk +++ b/flow/platforms/asap7/config.mk @@ -1,216 +1,3 @@ -export PLATFORM = asap7 -export PROCESS = 7 - -ifeq ($(LIB_MODEL),) - export LIB_MODEL = NLDM -endif -export LIB_DIR ?= $(PLATFORM_DIR)/lib/$(LIB_MODEL) - -export PLATFORM_TCL = $(PLATFORM_DIR)/liberty_suppressions.tcl - -#Library Setup variable -export TECH_LEF = $(PLATFORM_DIR)/lef/asap7_tech_1x_201209.lef - -export BC_TEMPERATURE = 25C -export TC_TEMPERATURE = 0C -export WC_TEMPERATURE = 100C - -export BC_VOLTAGE = 0.77 -export TC_VOLTAGE = 0.70 -export WC_VOLTAGE = 0.63 - -# Dont use cells to ease congestion -# Specify at least one filler cell if none -export DONT_USE_CELLS = *x1p*_ASAP7* *xp*_ASAP7* -export DONT_USE_CELLS += SDF* ICG* - -export SYNTH_MINIMUM_KEEP_SIZE ?= 1000 - -# BUF_X1, pin (A) = 0.974659. Arbitrarily multiply by 4 -export ABC_LOAD_IN_FF = 3.898 - - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE ?= asap7sc7p5t - -export MAKE_TRACKS = $(PLATFORM_DIR)/openRoad/make_tracks.tcl - -# Define default PDN config -ifeq ($(BLOCKS),) - export PDN_TCL ?= $(PLATFORM_DIR)/openRoad/pdn/grid_strategy-M1-M2-M5-M6.tcl -else - export PDN_TCL ?= $(PLATFORM_DIR)/openRoad/pdn/BLOCKS_grid_strategy.tcl -endif - - -# IO Placer pin layers -export IO_PLACER_H ?= M4 -export IO_PLACER_V ?= M5 - -export MACRO_PLACE_HALO ?= 10 10 - -# the followings create a keep out / halo between -# macro and core rows -export MACRO_ROWS_HALO_X ?= 2 -export MACRO_ROWS_HALO_Y ?= 2 - -export PLACE_DENSITY ?= 0.60 - -# Endcap and Welltie cells -export TAPCELL_TCL ?= $(PLATFORM_DIR)/openRoad/tapcell.tcl - -export SET_RC_TCL = $(PLATFORM_DIR)/setRC.tcl - -# Route options -export MIN_ROUTING_LAYER ?= M2 -export MIN_CLK_ROUTING_LAYER ?= M4 -export MAX_ROUTING_LAYER ?= M7 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/KLayout/asap7.lyt - -# KLayout DRC ruledeck -export KLAYOUT_DRC_FILE = $(PLATFORM_DIR)/drc/asap7.lydrc - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules - -# PLACEHOLDER gets replaced with the appropriate VT tag in the following templates -export BC_NLDM_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib -export BC_CCS_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib -export WC_NLDM_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib -export TC_NLDM_DFF_LIB_FILE_T = $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib -export BC_NLDM_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_FF_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_nldm_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_FF_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib -export BC_CCS_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_FF_ccs_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_ccs_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_FF_ccs_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_ccs_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib -export WC_NLDM_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_SS_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_SS_nldm_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_SS_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_SS_nldm_211120.lib.gz -export TC_NLDM_LIB_FILES_T = $(LIB_DIR)/asap7sc7p5t_AO_PLACEHOLDERVT_TT_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_INVBUF_PLACEHOLDERVT_TT_nldm_220122.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_OA_PLACEHOLDERVT_TT_nldm_211120.lib.gz \ - $(LIB_DIR)/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib \ - $(LIB_DIR)/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_TT_nldm_211120.lib.gz -export FILL_CELLS_T = FILLERxp5_ASAP7_75t_ \ - FILLER_ASAP7_75t_ \ - DECAPx1_ASAP7_75t_ \ - DECAPx2_ASAP7_75t_ \ - DECAPx4_ASAP7_75t_ \ - DECAPx6_ASAP7_75t_ \ - DECAPx10_ASAP7_75t_ - -# Default to RVT if unset -export VT_LIST = $(if $(strip $(ASAP7_USE_VT)), $(ASAP7_USE_VT), RVT) - -# # The first VT in the ASAP7_USE_VT list is the primary VT. The others get added to OTHER_VT -export PRIMARY_VT = $(word 1, $(VT_LIST)) -export PRIMARY_VT_TAG = $(strip $(patsubst %VT, %, $(PRIMARY_VT))) -export OTHER_VT = $(wordlist 2, $(words $(VT_LIST)), $(VT_LIST)) - -## Set cells based on the primary VT first -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT ?= TIEHIx1_ASAP7_75t_$(PRIMARY_VT_TAG) H -export TIELO_CELL_AND_PORT ?= TIELOx1_ASAP7_75t_$(PRIMARY_VT_TAG) L - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS ?= BUFx2_ASAP7_75t_$(PRIMARY_VT_TAG) A Y - -export HOLD_BUF_CELL ?= BUFx2_ASAP7_75t_$(PRIMARY_VT_TAG) - -export ABC_DRIVER_CELL ?= BUFx2_ASAP7_75t_$(PRIMARY_VT_TAG) - -# Fill cells used in fill cell insertion -export FILL_CELLS ?= $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T)) - -export TAP_CELL_NAME ?= TAPCELL_ASAP7_75t_$(PRIMARY_VT_TAG) - -# GDS_FILES has to be = vs. ?= because GDS_FILES gets set in the ORFS Makefile -export GDS_FILES = $(PLATFORM_DIR)/gds/asap7sc7p5t_28_$(PRIMARY_VT_TAG)_220121a.gds - -export SC_LEF ?= $(PLATFORM_DIR)/lef/asap7sc7p5t_28_$(PRIMARY_VT_TAG)_1x_220121a.lef - -# Yosys mapping files -export LATCH_MAP_FILE ?= $(PLATFORM_DIR)/yoSys/cells_latch_$(PRIMARY_VT_TAG).v -export CLKGATE_MAP_FILE ?= $(PLATFORM_DIR)/yoSys/cells_clkgate_$(PRIMARY_VT_TAG).v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/yoSys/cells_adders_$(PRIMARY_VT_TAG).v - -export BC_NLDM_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_NLDM_DFF_LIB_FILE_T)) -export BC_NLDM_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_NLDM_LIB_FILES_T)) -export BC_CCS_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_CCS_LIB_FILES_T)) \ - $(BC_ADDITIONAL_LIBS) -export BC_CCS_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(BC_CCS_DFF_LIB_FILE_T)) - -export WC_NLDM_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(WC_NLDM_DFF_LIB_FILE_T)) -export WC_NLDM_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(WC_NLDM_LIB_FILES_T)) - -export TC_NLDM_DFF_LIB_FILE ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(TC_NLDM_DFF_LIB_FILE_T)) -export TC_NLDM_LIB_FILES ?= $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),$(TC_NLDM_LIB_FILES_T)) - -ifeq ($(CLUSTER_FLOPS),1) - # Add the multi-bit FF for clustering. These are single corner libraries. - export ADDITIONAL_LIBS += $(LIB_DIR)/asap7sc7p5t_DFFHQNH2V2X_$(PRIMARY_VT_TAG)VT_TT_nldm_FAKE.lib \ - $(LIB_DIR)/asap7sc7p5t_DFFHQNV2X_$(PRIMARY_VT_TAG)VT_TT_nldm_FAKE.lib - - export ADDITIONAL_LEFS += $(PLATFORM_DIR)/lef/asap7sc7p5t_DFFHQNH2V2X.lef \ - $(PLATFORM_DIR)/lef/asap7sc7p5t_DFFHQNV2X.lef - export ADDITIONAL_SITES += asap7sc7p5t_pg - export GDS_ALLOW_EMPTY ?= DFFHQN[VH][24].* -endif - -### Add additional files to the variables based on the OTHER_VT list -$(foreach vt_type,$(OTHER_VT),\ - $(eval OTHER_VT_TAG = $(strip $(patsubst %VT, %, $(vt_type)))) \ - $(eval ADDITIONAL_LEFS += $(PLATFORM_DIR)/lef/asap7sc7p5t_28_$(OTHER_VT_TAG)_1x_220121a.lef) \ - $(eval BC_NLDM_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_NLDM_DFF_LIB_FILE_T))) \ - $(eval BC_CCS_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_CCS_DFF_LIB_FILE_T))) \ - $(eval WC_NLDM_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(WC_NLDM_DFF_LIB_FILE_T))) \ - $(eval TC_NLDM_DFF_LIB_FILE += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(TC_NLDM_DFF_LIB_FILE_T))) \ - $(eval BC_NLDM_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_NLDM_LIB_FILES_T))) \ - $(eval BC_CCS_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(BC_CCS_LIB_FILES_T))) \ - $(eval WC_NLDM_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(WC_NLDM_LIB_FILES_T))) \ - $(eval TC_NLDM_LIB_FILES += $(subst PLACEHOLDER,$(OTHER_VT_TAG),$(TC_NLDM_LIB_FILES_T))) \ - $(eval GDS_FILES += $(PLATFORM_DIR)/gds/asap7sc7p5t_28_$(OTHER_VT_TAG)_220121a.gds) \ - $(eval FILL_CELLS += $(addsuffix $(OTHER_VT_TAG), $(FILL_CELLS_T))) \ -) - -# Dont use SC library based on CORNER selection -# -# BC - Best case, fastest -# WC - Worst case, slowest -# TC - Typical case -export CORNER ?= BC -export LIB_FILES += $($(CORNER)_$(LIB_MODEL)_LIB_FILES) -export LIB_FILES += $(ADDITIONAL_LIBS) -export GDS_FILES += $(ADDITIONAL_GDS) -export DB_FILES += $(realpath $($(CORNER)_DB_FILES)) -export TEMPERATURE = $($(CORNER)_TEMPERATURE) -export VOLTAGE = $($(CORNER)_VOLTAGE) - -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD $(VOLTAGE) -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= M1 - -# Allow empty GDS cell -export GDS_ALLOW_EMPTY ?= fakeram.* - -export REMOVE_CELLS_FOR_LEC = TAPCELL* +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/asap7/config.py b/flow/platforms/asap7/config.py new file mode 100755 index 0000000000..f4f6207546 --- /dev/null +++ b/flow/platforms/asap7/config.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python3 +"""Platform configuration for asap7. + +Generates the same variable assignments as config.mk. +Handles VT variant selection, PLACEHOLDER template expansion, +foreach/eval loop for OTHER_VT, and corner-based indirection. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + cfg.set("PLATFORM", "asap7") + cfg.set("PROCESS", "7") + + # LIB_MODEL defaults to NLDM if not set + lib_model = cfg.env("LIB_MODEL", "NLDM") + if not lib_model: + lib_model = "NLDM" + cfg.set("LIB_MODEL", lib_model) + lib_dir = f"{pd}/lib/{lib_model}" + cfg.set("LIB_DIR", lib_dir, conditional=True) + + cfg.set("PLATFORM_TCL", f"{pd}/liberty_suppressions.tcl") + + # Library Setup + cfg.set("TECH_LEF", f"{pd}/lef/asap7_tech_1x_201209.lef") + + cfg.set("BC_TEMPERATURE", "25C") + cfg.set("TC_TEMPERATURE", "0C") + cfg.set("WC_TEMPERATURE", "100C") + + cfg.set("BC_VOLTAGE", "0.77") + cfg.set("TC_VOLTAGE", "0.70") + cfg.set("WC_VOLTAGE", "0.63") + + # Dont use cells + cfg.set("DONT_USE_CELLS", "*x1p*_ASAP7* *xp*_ASAP7*") + cfg.append("DONT_USE_CELLS", "SDF* ICG*") + + cfg.set("SYNTH_MINIMUM_KEEP_SIZE", "1000", conditional=True) + cfg.set("ABC_LOAD_IN_FF", "3.898") + + # Placement site + cfg.set("PLACE_SITE", "asap7sc7p5t", conditional=True) + cfg.set("MAKE_TRACKS", f"{pd}/openRoad/make_tracks.tcl") + + # PDN - conditional on BLOCKS + blocks = cfg.env("BLOCKS") + if not blocks: + cfg.set( + "PDN_TCL", + f"{pd}/openRoad/pdn/grid_strategy-M1-M2-M5-M6.tcl", + conditional=True, + ) + else: + cfg.set( + "PDN_TCL", f"{pd}/openRoad/pdn/BLOCKS_grid_strategy.tcl", conditional=True + ) + + # IO Placer + cfg.set("IO_PLACER_H", "M4", conditional=True) + cfg.set("IO_PLACER_V", "M5", conditional=True) + cfg.set("MACRO_PLACE_HALO", "10 10", conditional=True) + cfg.set("MACRO_ROWS_HALO_X", "2", conditional=True) + cfg.set("MACRO_ROWS_HALO_Y", "2", conditional=True) + cfg.set("PLACE_DENSITY", "0.60", conditional=True) + + # Endcap and Welltie + cfg.set("TAPCELL_TCL", f"{pd}/openRoad/tapcell.tcl", conditional=True) + cfg.set("SET_RC_TCL", f"{pd}/setRC.tcl") + + # Route options + cfg.set("MIN_ROUTING_LAYER", "M2", conditional=True) + cfg.set("MIN_CLK_ROUTING_LAYER", "M4", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "M7", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/KLayout/asap7.lyt") + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/asap7.lydrc") + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # PLACEHOLDER templates + bc_nldm_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib" + bc_ccs_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib" + wc_nldm_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib" + tc_nldm_dff_t = f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib" + + bc_nldm_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_FF_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_nldm_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_FF_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_nldm_220123.lib" + ) + bc_ccs_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_FF_ccs_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_FF_ccs_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_FF_ccs_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_FF_ccs_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_FF_ccs_220123.lib" + ) + wc_nldm_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_SS_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_SS_nldm_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_SS_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_SS_nldm_220123.lib " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_SS_nldm_211120.lib.gz" + ) + tc_nldm_libs_t = ( + f"{lib_dir}/asap7sc7p5t_AO_PLACEHOLDERVT_TT_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_INVBUF_PLACEHOLDERVT_TT_nldm_220122.lib.gz " + f"{lib_dir}/asap7sc7p5t_OA_PLACEHOLDERVT_TT_nldm_211120.lib.gz " + f"{lib_dir}/asap7sc7p5t_SEQ_PLACEHOLDERVT_TT_nldm_220123.lib " + f"{lib_dir}/asap7sc7p5t_SIMPLE_PLACEHOLDERVT_TT_nldm_211120.lib.gz" + ) + + fill_cells_t = [ + "FILLERxp5_ASAP7_75t_", + "FILLER_ASAP7_75t_", + "DECAPx1_ASAP7_75t_", + "DECAPx2_ASAP7_75t_", + "DECAPx4_ASAP7_75t_", + "DECAPx6_ASAP7_75t_", + "DECAPx10_ASAP7_75t_", + ] + + # VT list: default to RVT if ASAP7_USE_VT is unset + asap7_use_vt = cfg.env("ASAP7_USE_VT", "").strip() + vt_list = asap7_use_vt.split() if asap7_use_vt else ["RVT"] + primary_vt = vt_list[0] + primary_vt_tag = primary_vt.replace("VT", "") # RVT -> R, LVT -> L, SLVT -> SL + other_vt = vt_list[1:] + + # Set cells based on primary VT + cfg.set( + "TIEHI_CELL_AND_PORT", f"TIEHIx1_ASAP7_75t_{primary_vt_tag} H", conditional=True + ) + cfg.set( + "TIELO_CELL_AND_PORT", f"TIELOx1_ASAP7_75t_{primary_vt_tag} L", conditional=True + ) + cfg.set( + "MIN_BUF_CELL_AND_PORTS", + f"BUFx2_ASAP7_75t_{primary_vt_tag} A Y", + conditional=True, + ) + cfg.set("HOLD_BUF_CELL", f"BUFx2_ASAP7_75t_{primary_vt_tag}", conditional=True) + cfg.set("ABC_DRIVER_CELL", f"BUFx2_ASAP7_75t_{primary_vt_tag}", conditional=True) + + # Fill cells: $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T)) + cfg.set( + "FILL_CELLS", + " ".join(f"{cell}{primary_vt_tag}" for cell in fill_cells_t), + conditional=True, + ) + + cfg.set("TAP_CELL_NAME", f"TAPCELL_ASAP7_75t_{primary_vt_tag}", conditional=True) + + # GDS_FILES uses = (not ?=) because it gets set in the ORFS Makefile + cfg.set("GDS_FILES", f"{pd}/gds/asap7sc7p5t_28_{primary_vt_tag}_220121a.gds") + + cfg.set( + "SC_LEF", + f"{pd}/lef/asap7sc7p5t_28_{primary_vt_tag}_1x_220121a.lef", + conditional=True, + ) + + # Yosys mapping files + cfg.set( + "LATCH_MAP_FILE", f"{pd}/yoSys/cells_latch_{primary_vt_tag}.v", conditional=True + ) + cfg.set( + "CLKGATE_MAP_FILE", + f"{pd}/yoSys/cells_clkgate_{primary_vt_tag}.v", + conditional=True, + ) + cfg.set( + "ADDER_MAP_FILE", + f"{pd}/yoSys/cells_adders_{primary_vt_tag}.v", + conditional=True, + ) + + # Expand primary VT templates + def expand(template, tag): + return template.replace("PLACEHOLDER", tag) + + cfg.set( + "BC_NLDM_DFF_LIB_FILE", expand(bc_nldm_dff_t, primary_vt_tag), conditional=True + ) + cfg.set( + "BC_NLDM_LIB_FILES", expand(bc_nldm_libs_t, primary_vt_tag), conditional=True + ) + bc_ccs_libs = expand(bc_ccs_libs_t, primary_vt_tag) + bc_additional = cfg.env("BC_ADDITIONAL_LIBS") + if bc_additional: + bc_ccs_libs += f" {bc_additional}" + cfg.set("BC_CCS_LIB_FILES", bc_ccs_libs, conditional=True) + cfg.set( + "BC_CCS_DFF_LIB_FILE", expand(bc_ccs_dff_t, primary_vt_tag), conditional=True + ) + + cfg.set( + "WC_NLDM_DFF_LIB_FILE", expand(wc_nldm_dff_t, primary_vt_tag), conditional=True + ) + cfg.set( + "WC_NLDM_LIB_FILES", expand(wc_nldm_libs_t, primary_vt_tag), conditional=True + ) + + cfg.set( + "TC_NLDM_DFF_LIB_FILE", expand(tc_nldm_dff_t, primary_vt_tag), conditional=True + ) + cfg.set( + "TC_NLDM_LIB_FILES", expand(tc_nldm_libs_t, primary_vt_tag), conditional=True + ) + + # CLUSTER_FLOPS conditional + cluster_flops = cfg.env("CLUSTER_FLOPS") + if cluster_flops == "1": + cfg.append( + "ADDITIONAL_LIBS", + f"{lib_dir}/asap7sc7p5t_DFFHQNH2V2X_{primary_vt_tag}VT_TT_nldm_FAKE.lib " + f"{lib_dir}/asap7sc7p5t_DFFHQNV2X_{primary_vt_tag}VT_TT_nldm_FAKE.lib", + ) + cfg.append( + "ADDITIONAL_LEFS", + f"{pd}/lef/asap7sc7p5t_DFFHQNH2V2X.lef " + f"{pd}/lef/asap7sc7p5t_DFFHQNV2X.lef", + ) + cfg.append("ADDITIONAL_SITES", "asap7sc7p5t_pg") + cfg.set("GDS_ALLOW_EMPTY", "DFFHQN[VH][24].*", conditional=True) + + # foreach/eval loop: expand OTHER_VT templates and append + for vt_type in other_vt: + vt_tag = vt_type.replace("VT", "") # LVT -> L, SLVT -> SL + + cfg.append( + "ADDITIONAL_LEFS", f"{pd}/lef/asap7sc7p5t_28_{vt_tag}_1x_220121a.lef" + ) + cfg.append("BC_NLDM_DFF_LIB_FILE", expand(bc_nldm_dff_t, vt_tag)) + cfg.append("BC_CCS_DFF_LIB_FILE", expand(bc_ccs_dff_t, vt_tag)) + cfg.append("WC_NLDM_DFF_LIB_FILE", expand(wc_nldm_dff_t, vt_tag)) + cfg.append("TC_NLDM_DFF_LIB_FILE", expand(tc_nldm_dff_t, vt_tag)) + cfg.append("BC_NLDM_LIB_FILES", expand(bc_nldm_libs_t, vt_tag)) + cfg.append("BC_CCS_LIB_FILES", expand(bc_ccs_libs_t, vt_tag)) + cfg.append("WC_NLDM_LIB_FILES", expand(wc_nldm_libs_t, vt_tag)) + cfg.append("TC_NLDM_LIB_FILES", expand(tc_nldm_libs_t, vt_tag)) + cfg.append("GDS_FILES", f"{pd}/gds/asap7sc7p5t_28_{vt_tag}_220121a.gds") + cfg.append( + "FILL_CELLS", + " ".join(f"{cell}{vt_tag}" for cell in fill_cells_t), + ) + + # Corner selection via variable indirection + corner = cfg.env("CORNER", "BC") + cfg.set("CORNER", corner, conditional=True) + + # $($(CORNER)_$(LIB_MODEL)_LIB_FILES) + corner_model_key = f"{corner}_{lib_model}_LIB_FILES" + # Map to the right variable we computed above + lib_model_map = { + "BC_NLDM": "BC_NLDM_LIB_FILES", + "BC_CCS": "BC_CCS_LIB_FILES", + "WC_NLDM": "WC_NLDM_LIB_FILES", + "TC_NLDM": "TC_NLDM_LIB_FILES", + } + corner_lib_key = lib_model_map.get( + f"{corner}_{lib_model}", f"{corner}_{lib_model}_LIB_FILES" + ) + corner_lib_files = cfg.get(corner_lib_key, "") + + cfg.append("LIB_FILES", corner_lib_files) + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + cfg.append("LIB_FILES", additional_libs) + + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + cfg.append("GDS_FILES", additional_gds) + + # DB_FILES uses $(realpath $($(CORNER)_DB_FILES)) + corner_db_key = f"{corner}_DB_FILES" + db_files = cfg.get(corner_db_key, cfg.env(corner_db_key, "")) + if db_files: + resolved = " ".join(os.path.realpath(p) for p in db_files.split() if p) + cfg.append("DB_FILES", resolved) + + cfg.set("TEMPERATURE", cfg.get(f"{corner}_TEMPERATURE", "25C")) + cfg.set("VOLTAGE", cfg.get(f"{corner}_VOLTAGE", "0.77")) + + # IR Drop + voltage = cfg.get("VOLTAGE", "0.77") + cfg.set("PWR_NETS_VOLTAGES", f"VDD {voltage}", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "M1", conditional=True) + + # Allow empty GDS + cfg.set("GDS_ALLOW_EMPTY", "fakeram.*", conditional=True) + + cfg.set("REMOVE_CELLS_FOR_LEC", "TAPCELL*") + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/gf180/config.mk b/flow/platforms/gf180/config.mk index 46bbb7b54d..d61901351a 100644 --- a/flow/platforms/gf180/config.mk +++ b/flow/platforms/gf180/config.mk @@ -1,148 +1,3 @@ -#----------------------------------------------------- -# Tech/Libs -# TRACK_OPTION - 9t 7t -# METAL_OPTION - 5LM_1TM -#---------------------------------------------------- -export TRACK_OPTION ?= 9t -export METAL_OPTION ?= 5LM_1TM -export KVALUE ?= 9 -export POWER_OPTION ?= 5v0 -export CORNER ?= BC -export PROCESS = 180 - -#---------------------------------------------------- -# OpenROAD -#---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION)_tech.lef - -export SC_LEF ?= $(PLATFORM_DIR)/lef/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION)_sc.lef - -export GDS_FILES = $(wildcard $(PLATFORM_DIR)/gds/$(TRACK_OPTION)/*.gds) \ - $(ADDITIONAL_GDS) - -# Dont use cells -export DONT_USE_CELLS = *_1 - -# Fill cells used in fill cell insertion -export FILL_CELLS ?= gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_64 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_32 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_16 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_8 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_4 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_2 \ - gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__fill_1 - -export TIE_CELL = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__filltie -export ENDCAP_CELL = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__endcap -export RC_FILE = $(PLATFORM_DIR)/setRC.tcl - -#----------------------------------------------------- -# Yosys -#----------------------------------------------------- - -# set the TIEHI/TIELO cells -export TIEHI_CELL_AND_PORT = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__tieh Z -export TIELO_CELL_AND_PORT = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__tiel ZN - -export ABC_DRIVER_CELL = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__buf_4 -export ABC_LOAD_IN_FF = 0.01343 - -# hold buffer cell -export MIN_BUF_CELL_AND_PORTS = gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__dlya_4 I Z - -# Used in synthesis -export MAX_FANOUT = 20 - -# Yosys mapping files -export LATCH_MAP_FILE ?= $(PLATFORM_DIR)/cells_latch.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders.v - -#-------------------------------------------------------- -# Floorplan -#------------------------------------------------------- -# Placement site for core cells -ifeq ($(TRACK_OPTION),9t) -export PLACE_SITE ?= GF018hv5v_green_sc9 -else -export PLACE_SITE ?= GF018hv5v_mcu_sc7 -endif - -# IO Placer pin layers -export IO_PLACER_H ?= Metal3 -export IO_PLACER_V ?= Metal4 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/openROAD/pdn/pdn_grid_strategy_$(TRACK_OPTION)_6M.cfg - -# Endcap and Welltie cells -export TAPCELL_TCL ?= $(PLATFORM_DIR)/openROAD/tapcell.tcl - -# macro planning -export MACRO_PLACE_HALO ?= 10 10 - -#--------------------------------------------------------- -# Place -#-------------------------------------------------------- -export PLACE_DENSITY ?= 0.40 - -#--------------------------------------------------------- -# Route -#--------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER ?= Metal2 -export MAX_ROUTING_LAYER ?= Metal5 -export DISABLE_VIA_GEN ?= 1 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout layer properties -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/KLayout/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION).lyt -export KLAYOUT_LEF_FILE = $(PLATFORM_DIR)/KLayout/tech_$(TRACK_OPTION)_$(METAL_OPTION).lef -export GDS_LAYER_MAP = $(abspath $(PLATFORM_DIR)/gds/$(TRACK_OPTION)/gf180mcu_$(METAL_OPTION)_$(KVALUE)K_$(TRACK_OPTION)_edi2gds.layermap) - -# For RCX -export BC_RCX_RULES = $(PLATFORM_DIR)/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_bst.rules -export WC_RCX_RULES = $(PLATFORM_DIR)/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_wst.rules -export TC_RCX_RULES = $(PLATFORM_DIR)/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_typ.rules - -export BC_RCX_RC_CORNER = FuncRCmin -export WC_RCX_RC_CORNER = FuncRCmax -export TC_RCX_RC_CORNER = FuncRCtyp - -export RCX_RULES = $($(CORNER)_RCX_RULES) -export RCX_RC_CORNER = $($(CORNER)_RCX_RC_CORNER) - -#---------------------------------------------------------------------------------------------------- -# define libraries - corner dependant setting -#---------------------------------------------------------------------------------------------------- -# standard cell section -#---------------------------------------------------------------------------------------------------- -export BC_LIB_FILES = $(abspath $(PLATFORM_DIR)/lib/gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__ff_n40C_5v50.lib.gz) -export BC_TEMPERATURE = -40c -export BC_VOLTAGE = 5.5 - -export WC_LIB_FILES = $(abspath $(PLATFORM_DIR)/lib/gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__ss_125C_4v50.lib.gz) -export WC_TEMPERATURE = 125c -export WC_VOLTAGE = 4.5 - -export TC_LIB_FILES = $(abspath $(PLATFORM_DIR)/lib/gf180mcu_fd_sc_mcu$(TRACK_OPTION)$(POWER_OPTION)__tt_025C_5v00.lib.gz) -export TC_TEMPERATURE = 25c -export TC_VOLTAGE = 5.0 - -# ---------------------------------------------------------------------------------------------------- -# now, set files from user setting CORNER -# ---------------------------------------------------------------------------------------------------- -export TEMPERATURE = $($(CORNER)_TEMPERATURE) -export VOLTAGE = $($(CORNER)_VOLTAGE) -export LIB_FILES = $($(CORNER)_LIB_FILES) \ - $(ADDITIONAL_LIBS) - -# IR drop estimation supply net name to be analyzed and supply voltage variable -export PWR_NETS_VOLTAGES ?= VDD $(VOLTAGE) -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= Metal1 - -# For proprietary tool enablements that are not public -export GF180_PRIVATE_DIR ?= ../../gf180-private --include $(GF180_PRIVATE_DIR)/private.mk +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/gf180/config.py b/flow/platforms/gf180/config.py new file mode 100755 index 0000000000..68b37dcb21 --- /dev/null +++ b/flow/platforms/gf180/config.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python3 +"""Platform configuration for gf180. + +Generates the same variable assignments as config.mk. +Parameterized by TRACK_OPTION, METAL_OPTION, KVALUE, POWER_OPTION, CORNER. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + # Parameterized options + track = cfg.env("TRACK_OPTION", "9t") + metal = cfg.env("METAL_OPTION", "5LM_1TM") + kvalue = cfg.env("KVALUE", "9") + power = cfg.env("POWER_OPTION", "5v0") + corner = cfg.env("CORNER", "BC") + + cfg.set("TRACK_OPTION", track, conditional=True) + cfg.set("METAL_OPTION", metal, conditional=True) + cfg.set("KVALUE", kvalue, conditional=True) + cfg.set("POWER_OPTION", power, conditional=True) + cfg.set("CORNER", corner, conditional=True) + cfg.set("PROCESS", "180") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/gf180mcu_{metal}_{kvalue}K_{track}_tech.lef") + cfg.set( + "SC_LEF", + f"{pd}/lef/gf180mcu_{metal}_{kvalue}K_{track}_sc.lef", + conditional=True, + ) + + gds = cfg.wildcard_glob(f"{pd}/gds/{track}/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + cfg.set("DONT_USE_CELLS", "*_1") + + # Fill cells + sc = f"gf180mcu_fd_sc_mcu{track}{power}" + cfg.set( + "FILL_CELLS", + f"{sc}__fill_64 {sc}__fill_32 {sc}__fill_16 {sc}__fill_8 {sc}__fill_4 {sc}__fill_2 {sc}__fill_1", + conditional=True, + ) + + cfg.set("TIE_CELL", f"{sc}__filltie") + cfg.set("ENDCAP_CELL", f"{sc}__endcap") + cfg.set("RC_FILE", f"{pd}/setRC.tcl") + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", f"{sc}__tieh Z") + cfg.set("TIELO_CELL_AND_PORT", f"{sc}__tiel ZN") + cfg.set("ABC_DRIVER_CELL", f"{sc}__buf_4") + cfg.set("ABC_LOAD_IN_FF", "0.01343") + cfg.set("MIN_BUF_CELL_AND_PORTS", f"{sc}__dlya_4 I Z") + cfg.set("MAX_FANOUT", "20") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch.v", conditional=True) + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders.v", conditional=True) + + # Floorplan + if track == "9t": + cfg.set("PLACE_SITE", "GF018hv5v_green_sc9", conditional=True) + else: + cfg.set("PLACE_SITE", "GF018hv5v_mcu_sc7", conditional=True) + + cfg.set("IO_PLACER_H", "Metal3", conditional=True) + cfg.set("IO_PLACER_V", "Metal4", conditional=True) + cfg.set( + "PDN_TCL", + f"{pd}/openROAD/pdn/pdn_grid_strategy_{track}_6M.cfg", + conditional=True, + ) + cfg.set("TAPCELL_TCL", f"{pd}/openROAD/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "10 10", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.40", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "Metal2", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "Metal5", conditional=True) + cfg.set("DISABLE_VIA_GEN", "1", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/KLayout/gf180mcu_{metal}_{kvalue}K_{track}.lyt") + cfg.set("KLAYOUT_LEF_FILE", f"{pd}/KLayout/tech_{track}_{metal}.lef") + cfg.set( + "GDS_LAYER_MAP", + os.path.abspath( + f"{pd}/gds/{track}/gf180mcu_{metal}_{kvalue}K_{track}_edi2gds.layermap" + ), + ) + + # RCX - corner-dependent + cfg.set( + "BC_RCX_RULES", f"{pd}/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_bst.rules" + ) + cfg.set( + "WC_RCX_RULES", f"{pd}/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_wst.rules" + ) + cfg.set( + "TC_RCX_RULES", f"{pd}/openROAD/rcx/gf180mcu_1p5m_1tm_9k_sp_smim_OPTB_typ.rules" + ) + + cfg.set("BC_RCX_RC_CORNER", "FuncRCmin") + cfg.set("WC_RCX_RC_CORNER", "FuncRCmax") + cfg.set("TC_RCX_RC_CORNER", "FuncRCtyp") + + # Variable indirection for RCX + rcx_rules = { + "BC": cfg.get("BC_RCX_RULES"), + "WC": cfg.get("WC_RCX_RULES"), + "TC": cfg.get("TC_RCX_RULES"), + } + rcx_corners = {"BC": "FuncRCmin", "WC": "FuncRCmax", "TC": "FuncRCtyp"} + cfg.set("RCX_RULES", rcx_rules.get(corner, rcx_rules["BC"])) + cfg.set("RCX_RC_CORNER", rcx_corners.get(corner, rcx_corners["BC"])) + + # Corner-dependent libraries + bc_lib = os.path.abspath( + f"{pd}/lib/gf180mcu_fd_sc_mcu{track}{power}__ff_n40C_5v50.lib.gz" + ) + wc_lib = os.path.abspath( + f"{pd}/lib/gf180mcu_fd_sc_mcu{track}{power}__ss_125C_4v50.lib.gz" + ) + tc_lib = os.path.abspath( + f"{pd}/lib/gf180mcu_fd_sc_mcu{track}{power}__tt_025C_5v00.lib.gz" + ) + + cfg.set("BC_LIB_FILES", bc_lib) + cfg.set("BC_TEMPERATURE", "-40c") + cfg.set("BC_VOLTAGE", "5.5") + + cfg.set("WC_LIB_FILES", wc_lib) + cfg.set("WC_TEMPERATURE", "125c") + cfg.set("WC_VOLTAGE", "4.5") + + cfg.set("TC_LIB_FILES", tc_lib) + cfg.set("TC_TEMPERATURE", "25c") + cfg.set("TC_VOLTAGE", "5.0") + + # Variable indirection for corner selection + corner_libs = {"BC": bc_lib, "WC": wc_lib, "TC": tc_lib} + corner_temps = {"BC": "-40c", "WC": "125c", "TC": "25c"} + corner_volts = {"BC": "5.5", "WC": "4.5", "TC": "5.0"} + + lib_files = corner_libs.get(corner, corner_libs["BC"]) + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("TEMPERATURE", corner_temps.get(corner, corner_temps["BC"])) + cfg.set("VOLTAGE", corner_volts.get(corner, corner_volts["BC"])) + cfg.set("LIB_FILES", lib_files) + + # IR Drop + voltage = corner_volts.get(corner, corner_volts["BC"]) + cfg.set("PWR_NETS_VOLTAGES", f"VDD {voltage}", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "Metal1", conditional=True) + + # Private dir (skipped: -include private.mk is for vendor-specific additions) + cfg.set("GF180_PRIVATE_DIR", "../../gf180-private", conditional=True) + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/ihp-sg13g2/config.mk b/flow/platforms/ihp-sg13g2/config.mk index 3bd9248abb..d61901351a 100644 --- a/flow/platforms/ihp-sg13g2/config.mk +++ b/flow/platforms/ihp-sg13g2/config.mk @@ -1,181 +1,3 @@ -# Process node -export PROCESS = ihp-sg13g2 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -# Add IO related files when a TCL script is assigned to 'FOOTPRINT_TCL'. -# This variable is used to pass IO information. -export LOAD_ADDITIONAL_FILES ?= 1 -ifneq ($(FOOTPRINT_TCL),) - ifeq ($(LOAD_ADDITIONAL_FILES),1) - export ADDITIONAL_LEFS += $(PLATFORM_DIR)/lef/sg13g2_io.lef \ - $(PLATFORM_DIR)/lef/bondpad_70x70.lef - export ADDITIONAL_SLOW_LIBS += $(PLATFORM_DIR)/lib/sg13g2_io_slow_1p08V_3p0V_125C.lib - export ADDITIONAL_FAST_LIBS += $(PLATFORM_DIR)/lib/sg13g2_io_fast_1p32V_3p6V_m40C.lib - export ADDITIONAL_TYP_LIBS += $(PLATFORM_DIR)/lib/sg13g2_io_typ_1p2V_3p3V_25C.lib - export ADDITIONAL_GDS += $(PLATFORM_DIR)/gds/sg13g2_io.gds \ - $(PLATFORM_DIR)/gds/bondpad_70x70.gds - endif -endif -export TECH_LEF ?= $(PLATFORM_DIR)/lef/sg13g2_tech.lef -export SC_LEF ?= $(PLATFORM_DIR)/lef/sg13g2_stdcell.lef - -export SLOW_LIB_FILES ?= $(PLATFORM_DIR)/lib/sg13g2_stdcell_slow_1p08V_125C.lib \ - $(ADDITIONAL_SLOW_LIBS) -export FAST_LIB_FILES ?= $(PLATFORM_DIR)/lib/sg13g2_stdcell_fast_1p32V_m40C.lib \ - $(ADDITIONAL_FAST_LIBS) -export TYP_LIB_FILES ?= $(PLATFORM_DIR)/lib/sg13g2_stdcell_typ_1p20V_25C.lib \ - $(ADDITIONAL_TYP_LIBS) -export LIB_FILES ?= $(TYP_LIB_FILES) -export GDS_FILES ?= $(PLATFORM_DIR)/gds/sg13g2_stdcell.gds \ - $(ADDITIONAL_GDS) - -# Dont use cells to ease congestion -# Specify at least one filler cell if none - -# The *probe* are for inserting probe points and have metal shapes -# on all layers. -# *lpflow* cells are for multi-power domains -export DONT_USE_CELLS += \ -sg13g2_lgcp_1 \ -sg13g2_sighold \ -sg13g2_slgcp_1 \ -sg13g2_dfrbp_2 - - -# Define fill cells -export FILL_CELLS ?= sg13g2_fill_1 sg13g2_fill_2 sg13g2_decap_4 sg13g2_decap_8 -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = sg13g2_tiehi L_HI -export TIELO_CELL_AND_PORT = sg13g2_tielo L_LO - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = sg13g2_buf_1 A X - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate.v - -# Define ABC driver and load -export ABC_DRIVER_CELL = sg13g2_buf_4 -export ABC_LOAD_IN_FF = 6.0 -ifeq ($(origin ABC_CLOCK_PERIOD_IN_PS), undefined) - ifneq ($(wildcard $(SDC_FILE)),) - # Set yosys-abc clock period to first "clk_period" value or "-period" value found in sdc file - export ABC_CLOCK_PERIOD_IN_PS ?= $(shell sed -nE "s/^set clk_period (.+)|.* -period (.+) .*/\1\2/p" $(SDC_FILE) | head -1 | awk '{print $$1*1000}') - endif -endif - -# ----------------------------------------------------- -# Sizing -# ----------------------------------------------------- - -export MATCH_CELL_FOOTPRINT = 1 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = CoreSite - -# IO Placer pin layers -export IO_PLACER_V ?= Metal2 -export IO_PLACER_H ?= Metal3 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/pdn.tcl - -# To allow the core rings to fit inside the core area -export CORE_MARGIN ?= 17.5 - -# There are no Endcap and Welltie cells in this PDK, so -# `cut_rows` has to be called from the tapcell script. -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl - -export MACRO_PLACE_HALO ?= 40 40 - -# Will be placed left to right -export IO_NORTH_PINS ??= -export IO_SOUTH_PINS ??= -# Will be placed bottom to top -export IO_EAST_PINS ??= -export IO_WEST_PINS ??= - -# Variables for bondpad -export IO_BONDPAD_SIZE ?= 70 -export IO_BONDPAD_NAME ?= bondpad_70x70 -# Variables for padframe -export IO_LENGTH ?= 180 -export IO_WIDTH ?= 80 -export IO_SEALRING_OFFSET ?= 70 -export IO_FILLER_CELLS ?= \ -sg13g2_Filler10000 \ -sg13g2_Filler4000 \ -sg13g2_Filler2000 \ -sg13g2_Filler1000 \ -sg13g2_Filler400 \ -sg13g2_Filler200 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.65 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER ?= Metal2 -export MAX_ROUTING_LAYER ?= Metal5 -#export VIA_IN_PIN_MIN_LAYER ?= Metal1 -#export VIA_IN_PIN_MAX_LAYER ?= Metal1 -#export DISABLE_VIA_GEN ?= 1 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/sg13g2.lyt -# -# Rules for metal fill -export FILL_CONFIG = $(PLATFORM_DIR)/fill.json -# -# Template definition for power grid analysis -#export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules - -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.2 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= Metal1 - -# DRC Check -export KLAYOUT_DRC_FILE ?= $(PLATFORM_DIR)/drc/sg13g2_minimal.lydrc - -#LVS Check -export CDL_FILE ?= $(PLATFORM_DIR)/cdl/sg13g2_stdcell.cdl -#export KLAYOUT_LVS_FILE = $(PLATFORM_DIR)/lvs/$(PLATFORM).lylvs - -export REMOVE_CELLS_FOR_LEC ?= "bondpad_70* sg13g2*" - -# --------------------------------------------------------- -# Final -# --------------------------------------------------------- - -# SRAM macros have empty placeholder cells included. Just ignore them to not -# thrown an error. -export GDS_ALLOW_EMPTY = RM_IHPSG13_\dP_BITKIT_16x2_(CORNER|EDGE_TB|LE_con_corner|LE_con_edge_lr|LE_con_tap_lr|POWER_ramtap|TAP|TAP_LR) +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/ihp-sg13g2/config.py b/flow/platforms/ihp-sg13g2/config.py new file mode 100755 index 0000000000..30ce36e189 --- /dev/null +++ b/flow/platforms/ihp-sg13g2/config.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python3 +"""Platform configuration for ihp-sg13g2. + +Generates the same variable assignments as config.mk. +""" + +import os +import re +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + # Process node + cfg.set("PROCESS", "ihp-sg13g2") + + # Tech/Libs - conditional IO files when FOOTPRINT_TCL is set + cfg.set("LOAD_ADDITIONAL_FILES", "1", conditional=True) + footprint_tcl = cfg.env("FOOTPRINT_TCL") + load_additional = cfg.env("LOAD_ADDITIONAL_FILES", "1") + if footprint_tcl and load_additional == "1": + cfg.append( + "ADDITIONAL_LEFS", f"{pd}/lef/sg13g2_io.lef {pd}/lef/bondpad_70x70.lef" + ) + cfg.append( + "ADDITIONAL_SLOW_LIBS", f"{pd}/lib/sg13g2_io_slow_1p08V_3p0V_125C.lib" + ) + cfg.append( + "ADDITIONAL_FAST_LIBS", f"{pd}/lib/sg13g2_io_fast_1p32V_3p6V_m40C.lib" + ) + cfg.append("ADDITIONAL_TYP_LIBS", f"{pd}/lib/sg13g2_io_typ_1p2V_3p3V_25C.lib") + cfg.append( + "ADDITIONAL_GDS", f"{pd}/gds/sg13g2_io.gds {pd}/gds/bondpad_70x70.gds" + ) + + cfg.set("TECH_LEF", f"{pd}/lef/sg13g2_tech.lef", conditional=True) + cfg.set("SC_LEF", f"{pd}/lef/sg13g2_stdcell.lef", conditional=True) + + additional_slow_libs = cfg.get( + "ADDITIONAL_SLOW_LIBS", cfg.env("ADDITIONAL_SLOW_LIBS") + ) + additional_fast_libs = cfg.get( + "ADDITIONAL_FAST_LIBS", cfg.env("ADDITIONAL_FAST_LIBS") + ) + additional_typ_libs = cfg.get("ADDITIONAL_TYP_LIBS", cfg.env("ADDITIONAL_TYP_LIBS")) + additional_gds = cfg.get("ADDITIONAL_GDS", cfg.env("ADDITIONAL_GDS")) + + slow_lib = f"{pd}/lib/sg13g2_stdcell_slow_1p08V_125C.lib" + if additional_slow_libs: + slow_lib += f" {additional_slow_libs}" + cfg.set("SLOW_LIB_FILES", slow_lib, conditional=True) + + fast_lib = f"{pd}/lib/sg13g2_stdcell_fast_1p32V_m40C.lib" + if additional_fast_libs: + fast_lib += f" {additional_fast_libs}" + cfg.set("FAST_LIB_FILES", fast_lib, conditional=True) + + typ_lib = f"{pd}/lib/sg13g2_stdcell_typ_1p20V_25C.lib" + if additional_typ_libs: + typ_lib += f" {additional_typ_libs}" + cfg.set("TYP_LIB_FILES", typ_lib, conditional=True) + + cfg.set("LIB_FILES", cfg.get("TYP_LIB_FILES", typ_lib), conditional=True) + + gds_files = f"{pd}/gds/sg13g2_stdcell.gds" + if additional_gds: + gds_files += f" {additional_gds}" + cfg.set("GDS_FILES", gds_files, conditional=True) + + # Dont use cells + cfg.append( + "DONT_USE_CELLS", + "sg13g2_lgcp_1 sg13g2_sighold sg13g2_slgcp_1 sg13g2_dfrbp_2", + ) + + # Fill cells + cfg.set( + "FILL_CELLS", + "sg13g2_fill_1 sg13g2_fill_2 sg13g2_decap_4 sg13g2_decap_8", + conditional=True, + ) + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", "sg13g2_tiehi L_HI") + cfg.set("TIELO_CELL_AND_PORT", "sg13g2_tielo L_LO") + cfg.set("MIN_BUF_CELL_AND_PORTS", "sg13g2_buf_1 A X") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate.v") + + cfg.set("ABC_DRIVER_CELL", "sg13g2_buf_4") + cfg.set("ABC_LOAD_IN_FF", "6.0") + + # SDC clock period extraction: $(shell sed ...) + # Replaces: $(origin ABC_CLOCK_PERIOD_IN_PS) check + $(shell sed ...) + awk + if "ABC_CLOCK_PERIOD_IN_PS" not in os.environ: + sdc_file = cfg.env("SDC_FILE") + if sdc_file and os.path.isfile(sdc_file): + with open(sdc_file) as f: + for line in f: + m = re.search( + r"^set\s+clk_period\s+(\S+)|.*-period\s+(\S+)", + line, + ) + if m: + val = m.group(1) or m.group(2) + try: + period_ps = str(float(val) * 1000) + cfg.set( + "ABC_CLOCK_PERIOD_IN_PS", period_ps, conditional=True + ) + except ValueError: + pass + break + + # Sizing + cfg.set("MATCH_CELL_FOOTPRINT", "1") + + # Floorplan + cfg.set("PLACE_SITE", "CoreSite") + cfg.set("IO_PLACER_V", "Metal2", conditional=True) + cfg.set("IO_PLACER_H", "Metal3", conditional=True) + cfg.set("PDN_TCL", f"{pd}/pdn.tcl", conditional=True) + cfg.set("CORE_MARGIN", "17.5", conditional=True) + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "40 40", conditional=True) + + # IO pin variables (??= treated as ?=) + cfg.set("IO_NORTH_PINS", "", conditional=True) + cfg.set("IO_SOUTH_PINS", "", conditional=True) + cfg.set("IO_EAST_PINS", "", conditional=True) + cfg.set("IO_WEST_PINS", "", conditional=True) + + # Bondpad/padframe variables + cfg.set("IO_BONDPAD_SIZE", "70", conditional=True) + cfg.set("IO_BONDPAD_NAME", "bondpad_70x70", conditional=True) + cfg.set("IO_LENGTH", "180", conditional=True) + cfg.set("IO_WIDTH", "80", conditional=True) + cfg.set("IO_SEALRING_OFFSET", "70", conditional=True) + cfg.set( + "IO_FILLER_CELLS", + "sg13g2_Filler10000 sg13g2_Filler4000 sg13g2_Filler2000 sg13g2_Filler1000 sg13g2_Filler400 sg13g2_Filler200", + conditional=True, + ) + + # Place + cfg.set("PLACE_DENSITY", "0.65", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "Metal2", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "Metal5", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/sg13g2.lyt") + cfg.set("FILL_CONFIG", f"{pd}/fill.json") + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.2", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "Metal1", conditional=True) + + # DRC/LVS + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/sg13g2_minimal.lydrc", conditional=True) + cfg.set("CDL_FILE", f"{pd}/cdl/sg13g2_stdcell.cdl", conditional=True) + cfg.set("REMOVE_CELLS_FOR_LEC", "bondpad_70* sg13g2*", conditional=True) + + # Final + cfg.set( + "GDS_ALLOW_EMPTY", + r"RM_IHPSG13_\dP_BITKIT_16x2_(CORNER|EDGE_TB|LE_con_corner|LE_con_edge_lr|LE_con_tap_lr|POWER_ramtap|TAP|TAP_LR)", + ) + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/nangate45/config.mk b/flow/platforms/nangate45/config.mk index d8b60131f4..d61901351a 100644 --- a/flow/platforms/nangate45/config.mk +++ b/flow/platforms/nangate45/config.mk @@ -1,108 +1,3 @@ -# Process node -export PROCESS = 45 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/NangateOpenCellLibrary.tech.lef -export SC_LEF = $(PLATFORM_DIR)/lef/NangateOpenCellLibrary.macro.mod.lef - -export LIB_FILES = $(PLATFORM_DIR)/lib/NangateOpenCellLibrary_typical.lib \ - $(ADDITIONAL_LIBS) -export GDS_FILES = $(sort $(wildcard $(PLATFORM_DIR)/gds/*.gds)) \ - $(ADDITIONAL_GDS) -# Dont use cells to ease congestion -# Specify at least one filler cell if none -export DONT_USE_CELLS = TAPCELL_X1 FILLCELL_X1 AOI211_X1 OAI211_X1 - -# Fill cells used in fill cell insertion -export FILL_CELLS ?= FILLCELL_X1 FILLCELL_X2 FILLCELL_X4 FILLCELL_X8 FILLCELL_X16 FILLCELL_X32 - -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Ungroup size for hierarchical synthesis -export SYNTH_MINIMUM_KEEP_SIZE ?= 10000 -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = LOGIC1_X1 Z -export TIELO_CELL_AND_PORT = LOGIC0_X1 Z - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = BUF_X1 A Z - - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders.v -# -export ABC_DRIVER_CELL = BUF_X1 -# BUF_X1, pin (A) = 0.974659. Arbitrarily multiply by 4 -export ABC_LOAD_IN_FF = 3.898 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = FreePDK45_38x28_10R_NP_162NW_34O - -# IO Placer pin layers -export IO_PLACER_H ?= metal5 -export IO_PLACER_V ?= metal6 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/grid_strategy-M1-M4-M7.tcl - -# Endcap and Welltie cells -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl -export TAP_CELL_NAME = TAPCELL_X1 - -export MACRO_PLACE_HALO ?= 22.4 15.12 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.30 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER = metal2 -export MIN_CLK_ROUTING_LAYER = metal4 -export MAX_ROUTING_LAYER = metal10 - -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/FreePDK45.lyt - -# KLayout DRC ruledeck -export KLAYOUT_DRC_FILE = $(PLATFORM_DIR)/drc/FreePDK45.lydrc - -# KLayout LVS ruledeck -export KLAYOUT_LVS_FILE = $(PLATFORM_DIR)/lvs/FreePDK45.lylvs - -# Allow empty GDS cell -export GDS_ALLOW_EMPTY ?= fakeram.* - -export CDL_FILE = $(PLATFORM_DIR)/cdl/NangateOpenCellLibrary.cdl - -# Template definition for power grid analysis -export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.1 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= metal1 +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/nangate45/config.py b/flow/platforms/nangate45/config.py new file mode 100755 index 0000000000..55d4f18774 --- /dev/null +++ b/flow/platforms/nangate45/config.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Platform configuration for nangate45. + +Generates the same variable assignments as config.mk. +Called by Make via $(shell) or by bazel-orfs for JSON output. + +Usage: + python config.py # Make-compatible output + python config.py --format=json # JSON dict for bazel-orfs +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + + # Process node + cfg.set("PROCESS", "45") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/NangateOpenCellLibrary.tech.lef") + cfg.set("SC_LEF", f"{pd}/lef/NangateOpenCellLibrary.macro.mod.lef") + + lib_files = f"{pd}/lib/NangateOpenCellLibrary_typical.lib" + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("LIB_FILES", lib_files) + + gds = cfg.sorted_glob(f"{pd}/gds/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + cfg.set("DONT_USE_CELLS", "TAPCELL_X1 FILLCELL_X1 AOI211_X1 OAI211_X1") + + # Fill cells + cfg.set( + "FILL_CELLS", + "FILLCELL_X1 FILLCELL_X2 FILLCELL_X4 FILLCELL_X8 FILLCELL_X16 FILLCELL_X32", + conditional=True, + ) + + # Yosys + cfg.set("SYNTH_MINIMUM_KEEP_SIZE", "10000", conditional=True) + cfg.set("TIEHI_CELL_AND_PORT", "LOGIC1_X1 Z") + cfg.set("TIELO_CELL_AND_PORT", "LOGIC0_X1 Z") + cfg.set("MIN_BUF_CELL_AND_PORTS", "BUF_X1 A Z") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate.v") + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders.v", conditional=True) + + cfg.set("ABC_DRIVER_CELL", "BUF_X1") + cfg.set("ABC_LOAD_IN_FF", "3.898") + + # Floorplan + cfg.set("PLACE_SITE", "FreePDK45_38x28_10R_NP_162NW_34O") + cfg.set("IO_PLACER_H", "metal5", conditional=True) + cfg.set("IO_PLACER_V", "metal6", conditional=True) + cfg.set("PDN_TCL", f"{pd}/grid_strategy-M1-M4-M7.tcl", conditional=True) + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("TAP_CELL_NAME", "TAPCELL_X1") + cfg.set("MACRO_PLACE_HALO", "22.4 15.12", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.30", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "metal2") + cfg.set("MIN_CLK_ROUTING_LAYER", "metal4") + cfg.set("MAX_ROUTING_LAYER", "metal10") + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/FreePDK45.lyt") + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/FreePDK45.lydrc") + cfg.set("KLAYOUT_LVS_FILE", f"{pd}/lvs/FreePDK45.lylvs") + + # Allow empty GDS cell + cfg.set("GDS_ALLOW_EMPTY", "fakeram.*", conditional=True) + + cfg.set("CDL_FILE", f"{pd}/cdl/NangateOpenCellLibrary.cdl") + cfg.set("TEMPLATE_PGA_CFG", f"{pd}/template_pga.cfg", conditional=True) + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.1", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "metal1", conditional=True) + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/sky130hd/config.mk b/flow/platforms/sky130hd/config.mk index d8a7f998fd..d61901351a 100644 --- a/flow/platforms/sky130hd/config.mk +++ b/flow/platforms/sky130hd/config.mk @@ -1,153 +1,3 @@ -# Process node -export PROCESS = 130 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hd.tlef -export SC_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hd_merged.lef - -export LIB_FILES = $(PLATFORM_DIR)/lib/sky130_fd_sc_hd__tt_025C_1v80.lib \ - $(ADDITIONAL_LIBS) -export GDS_FILES = $(wildcard $(PLATFORM_DIR)/gds/*.gds) \ - $(ADDITIONAL_GDS) - -# Dont use cells to ease congestion -# Specify at least one filler cell if none - -# The *probe* are for inserting probe points and have metal shapes -# on all layers. -# *lpflow* cells are for multi-power domains -export DONT_USE_CELLS += \ - sky130_fd_sc_hd__probe_p_8 sky130_fd_sc_hd__probec_p_8 \ - sky130_fd_sc_hd__lpflow_bleeder_1 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_1 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_16 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_2 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_4 \ - sky130_fd_sc_hd__lpflow_clkbufkapwr_8 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_1 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_16 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_2 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_4 \ - sky130_fd_sc_hd__lpflow_clkinvkapwr_8 \ - sky130_fd_sc_hd__lpflow_decapkapwr_12 \ - sky130_fd_sc_hd__lpflow_decapkapwr_3 \ - sky130_fd_sc_hd__lpflow_decapkapwr_4 \ - sky130_fd_sc_hd__lpflow_decapkapwr_6 \ - sky130_fd_sc_hd__lpflow_decapkapwr_8 \ - sky130_fd_sc_hd__lpflow_inputiso0n_1 \ - sky130_fd_sc_hd__lpflow_inputiso0p_1 \ - sky130_fd_sc_hd__lpflow_inputiso1n_1 \ - sky130_fd_sc_hd__lpflow_inputiso1p_1 \ - sky130_fd_sc_hd__lpflow_inputisolatch_1 \ - sky130_fd_sc_hd__lpflow_isobufsrc_1 \ - sky130_fd_sc_hd__lpflow_isobufsrc_16 \ - sky130_fd_sc_hd__lpflow_isobufsrc_2 \ - sky130_fd_sc_hd__lpflow_isobufsrc_4 \ - sky130_fd_sc_hd__lpflow_isobufsrc_8 \ - sky130_fd_sc_hd__lpflow_isobufsrckapwr_16 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_1 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_2 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_4 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_4 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_1 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_2 \ - sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_4 -# -# Define fill cells -export FILL_CELLS ?= sky130_fd_sc_hd__fill_1 sky130_fd_sc_hd__fill_2 sky130_fd_sc_hd__fill_4 sky130_fd_sc_hd__fill_8 - -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = sky130_fd_sc_hd__conb_1 HI -export TIELO_CELL_AND_PORT = sky130_fd_sc_hd__conb_1 LO - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = sky130_fd_sc_hd__buf_4 A X - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch_hd.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate_hd.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders_hd.v - -# Define ABC driver and load -export ABC_DRIVER_CELL = sky130_fd_sc_hd__buf_1 -export ABC_LOAD_IN_FF = 5 - -# ----------------------------------------------------- -# Sizing -# ----------------------------------------------------- - -export MATCH_CELL_FOOTPRINT = 1 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = unithd - -# IO Placer pin layers -export IO_PLACER_H ?= met3 -export IO_PLACER_V ?= met2 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/pdn.tcl - -# Endcap and Welltie cells -export TAP_CELL_NAME = sky130_fd_sc_hd__tapvpwrvgnd_1 -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl - -export MACRO_PLACE_HALO ?= 40 40 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.60 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER ?= met1 -export MIN_CLK_ROUTING_LAYER ?= met3 -export MAX_ROUTING_LAYER ?= met5 - -# -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/$(PLATFORM).lyt -# -# Rules for metal fill -export FILL_CONFIG = $(PLATFORM_DIR)/fill.json -# -# Template definition for power grid analysis -export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules - -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.8 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= met1 - -# DRC Check -export KLAYOUT_DRC_FILE = $(PLATFORM_DIR)/drc/$(PLATFORM).lydrc - -#LVS Check -export CDL_FILE = $(PLATFORM_DIR)/cdl/$(PLATFORM).cdl -export KLAYOUT_LVS_FILE = $(PLATFORM_DIR)/lvs/$(PLATFORM).lylvs -export REMOVE_CELLS_FOR_LEC = sky130_fd_sc_hd__tapvpwrvgnd* +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/sky130hd/config.py b/flow/platforms/sky130hd/config.py new file mode 100755 index 0000000000..ee8738be6f --- /dev/null +++ b/flow/platforms/sky130hd/config.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +"""Platform configuration for sky130hd. + +Generates the same variable assignments as config.mk. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + platform = cfg.env("PLATFORM", "sky130hd") + + # Process node + cfg.set("PROCESS", "130") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/sky130_fd_sc_hd.tlef") + cfg.set("SC_LEF", f"{pd}/lef/sky130_fd_sc_hd_merged.lef") + + lib_files = f"{pd}/lib/sky130_fd_sc_hd__tt_025C_1v80.lib" + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("LIB_FILES", lib_files) + + gds = cfg.wildcard_glob(f"{pd}/gds/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + # Dont use cells + cfg.append( + "DONT_USE_CELLS", + "sky130_fd_sc_hd__probe_p_8 sky130_fd_sc_hd__probec_p_8 " + "sky130_fd_sc_hd__lpflow_bleeder_1 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_1 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_16 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_2 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_4 " + "sky130_fd_sc_hd__lpflow_clkbufkapwr_8 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_1 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_16 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_2 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_4 " + "sky130_fd_sc_hd__lpflow_clkinvkapwr_8 " + "sky130_fd_sc_hd__lpflow_decapkapwr_12 " + "sky130_fd_sc_hd__lpflow_decapkapwr_3 " + "sky130_fd_sc_hd__lpflow_decapkapwr_4 " + "sky130_fd_sc_hd__lpflow_decapkapwr_6 " + "sky130_fd_sc_hd__lpflow_decapkapwr_8 " + "sky130_fd_sc_hd__lpflow_inputiso0n_1 " + "sky130_fd_sc_hd__lpflow_inputiso0p_1 " + "sky130_fd_sc_hd__lpflow_inputiso1n_1 " + "sky130_fd_sc_hd__lpflow_inputiso1p_1 " + "sky130_fd_sc_hd__lpflow_inputisolatch_1 " + "sky130_fd_sc_hd__lpflow_isobufsrc_1 " + "sky130_fd_sc_hd__lpflow_isobufsrc_16 " + "sky130_fd_sc_hd__lpflow_isobufsrc_2 " + "sky130_fd_sc_hd__lpflow_isobufsrc_4 " + "sky130_fd_sc_hd__lpflow_isobufsrc_8 " + "sky130_fd_sc_hd__lpflow_isobufsrckapwr_16 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_1 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_2 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_hl_isowell_tap_4 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_4 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_1 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_2 " + "sky130_fd_sc_hd__lpflow_lsbuf_lh_isowell_tap_4", + ) + + # Fill cells + cfg.set( + "FILL_CELLS", + "sky130_fd_sc_hd__fill_1 sky130_fd_sc_hd__fill_2 sky130_fd_sc_hd__fill_4 sky130_fd_sc_hd__fill_8", + conditional=True, + ) + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", "sky130_fd_sc_hd__conb_1 HI") + cfg.set("TIELO_CELL_AND_PORT", "sky130_fd_sc_hd__conb_1 LO") + cfg.set("MIN_BUF_CELL_AND_PORTS", "sky130_fd_sc_hd__buf_4 A X") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch_hd.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate_hd.v") + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders_hd.v", conditional=True) + + cfg.set("ABC_DRIVER_CELL", "sky130_fd_sc_hd__buf_1") + cfg.set("ABC_LOAD_IN_FF", "5") + + # Sizing + cfg.set("MATCH_CELL_FOOTPRINT", "1") + + # Floorplan + cfg.set("PLACE_SITE", "unithd") + cfg.set("IO_PLACER_H", "met3", conditional=True) + cfg.set("IO_PLACER_V", "met2", conditional=True) + cfg.set("PDN_TCL", f"{pd}/pdn.tcl", conditional=True) + cfg.set("TAP_CELL_NAME", "sky130_fd_sc_hd__tapvpwrvgnd_1") + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "40 40", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.60", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "met1", conditional=True) + cfg.set("MIN_CLK_ROUTING_LAYER", "met3", conditional=True) + cfg.set("MAX_ROUTING_LAYER", "met5", conditional=True) + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/{platform}.lyt") + cfg.set("FILL_CONFIG", f"{pd}/fill.json") + cfg.set("TEMPLATE_PGA_CFG", f"{pd}/template_pga.cfg", conditional=True) + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.8", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "met1", conditional=True) + + # DRC/LVS + cfg.set("KLAYOUT_DRC_FILE", f"{pd}/drc/{platform}.lydrc") + cfg.set("CDL_FILE", f"{pd}/cdl/{platform}.cdl") + cfg.set("KLAYOUT_LVS_FILE", f"{pd}/lvs/{platform}.lylvs") + cfg.set("REMOVE_CELLS_FOR_LEC", "sky130_fd_sc_hd__tapvpwrvgnd*") + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/platforms/sky130hs/config.mk b/flow/platforms/sky130hs/config.mk index 1cf050536c..d61901351a 100644 --- a/flow/platforms/sky130hs/config.mk +++ b/flow/platforms/sky130hs/config.mk @@ -1,108 +1,3 @@ -# Process node -export PROCESS = 130 - -#----------------------------------------------------- -# Tech/Libs -# ---------------------------------------------------- -export TECH_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hs.tlef -export SC_LEF = $(PLATFORM_DIR)/lef/sky130_fd_sc_hs_merged.lef - -export LIB_FILES = $(PLATFORM_DIR)/lib/sky130_fd_sc_hs__tt_025C_1v80.lib \ - $(ADDITIONAL_LIBS) -export GDS_FILES = $(wildcard $(PLATFORM_DIR)/gds/*.gds) \ - $(ADDITIONAL_GDS) - -# Dont use cells to ease congestion -# Specify at least one filler cell if none -export DONT_USE_CELLS += - -# Define fill cells -export FILL_CELLS ?= sky130_fd_sc_hs__fill_1 sky130_fd_sc_hs__fill_2 sky130_fd_sc_hs__fill_4 sky130_fd_sc_hs__fill_8 - -# ----------------------------------------------------- -# Yosys -# ---------------------------------------------------- -# Set the TIEHI/TIELO cells -# These are used in yosys synthesis to avoid logical 1/0's in the netlist -export TIEHI_CELL_AND_PORT = sky130_fd_sc_hs__conb_1 HI -export TIELO_CELL_AND_PORT = sky130_fd_sc_hs__conb_1 LO - -# Used in synthesis -export MIN_BUF_CELL_AND_PORTS = sky130_fd_sc_hs__buf_4 A X - - -# Yosys mapping files -export LATCH_MAP_FILE = $(PLATFORM_DIR)/cells_latch_hs.v -export CLKGATE_MAP_FILE = $(PLATFORM_DIR)/cells_clkgate_hs.v -export ADDER_MAP_FILE ?= $(PLATFORM_DIR)/cells_adders_hs.v -# -# Define ABC driver and load -export ABC_DRIVER_CELL = sky130_fd_sc_hs__buf_1 -export ABC_LOAD_IN_FF = 5 - -# ----------------------------------------------------- -# Sizing -# ----------------------------------------------------- - -export MATCH_CELL_FOOTPRINT = 1 - -#-------------------------------------------------------- -# Floorplan -# ------------------------------------------------------- - -# Placement site for core cells -# This can be found in the technology lef -export PLACE_SITE = unit - -# IO Placer pin layers -export IO_PLACER_H ?= met3 -export IO_PLACER_V ?= met2 - -# Define default PDN config -export PDN_TCL ?= $(PLATFORM_DIR)/pdn.tcl - -# Endcap and Welltie cells -export TAP_CELL_NAME = sky130_fd_sc_hs__tapvpwrvgnd_1 -export TAPCELL_TCL ?= $(PLATFORM_DIR)/tapcell.tcl - -export MACRO_PLACE_HALO ?= 40 40 - -#--------------------------------------------------------- -# Place -# -------------------------------------------------------- -export PLACE_DENSITY ?= 0.50 - -# --------------------------------------------------------- -# Route -# --------------------------------------------------------- -# FastRoute options -export MIN_ROUTING_LAYER = met1 -export MIN_CLK_ROUTING_LAYER = met3 -export MAX_ROUTING_LAYER = met5 - -# -# Define fastRoute tcl -export FASTROUTE_TCL ?= $(PLATFORM_DIR)/fastroute.tcl - - -# KLayout technology file -export KLAYOUT_TECH_FILE = $(PLATFORM_DIR)/$(PLATFORM).lyt -# -# Rules for metal fill -export FILL_CONFIG = $(PLATFORM_DIR)/fill.json -# -# Template definition for power grid analysis -export TEMPLATE_PGA_CFG ?= $(PLATFORM_DIR)/template_pga.cfg - -# OpenRCX extRules -export RCX_RULES = $(PLATFORM_DIR)/rcx_patterns.rules -# --------------------------------------------------------- -# IR Drop -# --------------------------------------------------------- - -# IR drop estimation supply net name to be analyzed and supply voltage variable -# For multiple nets: PWR_NETS_VOLTAGES = "VDD1 1.8 VDD2 1.2" -export PWR_NETS_VOLTAGES ?= VDD 1.8 -export GND_NETS_VOLTAGES ?= VSS 0.0 -export IR_DROP_LAYER ?= met1 -export REMOVE_CELLS_FOR_LEC = sky130_fd_sc_hs__tapvpwrvgnd* \ No newline at end of file +# Platform configuration generated by config.py +# Same pattern as defaults.py in variables.mk:44 +$(foreach line,$(shell $(PYTHON_EXE) $(PLATFORM_DIR)/config.py),$(eval export $(subst __SPACE__, ,$(line)))) diff --git a/flow/platforms/sky130hs/config.py b/flow/platforms/sky130hs/config.py new file mode 100755 index 0000000000..2848807ebf --- /dev/null +++ b/flow/platforms/sky130hs/config.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +"""Platform configuration for sky130hs. + +Generates the same variable assignments as config.mk. +""" + +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "scripts")) +from platform_config_utils import PlatformConfig + + +def get_config(platform_dir=None): + cfg = PlatformConfig(platform_dir) + pd = cfg.platform_dir + platform = cfg.env("PLATFORM", "sky130hs") + + # Process node + cfg.set("PROCESS", "130") + + # Tech/Libs + cfg.set("TECH_LEF", f"{pd}/lef/sky130_fd_sc_hs.tlef") + cfg.set("SC_LEF", f"{pd}/lef/sky130_fd_sc_hs_merged.lef") + + lib_files = f"{pd}/lib/sky130_fd_sc_hs__tt_025C_1v80.lib" + additional_libs = cfg.env("ADDITIONAL_LIBS") + if additional_libs: + lib_files += f" {additional_libs}" + cfg.set("LIB_FILES", lib_files) + + gds = cfg.wildcard_glob(f"{pd}/gds/*.gds") + additional_gds = cfg.env("ADDITIONAL_GDS") + if additional_gds: + gds += f" {additional_gds}" + cfg.set("GDS_FILES", gds) + + # DONT_USE_CELLS += (empty in sky130hs) + # Only append if there's something to append from env + dont_use = cfg.env("DONT_USE_CELLS") + if dont_use: + cfg.set("DONT_USE_CELLS", dont_use) + + # Fill cells + cfg.set( + "FILL_CELLS", + "sky130_fd_sc_hs__fill_1 sky130_fd_sc_hs__fill_2 sky130_fd_sc_hs__fill_4 sky130_fd_sc_hs__fill_8", + conditional=True, + ) + + # Yosys + cfg.set("TIEHI_CELL_AND_PORT", "sky130_fd_sc_hs__conb_1 HI") + cfg.set("TIELO_CELL_AND_PORT", "sky130_fd_sc_hs__conb_1 LO") + cfg.set("MIN_BUF_CELL_AND_PORTS", "sky130_fd_sc_hs__buf_4 A X") + + # Yosys mapping files + cfg.set("LATCH_MAP_FILE", f"{pd}/cells_latch_hs.v") + cfg.set("CLKGATE_MAP_FILE", f"{pd}/cells_clkgate_hs.v") + cfg.set("ADDER_MAP_FILE", f"{pd}/cells_adders_hs.v", conditional=True) + + cfg.set("ABC_DRIVER_CELL", "sky130_fd_sc_hs__buf_1") + cfg.set("ABC_LOAD_IN_FF", "5") + + # Sizing + cfg.set("MATCH_CELL_FOOTPRINT", "1") + + # Floorplan + cfg.set("PLACE_SITE", "unit") + cfg.set("IO_PLACER_H", "met3", conditional=True) + cfg.set("IO_PLACER_V", "met2", conditional=True) + cfg.set("PDN_TCL", f"{pd}/pdn.tcl", conditional=True) + cfg.set("TAP_CELL_NAME", "sky130_fd_sc_hs__tapvpwrvgnd_1") + cfg.set("TAPCELL_TCL", f"{pd}/tapcell.tcl", conditional=True) + cfg.set("MACRO_PLACE_HALO", "40 40", conditional=True) + + # Place + cfg.set("PLACE_DENSITY", "0.50", conditional=True) + + # Route + cfg.set("MIN_ROUTING_LAYER", "met1") + cfg.set("MIN_CLK_ROUTING_LAYER", "met3") + cfg.set("MAX_ROUTING_LAYER", "met5") + cfg.set("FASTROUTE_TCL", f"{pd}/fastroute.tcl", conditional=True) + + # KLayout + cfg.set("KLAYOUT_TECH_FILE", f"{pd}/{platform}.lyt") + cfg.set("FILL_CONFIG", f"{pd}/fill.json") + cfg.set("TEMPLATE_PGA_CFG", f"{pd}/template_pga.cfg", conditional=True) + + # OpenRCX + cfg.set("RCX_RULES", f"{pd}/rcx_patterns.rules") + + # IR Drop + cfg.set("PWR_NETS_VOLTAGES", "VDD 1.8", conditional=True) + cfg.set("GND_NETS_VOLTAGES", "VSS 0.0", conditional=True) + cfg.set("IR_DROP_LAYER", "met1", conditional=True) + + cfg.set("REMOVE_CELLS_FOR_LEC", "sky130_fd_sc_hs__tapvpwrvgnd*") + + return cfg + + +if __name__ == "__main__": + get_config().output() diff --git a/flow/scripts/platform_config_utils.py b/flow/scripts/platform_config_utils.py new file mode 100644 index 0000000000..717b1cc0ab --- /dev/null +++ b/flow/scripts/platform_config_utils.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +"""Shared utilities for platform config.py files. + +Each platform's config.py uses PlatformConfig to accumulate variables +and output them in Make-compatible or JSON format. This follows the +same pattern as defaults.py: Python generates Make code that Make +$(eval)s back into itself. +""" + +import glob +import json +import os +import sys + + +class PlatformConfig: + """Accumulates platform configuration variables and outputs them. + + Maintains ordered list of (key, value, conditional) tuples. + conditional=True means ?= (only set if not already defined). + conditional=False means = (unconditional assignment). + """ + + def __init__(self, platform_dir=None): + if platform_dir is not None: + self.platform_dir = platform_dir + else: + self.platform_dir = os.environ.get( + "PLATFORM_DIR", + os.path.dirname( + os.path.abspath(sys._getframe(1).f_globals["__file__"]) + ), + ) + self.platform = os.environ.get("PLATFORM", os.path.basename(self.platform_dir)) + self._vars = [] # ordered list of (key, value, conditional) + self._index = {} # key -> index in _vars for fast lookup + + def env(self, key, default=""): + """Read a variable from the environment.""" + return os.environ.get(key, default) + + def set(self, key, value, conditional=False): + """Set a variable. conditional=True means ?= semantics.""" + value = str(value) + if conditional and key in self._index: + # Already set internally, skip conditional + return + if conditional and key in os.environ: + # Already set in environment, use env value + value = os.environ[key] + conditional = False + if key in self._index: + self._vars[self._index[key]] = (key, value, conditional) + else: + self._index[key] = len(self._vars) + self._vars.append((key, value, conditional)) + + def append(self, key, value): + """Append to a variable (like Make +=). + + If the key exists internally, appends to that value. + Otherwise reads current value from environment first. + """ + value = str(value) + if key in self._index: + existing = self._vars[self._index[key]][1] + combined = (existing + " " + value).strip() + self._vars[self._index[key]] = (key, combined, False) + else: + existing = os.environ.get(key, "") + combined = (existing + " " + value).strip() + self._index[key] = len(self._vars) + self._vars.append((key, combined, False)) + + def get(self, key, default=""): + """Get a variable's current value (from internal state).""" + if key in self._index: + return self._vars[self._index[key]][1] + return default + + def sorted_glob(self, pattern): + """sorted(glob.glob(pattern)) -- replaces $(sort $(wildcard ...))""" + return " ".join(sorted(glob.glob(pattern))) + + def wildcard_glob(self, pattern): + """glob.glob(pattern) -- replaces $(wildcard ...)""" + return " ".join(glob.glob(pattern)) + + def _unexpand(self, value): + """Replace expanded paths with Make variable references. + + Consumers expand these on their end: + - Make: $(eval) expands $(PLATFORM_DIR) and $(PLATFORM) + - bazel-orfs: Python substitution when the rule executes + """ + # Replace platform_dir first (longer, more specific) + value = value.replace(self.platform_dir, "$(PLATFORM_DIR)") + # Replace platform name within $(PLATFORM_DIR)/... paths only + # e.g. $(PLATFORM_DIR)/sky130hd.lyt -> $(PLATFORM_DIR)/$(PLATFORM).lyt + if self.platform: + value = value.replace( + "$(PLATFORM_DIR)/" + self.platform, + "$(PLATFORM_DIR)/$(PLATFORM)", + ) + # Also in subdirectories: $(PLATFORM_DIR)/drc/sky130hd.lydrc + value = value.replace( + "/" + self.platform + ".", + "/$(PLATFORM).", + ) + return value + + def output_make(self): + """Print Make-compatible output lines. + + Format matches defaults.py: export KEY=VALUE or export KEY?=VALUE + with spaces replaced by __SPACE__. + """ + for key, value, conditional in self._vars: + op = "?=" if conditional else "=" + value = self._unexpand(value) + encoded = value.replace(" ", "__SPACE__") + print(f"export {key}{op}{encoded}") + + def output_json(self): + """Print flat JSON dict for bazel-orfs or other consumers.""" + result = {} + for key, value, _conditional in self._vars: + result[key] = self._unexpand(value) + json.dump(result, sys.stdout, indent=2) + print() # trailing newline + + def output(self): + """Select output mode based on --format=json argument.""" + if "--format=json" in sys.argv: + self.output_json() + else: + self.output_make() + + def to_dict(self): + """Return flat dict of all variables (for testing).""" + result = {} + for key, value, _conditional in self._vars: + result[key] = value + return result diff --git a/flow/scripts/variables.md b/flow/scripts/variables.md new file mode 100644 index 0000000000..334643dada --- /dev/null +++ b/flow/scripts/variables.md @@ -0,0 +1,113 @@ +# Platform config.py variable rules + +Rules for writing and consuming platform `config.py` files. + +## Path variables must stay symbolic + +Output values must use `$(PLATFORM_DIR)/...` and `$(PLATFORM)`, never +baked-in absolute paths. Consumers expand on their end: + +- **Make shim**: `$(eval)` expands `$(PLATFORM_DIR)` and `$(PLATFORM)` + naturally, matching the original config.mk behavior. +- **bazel-orfs**: Python string substitution when the Bazel rule + executes. The sandbox has platform files at a different path than + the developer's machine. + +`PlatformConfig._unexpand()` handles this automatically at output time. + +### Variables that use $(PLATFORM_DIR) + +All 6 platforms. Every path-valued variable: `TECH_LEF`, `SC_LEF`, +`LIB_FILES`, `GDS_FILES`, `PDN_TCL`, `TAPCELL_TCL`, `FASTROUTE_TCL`, +`KLAYOUT_TECH_FILE`, `RCX_RULES`, `LATCH_MAP_FILE`, etc. + +### Variables that use $(PLATFORM) + +sky130hd, sky130hs only. Used in filenames within `$(PLATFORM_DIR)`: +`KLAYOUT_TECH_FILE`, `KLAYOUT_DRC_FILE`, `CDL_FILE`, `KLAYOUT_LVS_FILE`. + +Example: `$(PLATFORM_DIR)/$(PLATFORM).lyt` not `$(PLATFORM_DIR)/sky130hd.lyt`. + +## Assignment semantics + +| Syntax | PlatformConfig method | Behavior | +|--------|----------------------|----------| +| `=` | `cfg.set(key, val)` | Unconditional. Always sets. | +| `?=` | `cfg.set(key, val, conditional=True)` | Set only if not already defined (internally or in env). | +| `+=` | `cfg.append(key, val)` | Append to existing value. Reads env if not set internally. | + +## Glob results + +`$(sort $(wildcard ...))` and `$(wildcard ...)` require real filesystem +paths at config.py runtime. `PlatformConfig.sorted_glob()` and +`wildcard_glob()` use the real `platform_dir` for glob operations. +The `_unexpand()` step replaces the prefix back to `$(PLATFORM_DIR)` +in output. + +## Environment variable inputs + +These env vars are **read** by config.py to control logic but do NOT +appear as `$(...)` references in output: + +| Input | Platforms | Purpose | +|-------|-----------|---------| +| `CORNER` | asap7, gf180 | Select lib files (BC/WC/TC) | +| `TRACK_OPTION` | gf180 | Track variant (9t/7t) | +| `METAL_OPTION` | gf180 | Metal stack (5LM_1TM) | +| `KVALUE` | gf180 | K value (9/11) | +| `POWER_OPTION` | gf180 | Power variant (5v0/3v3) | +| `LIB_MODEL` | asap7 | NLDM or CCS | +| `ASAP7_USE_VT` | asap7 | VT list (RVT LVT SLVT) | +| `CLUSTER_FLOPS` | asap7 | Enable flop clustering | +| `BLOCKS` | asap7 | Hierarchical block PDN | +| `FOOTPRINT_TCL` | ihp-sg13g2 | IO placement file | +| `LOAD_ADDITIONAL_FILES` | ihp-sg13g2 | Enable IO libs/lefs | +| `SDC_FILE` | ihp-sg13g2 | Parsed for clock period | +| `ABC_CLOCK_PERIOD_IN_PS` | ihp-sg13g2 | Override clock period | + +These env vars are **concatenated into output values** (their content +is embedded in variables like `LIB_FILES`, `GDS_FILES`): + +| Input | Output vars | Platforms | +|-------|-------------|-----------| +| `ADDITIONAL_LIBS` | `LIB_FILES` | all 6 | +| `ADDITIONAL_GDS` | `GDS_FILES` | all 6 | +| `ADDITIONAL_LEFS` | `ADDITIONAL_LEFS` | ihp-sg13g2, asap7 | +| `ADDITIONAL_SLOW_LIBS` | `SLOW_LIB_FILES` | ihp-sg13g2 | +| `ADDITIONAL_FAST_LIBS` | `FAST_LIB_FILES` | ihp-sg13g2 | +| `ADDITIONAL_TYP_LIBS` | `TYP_LIB_FILES` | ihp-sg13g2 | +| `BC_ADDITIONAL_LIBS` | `BC_CCS_LIB_FILES` | asap7 | + +In Make, these come from design configs as concrete paths. In bazel-orfs, +the Bazel rule provides them — no `$(...)` syntax. + +## Why variables.mk does not need porting + +`variables.mk` computes tool paths (`OPENROAD_EXE`, `YOSYS_EXE`, +`KLAYOUT_CMD`), output directories (`LOG_DIR`, `RESULTS_DIR`), macro +wrappers (`WRAPPED_LEFS`), stream format selection (`GDS` vs `OAS`), +and Make debugging introspection. This is Make-flow plumbing that +bazel-orfs replaces with Bazel-native equivalents. The only shared +concern is platform config variables, which `config.py` provides. + +## Make functions already resolved by config.py + +These Make constructs appeared in the original config.mk files. config.py +resolves all of them — none leak into output: + +| Make function | Python equivalent | Platforms | +|---------------|-------------------|-----------| +| `$(sort $(wildcard ...))` | `sorted_glob()` | nangate45 | +| `$(wildcard ...)` | `wildcard_glob()` | sky130hd, sky130hs, gf180 | +| `$(abspath ...)` | `os.path.abspath()` | gf180 | +| `$(realpath ...)` | `os.path.realpath()` | asap7 | +| `$(origin VAR)` | `"VAR" in os.environ` | ihp-sg13g2 | +| `$(shell sed ...)` | `re.search()` | ihp-sg13g2 | +| `$(foreach)/$(eval)` | `for` loop | asap7 | +| `$(subst ...)` | `str.replace()` | asap7 | +| `$(patsubst ...)` | `str.replace()` | asap7 | +| `$(addsuffix ...)` | string concat | asap7 | +| `$(word N,...)` | `str.split()[N]` | asap7 | +| `$(wordlist ...)` | `str.split()[N:]` | asap7 | +| `$(strip ...)` | `str.strip()` | asap7 | +| `$(if ...)` | `if` statement | asap7 | diff --git a/flow/scripts/variables.mk b/flow/scripts/variables.mk index d6f0712079..0381710005 100644 --- a/flow/scripts/variables.mk +++ b/flow/scripts/variables.mk @@ -37,6 +37,10 @@ else $(error [ERROR][FLOW] Platform '$(PLATFORM)' not found.) endif +# PYTHON_EXE must be defined before including config.mk, as +# config.mk may use $(shell $(PYTHON_EXE) ...) to generate variables. +export PYTHON_EXE ?= $(shell command -v python3) + include $(PLATFORM_DIR)/config.mk # __SPACE__ is a workaround for whitespace hell in "foreach"; there @@ -70,7 +74,6 @@ export NUM_CORES #------------------------------------------------------------------------------- # setup all commands used within this flow -export PYTHON_EXE ?= $(shell command -v python3) export TIME_BIN ?= env time TIME_CMD = $(TIME_BIN) -f 'Elapsed time: %E[h:]min:sec. CPU time: user %U sys %S (%P). Peak memory: %MKB.' diff --git a/flow/test/test_platform_config.py b/flow/test/test_platform_config.py new file mode 100644 index 0000000000..88d6638adb --- /dev/null +++ b/flow/test/test_platform_config.py @@ -0,0 +1,1165 @@ +#!/usr/bin/env python3 +"""Tests for platform config.py files. + +Covers every Make construct used across all 6 platform config.mk files. +Tests are organized by use-case (Make construct) and by platform. + +Run: python -m unittest flow.test.test_platform_config -v +Integration: RUN_INTEGRATION=1 python -m unittest flow.test.test_platform_config -v +""" + +import io +import json +import os +import shutil +import subprocess +import sys +import tempfile +import textwrap +import unittest +from contextlib import redirect_stdout +from unittest.mock import patch + +# Add scripts dir to path for imports +FLOW_DIR = os.path.join(os.path.dirname(__file__), "..") +sys.path.insert(0, os.path.join(FLOW_DIR, "scripts")) + +from platform_config_utils import PlatformConfig + +# Import platform config modules +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "nangate45")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "sky130hs")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "sky130hd")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "gf180")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "ihp-sg13g2")) +sys.path.insert(0, os.path.join(FLOW_DIR, "platforms", "asap7")) + +# We import via importlib to handle the hyphenated directory name +import importlib.util + + +def _load_config_module(platform_name): + """Load a platform's config.py module by path.""" + if platform_name == "ihp-sg13g2": + dirname = "ihp-sg13g2" + else: + dirname = platform_name + spec = importlib.util.spec_from_file_location( + f"config_{platform_name.replace('-', '_')}", + os.path.join(FLOW_DIR, "platforms", dirname, "config.py"), + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + + +nangate45_config = _load_config_module("nangate45") +sky130hs_config = _load_config_module("sky130hs") +sky130hd_config = _load_config_module("sky130hd") +gf180_config = _load_config_module("gf180") +ihp_config = _load_config_module("ihp-sg13g2") +asap7_config = _load_config_module("asap7") + +PLATFORMS = ["nangate45", "sky130hs", "sky130hd", "gf180", "ihp-sg13g2", "asap7"] +PLATFORM_MODULES = { + "nangate45": nangate45_config, + "sky130hs": sky130hs_config, + "sky130hd": sky130hd_config, + "gf180": gf180_config, + "ihp-sg13g2": ihp_config, + "asap7": asap7_config, +} + +# Environment variables to clean before each test +ENV_VARS_TO_CLEAN = [ + "ADDITIONAL_LIBS", + "ADDITIONAL_GDS", + "ADDITIONAL_LEFS", + "BLOCKS", + "CORNER", + "ASAP7_USE_VT", + "LIB_MODEL", + "CLUSTER_FLOPS", + "FOOTPRINT_TCL", + "LOAD_ADDITIONAL_FILES", + "TRACK_OPTION", + "METAL_OPTION", + "KVALUE", + "POWER_OPTION", + "SDC_FILE", + "ABC_CLOCK_PERIOD_IN_PS", + "DONT_USE_CELLS", + "BC_ADDITIONAL_LIBS", + "ADDITIONAL_SLOW_LIBS", + "ADDITIONAL_FAST_LIBS", + "ADDITIONAL_TYP_LIBS", +] + + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- +def get_platform_dir(platform): + return os.path.abspath(os.path.join(FLOW_DIR, "platforms", platform)) + + +def make_clean_env(platform, extras=None): + """Return an env dict for use with patch.dict(os.environ, ...).""" + env = { + "PLATFORM_DIR": get_platform_dir(platform), + "PLATFORM": platform, + } + if extras: + env.update(extras) + return env + + +def clean_and_get_config(platform, extras=None): + """Clean env, run get_config, return dict. Must be called inside patch.dict.""" + cfg = PLATFORM_MODULES[platform].get_config() + return cfg.to_dict() + + +class PlatformTestCase(unittest.TestCase): + """Base class that cleans environment variables in setUp.""" + + def setUp(self): + self._saved_env = {} + for var in ENV_VARS_TO_CLEAN: + if var in os.environ: + self._saved_env[var] = os.environ.pop(var) + + def tearDown(self): + # Remove any vars we may have set + for var in ENV_VARS_TO_CLEAN: + os.environ.pop(var, None) + # Restore original values + os.environ.update(self._saved_env) + + def run_with_env(self, platform, extras=None): + """Set up env and return config dict.""" + env = make_clean_env(platform, extras) + os.environ.update(env) + return clean_and_get_config(platform, extras) + + +# =================================================================== +# 1. PlatformConfig utility tests +# =================================================================== +class TestPlatformConfigUtility(unittest.TestCase): + def test_set_unconditional(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "bar") + d = cfg.to_dict() + self.assertEqual(d["FOO"], "bar") + + def test_set_conditional_default(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "default_val", conditional=True) + d = cfg.to_dict() + self.assertEqual(d["FOO"], "default_val") + + def test_set_conditional_override_from_env(self): + with patch.dict(os.environ, {"FOO": "from_env"}): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "default_val", conditional=True) + d = cfg.to_dict() + self.assertEqual(d["FOO"], "from_env") + + def test_set_conditional_does_not_overwrite_internal(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "first") + cfg.set("FOO", "second", conditional=True) + d = cfg.to_dict() + self.assertEqual(d["FOO"], "first") + + def test_append_internal(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "a b") + cfg.append("FOO", "c d") + d = cfg.to_dict() + self.assertEqual(d["FOO"], "a b c d") + + def test_append_from_env(self): + with patch.dict(os.environ, {"FOO": "from_env"}): + cfg = PlatformConfig(platform_dir="/fake") + cfg.append("FOO", "extra") + d = cfg.to_dict() + self.assertEqual(d["FOO"], "from_env extra") + + def test_append_new_var(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.append("FOO", "value") + d = cfg.to_dict() + self.assertEqual(d["FOO"], "value") + + def test_get(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("FOO", "bar") + self.assertEqual(cfg.get("FOO"), "bar") + self.assertEqual(cfg.get("MISSING", "default"), "default") + + def test_output_make(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("SIMPLE", "value") + cfg.set("SPACES", "a b c") + cfg.set("COND", "default", conditional=True) + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_make() + lines = buf.getvalue().strip().split("\n") + self.assertIn("export SIMPLE=value", lines) + self.assertIn("export SPACES=a__SPACE__b__SPACE__c", lines) + self.assertIn("export COND?=default", lines) + + def test_output_json(self): + cfg = PlatformConfig(platform_dir="/fake") + cfg.set("KEY1", "val1") + cfg.set("KEY2", "val2") + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + self.assertEqual(data["KEY1"], "val1") + self.assertEqual(data["KEY2"], "val2") + + def test_sorted_glob(self): + tmp = tempfile.mkdtemp() + try: + for name in ["c.gds", "a.gds", "b.gds"]: + open(os.path.join(tmp, name), "w").close() + cfg = PlatformConfig(platform_dir="/fake") + result = cfg.sorted_glob(os.path.join(tmp, "*.gds")) + files = result.split() + self.assertEqual(len(files), 3) + self.assertTrue(files[0].endswith("a.gds")) + self.assertTrue(files[1].endswith("b.gds")) + self.assertTrue(files[2].endswith("c.gds")) + finally: + shutil.rmtree(tmp) + + def test_wildcard_glob(self): + tmp = tempfile.mkdtemp() + try: + for name in ["x.gds", "y.gds"]: + open(os.path.join(tmp, name), "w").close() + cfg = PlatformConfig(platform_dir="/fake") + result = cfg.wildcard_glob(os.path.join(tmp, "*.gds")) + files = result.split() + self.assertEqual(len(files), 2) + finally: + shutil.rmtree(tmp) + + +# =================================================================== +# 2. Per-platform unit tests -- use-case coverage +# =================================================================== + + +# --- Test 1: Unconditional assignment (export VAR = value) --- +class TestUnconditionalAssignment(PlatformTestCase): + def test_unconditional_assignment(self): + cases = [ + ("nangate45", "PROCESS", "45"), + ("sky130hs", "PROCESS", "130"), + ("sky130hd", "PROCESS", "130"), + ("gf180", "PROCESS", "180"), + ("ihp-sg13g2", "PROCESS", "ihp-sg13g2"), + ("asap7", "PROCESS", "7"), + ] + for platform, key, expected_substr in cases: + with self.subTest(platform=platform, key=key): + d = self.run_with_env(platform) + self.assertEqual(d[key], expected_substr) + + +# --- Test 2: Conditional assignment (export VAR ?= value) --- +class TestConditionalAssignment(PlatformTestCase): + def test_conditional_assignment_default(self): + cases = [ + ("nangate45", "PLACE_DENSITY", "0.30"), + ("sky130hs", "PLACE_DENSITY", "0.50"), + ("sky130hd", "PLACE_DENSITY", "0.60"), + ("gf180", "PLACE_DENSITY", "0.40"), + ("ihp-sg13g2", "PLACE_DENSITY", "0.65"), + ("asap7", "PLACE_DENSITY", "0.60"), + ] + for platform, key, default_val in cases: + with self.subTest(platform=platform): + d = self.run_with_env(platform) + self.assertEqual(d[key], default_val) + + def test_conditional_assignment_override(self): + for platform in PLATFORMS: + with self.subTest(platform=platform): + d = self.run_with_env(platform, {"PLACE_DENSITY": "0.99"}) + self.assertEqual(d["PLACE_DENSITY"], "0.99") + + +# --- Test 3: Internal append (VAR += value within same config) --- +class TestInternalAppend(PlatformTestCase): + def test_asap7_dont_use_cells_internal_append(self): + """asap7: DONT_USE_CELLS = X then DONT_USE_CELLS += SDF* ICG*""" + d = self.run_with_env("asap7") + self.assertIn("*x1p*_ASAP7*", d["DONT_USE_CELLS"]) + self.assertIn("SDF*", d["DONT_USE_CELLS"]) + self.assertIn("ICG*", d["DONT_USE_CELLS"]) + + +# --- Test 4: External append (VAR += from env) --- +class TestExternalAppend(PlatformTestCase): + def test_sky130hd_dont_use_cells_from_env(self): + """sky130hd: DONT_USE_CELLS += list (appends to env value)""" + d = self.run_with_env("sky130hd", {"DONT_USE_CELLS": "EXISTING_CELL"}) + self.assertIn("EXISTING_CELL", d["DONT_USE_CELLS"]) + self.assertIn("sky130_fd_sc_hd__probe_p_8", d["DONT_USE_CELLS"]) + + def test_ihp_dont_use_cells_from_env(self): + """ihp-sg13g2: DONT_USE_CELLS += list (appends to env value)""" + d = self.run_with_env("ihp-sg13g2", {"DONT_USE_CELLS": "EXISTING"}) + self.assertIn("EXISTING", d["DONT_USE_CELLS"]) + self.assertIn("sg13g2_lgcp_1", d["DONT_USE_CELLS"]) + + +# --- Test 5: $(PLATFORM_DIR)/path expansion --- +class TestPlatformDirExpansion(PlatformTestCase): + def test_platform_dir_expansion(self): + cases = [ + ("nangate45", "TECH_LEF", "/lef/NangateOpenCellLibrary.tech.lef"), + ("sky130hd", "TECH_LEF", "/lef/sky130_fd_sc_hd.tlef"), + ("asap7", "TECH_LEF", "/lef/asap7_tech_1x_201209.lef"), + ] + for platform, key, suffix in cases: + with self.subTest(platform=platform): + d = self.run_with_env(platform) + self.assertTrue(d[key].endswith(suffix)) + self.assertIn(get_platform_dir(platform), d[key]) + + +# --- Test 6: $(sort $(wildcard ...)) --- +class TestSortedGlob(PlatformTestCase): + def test_nangate45_gds_files_sorted(self): + d = self.run_with_env("nangate45") + gds = d["GDS_FILES"].split() + self.assertEqual(gds, sorted(gds)) + + +# --- Test 7: $(wildcard ...) --- +class TestWildcardGlob(PlatformTestCase): + def test_sky130hd_gds_files(self): + d = self.run_with_env("sky130hd") + if d["GDS_FILES"].strip(): + self.assertIn(".gds", d["GDS_FILES"]) + + +# --- Test 8: ifeq/ifneq conditionals --- +class TestConditionalIfeq(PlatformTestCase): + def test_gf180_place_site_9t(self): + """gf180: ifeq ($(TRACK_OPTION),9t) -> GF018hv5v_green_sc9""" + d = self.run_with_env("gf180") + self.assertEqual(d["PLACE_SITE"], "GF018hv5v_green_sc9") + + def test_gf180_place_site_7t(self): + """gf180: else -> GF018hv5v_mcu_sc7""" + d = self.run_with_env("gf180", {"TRACK_OPTION": "7t"}) + self.assertEqual(d["PLACE_SITE"], "GF018hv5v_mcu_sc7") + + def test_asap7_pdn_no_blocks(self): + """asap7: ifeq ($(BLOCKS),) -> grid_strategy-M1-M2-M5-M6.tcl""" + d = self.run_with_env("asap7") + self.assertIn("grid_strategy-M1-M2-M5-M6.tcl", d["PDN_TCL"]) + + def test_asap7_pdn_with_blocks(self): + """asap7: BLOCKS set -> BLOCKS_grid_strategy.tcl""" + d = self.run_with_env("asap7", {"BLOCKS": "block1"}) + self.assertIn("BLOCKS_grid_strategy.tcl", d["PDN_TCL"]) + + +# --- Test 9: $(ADDITIONAL_LIBS) from env --- +class TestEnvVariableInclusion(PlatformTestCase): + def test_nangate45_additional_libs(self): + d = self.run_with_env("nangate45", {"ADDITIONAL_LIBS": "/extra/lib.lib"}) + self.assertIn("/extra/lib.lib", d["LIB_FILES"]) + self.assertIn("NangateOpenCellLibrary_typical.lib", d["LIB_FILES"]) + + +# --- Test 10: $($(CORNER)_LIB_FILES) variable indirection --- +class TestVariableIndirection(PlatformTestCase): + def test_gf180_bc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertIn("ff_n40C_5v50", d["LIB_FILES"]) + + def test_gf180_wc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertIn("ss_125C_4v50", d["LIB_FILES"]) + + def test_gf180_tc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "TC"}) + self.assertIn("tt_025C_5v00", d["LIB_FILES"]) + + def test_asap7_bc_nldm_corner(self): + d = self.run_with_env("asap7", {"CORNER": "BC"}) + self.assertIn("_FF_nldm_", d["LIB_FILES"]) + + def test_asap7_wc_corner(self): + d = self.run_with_env("asap7", {"CORNER": "WC"}) + self.assertIn("_SS_nldm_", d["LIB_FILES"]) + + +# --- Test 11: $(subst PLACEHOLDER,...) template expansion --- +class TestPlaceholderSubstitution(PlatformTestCase): + def test_asap7_placeholder_expansion(self): + """asap7: $(subst PLACEHOLDER,$(PRIMARY_VT_TAG),...) templates""" + d = self.run_with_env("asap7") + self.assertNotIn("PLACEHOLDER", d.get("BC_NLDM_DFF_LIB_FILE", "")) + self.assertIn("_RVT_", d["BC_NLDM_DFF_LIB_FILE"]) + self.assertIn("_RVT_", d["BC_NLDM_LIB_FILES"]) + + +# --- Test 12: $(patsubst %VT,%,...) --- +class TestPatsubstVtTag(PlatformTestCase): + def test_asap7_vt_tag_derivation(self): + """RVT -> R, LVT -> L, SLVT -> SL""" + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT"}) + self.assertTrue("_L_" in d["SC_LEF"] or "_L_" in d["GDS_FILES"]) + + def test_asap7_slvt_tag(self): + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "SLVT"}) + self.assertIn("_SL_", d["SC_LEF"]) + + +# --- Test 13: $(word 1,...) --- +class TestWordExtraction(PlatformTestCase): + def test_asap7_primary_vt_is_first(self): + """PRIMARY_VT = $(word 1, $(VT_LIST))""" + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT RVT SLVT"}) + self.assertIn("asap7sc7p5t_28_L_", d["SC_LEF"]) + + +# --- Test 14: $(wordlist 2,N,...) --- +class TestWordlistExtraction(PlatformTestCase): + def test_asap7_other_vt_is_rest(self): + """OTHER_VT = $(wordlist 2, ..., $(VT_LIST))""" + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) + self.assertIn("asap7sc7p5t_28_L_1x", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("asap7sc7p5t_28_SL_1x", d.get("ADDITIONAL_LEFS", "")) + + +# --- Test 15: $(addsuffix tag,...) --- +class TestAddsuffix(PlatformTestCase): + def test_asap7_fill_cells_suffix(self): + """FILL_CELLS = $(addsuffix $(PRIMARY_VT_TAG), $(FILL_CELLS_T))""" + d = self.run_with_env("asap7") + self.assertIn("FILLERxp5_ASAP7_75t_R", d["FILL_CELLS"]) + self.assertIn("FILLER_ASAP7_75t_R", d["FILL_CELLS"]) + self.assertIn("DECAPx10_ASAP7_75t_R", d["FILL_CELLS"]) + + +# --- Test 16: $(if $(strip $(VAR)),...) --- +class TestIfStrip(PlatformTestCase): + def test_asap7_default_vt_when_unset(self): + """VT_LIST = $(if $(strip $(ASAP7_USE_VT)), ..., RVT)""" + d = self.run_with_env("asap7") + self.assertIn("asap7sc7p5t_28_R_", d["GDS_FILES"]) + + def test_asap7_vt_when_set(self): + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT"}) + self.assertIn("asap7sc7p5t_28_L_", d["GDS_FILES"]) + + +# --- Test 17: $(foreach)/$(eval) loop --- +class TestForeachEvalVtExpansion(PlatformTestCase): + def test_asap7_multi_vt_expansion(self): + """foreach vt in OTHER_VT: expand templates and append""" + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "RVT LVT SLVT"}) + + # Primary VT = RVT (tag R) + self.assertIn("asap7sc7p5t_28_R_", d["GDS_FILES"]) + + # OTHER_VT = [LVT, SLVT] should be appended + self.assertIn("asap7sc7p5t_28_L_220121a.gds", d["GDS_FILES"]) + self.assertIn("asap7sc7p5t_28_SL_220121a.gds", d["GDS_FILES"]) + + # ADDITIONAL_LEFS should have OTHER_VT entries + self.assertIn("asap7sc7p5t_28_L_1x_220121a.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("asap7sc7p5t_28_SL_1x_220121a.lef", d.get("ADDITIONAL_LEFS", "")) + + # DFF lib files should have all 3 VTs + self.assertIn("_RVT_", d["BC_NLDM_DFF_LIB_FILE"]) + self.assertIn("_LVT_", d["BC_NLDM_DFF_LIB_FILE"]) + self.assertIn("_SLVT_", d["BC_NLDM_DFF_LIB_FILE"]) + + # FILL_CELLS should have all 3 VT suffixes + self.assertIn("FILLERxp5_ASAP7_75t_R", d["FILL_CELLS"]) + self.assertIn("FILLERxp5_ASAP7_75t_L", d["FILL_CELLS"]) + self.assertIn("FILLERxp5_ASAP7_75t_SL", d["FILL_CELLS"]) + + +# --- Test 18: $(strip ...) --- +class TestStrip(PlatformTestCase): + def test_asap7_strip_asap7_use_vt(self): + """Whitespace in ASAP7_USE_VT should be stripped""" + d = self.run_with_env("asap7", {"ASAP7_USE_VT": " RVT "}) + self.assertIn("asap7sc7p5t_28_R_", d["GDS_FILES"]) + + +# --- Test 19: $(shell sed ...) SDC clock period extraction --- +class TestSdcClockPeriodExtraction(PlatformTestCase): + def test_ihp_sdc_clk_period(self): + """ihp-sg13g2: extract clock period from SDC file""" + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("set clk_period 10.0\ncreate_clock ...\n") + d = self.run_with_env("ihp-sg13g2", {"SDC_FILE": sdc}) + self.assertEqual(d["ABC_CLOCK_PERIOD_IN_PS"], "10000.0") + finally: + shutil.rmtree(tmp) + + def test_ihp_sdc_period_flag(self): + """ihp-sg13g2: extract from -period flag""" + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("create_clock -period 5.0 [get_ports clk]\n") + d = self.run_with_env("ihp-sg13g2", {"SDC_FILE": sdc}) + self.assertEqual(d["ABC_CLOCK_PERIOD_IN_PS"], "5000.0") + finally: + shutil.rmtree(tmp) + + def test_ihp_no_sdc_file(self): + """No SDC file -> ABC_CLOCK_PERIOD_IN_PS not set""" + d = self.run_with_env("ihp-sg13g2") + self.assertNotIn("ABC_CLOCK_PERIOD_IN_PS", d) + + +# --- Test 20: $(origin VAR) check --- +class TestOriginCheck(PlatformTestCase): + def test_ihp_origin_undefined(self): + """When ABC_CLOCK_PERIOD_IN_PS is not in env, extract from SDC""" + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("set clk_period 8.0\n") + d = self.run_with_env("ihp-sg13g2", {"SDC_FILE": sdc}) + self.assertEqual(d["ABC_CLOCK_PERIOD_IN_PS"], "8000.0") + finally: + shutil.rmtree(tmp) + + def test_ihp_origin_defined(self): + """When ABC_CLOCK_PERIOD_IN_PS is in env, don't extract""" + tmp = tempfile.mkdtemp() + try: + sdc = os.path.join(tmp, "constraint.sdc") + with open(sdc, "w") as f: + f.write("set clk_period 8.0\n") + d = self.run_with_env( + "ihp-sg13g2", + {"SDC_FILE": sdc, "ABC_CLOCK_PERIOD_IN_PS": "12345"}, + ) + self.assertTrue( + "ABC_CLOCK_PERIOD_IN_PS" not in d + or d.get("ABC_CLOCK_PERIOD_IN_PS") != "8000.0" + ) + finally: + shutil.rmtree(tmp) + + +# --- Test 21: $(abspath ...) --- +class TestAbspath(PlatformTestCase): + def test_gf180_lib_files_absolute(self): + d = self.run_with_env("gf180") + self.assertTrue(os.path.isabs(d["BC_LIB_FILES"])) + self.assertTrue(os.path.isabs(d["LIB_FILES"].split()[0])) + + +# --- Test 22: $(realpath ...) --- +class TestRealpath(PlatformTestCase): + def test_asap7_db_files_realpath(self): + """asap7: DB_FILES uses $(realpath ...) -- only if corner DB files exist""" + d = self.run_with_env("asap7") + self.assertIsInstance(d.get("DB_FILES", ""), str) + + +# --- Test 23: -include private.mk skipped --- +class TestPrivateMkSkipped(PlatformTestCase): + def test_gf180_has_private_dir_default(self): + """gf180: -include private.mk is skipped, but GF180_PRIVATE_DIR is set""" + d = self.run_with_env("gf180") + self.assertEqual(d["GF180_PRIVATE_DIR"], "../../gf180-private") + + +# --- Test 24: ??= (treated as ?=) --- +class TestDoubleQuestionEquals(PlatformTestCase): + def test_ihp_io_pins_default_empty(self): + """ihp-sg13g2: ??= variables default to empty""" + d = self.run_with_env("ihp-sg13g2") + self.assertEqual(d.get("IO_NORTH_PINS", ""), "") + self.assertEqual(d.get("IO_SOUTH_PINS", ""), "") + + def test_ihp_io_pins_override(self): + """ihp-sg13g2: ??= variables can be overridden from env""" + d = self.run_with_env("ihp-sg13g2", {"IO_NORTH_PINS": "pin1 pin2"}) + self.assertEqual(d["IO_NORTH_PINS"], "pin1 pin2") + + +# --- Test 25: Parameterized options (gf180) --- +class TestGf180ParameterizedOptions(PlatformTestCase): + def test_default_options(self): + d = self.run_with_env("gf180") + self.assertIn("5LM_1TM", d["TECH_LEF"]) + self.assertIn("9K", d["TECH_LEF"]) + self.assertIn("9t", d["TECH_LEF"]) + + def test_custom_track_option(self): + d = self.run_with_env("gf180", {"TRACK_OPTION": "7t"}) + self.assertIn("7t", d["TECH_LEF"]) + self.assertEqual(d["PLACE_SITE"], "GF018hv5v_mcu_sc7") + + def test_custom_metal_option(self): + d = self.run_with_env("gf180", {"METAL_OPTION": "3LM_1TM"}) + self.assertIn("3LM_1TM", d["TECH_LEF"]) + + +# --- Test 26: BLOCKS conditional for PDN_TCL --- +class TestAsap7BlocksPdn(PlatformTestCase): + def test_no_blocks(self): + d = self.run_with_env("asap7") + self.assertNotIn("BLOCKS", d["PDN_TCL"]) + + def test_with_blocks(self): + d = self.run_with_env("asap7", {"BLOCKS": "some_block"}) + self.assertIn("BLOCKS_grid_strategy", d["PDN_TCL"]) + + +# --- Test 27: CLUSTER_FLOPS conditional --- +class TestAsap7ClusterFlops(PlatformTestCase): + def test_no_cluster_flops(self): + d = self.run_with_env("asap7") + self.assertNotIn("DFFHQNH2V2X", d.get("ADDITIONAL_LIBS", "")) + + def test_with_cluster_flops(self): + d = self.run_with_env("asap7", {"CLUSTER_FLOPS": "1"}) + self.assertIn("DFFHQNH2V2X", d.get("ADDITIONAL_LIBS", "")) + self.assertIn("DFFHQNV2X", d.get("ADDITIONAL_LIBS", "")) + self.assertIn("asap7sc7p5t_DFFHQNH2V2X.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("asap7sc7p5t_pg", d.get("ADDITIONAL_SITES", "")) + self.assertEqual(d.get("GDS_ALLOW_EMPTY"), "DFFHQN[VH][24].*") + + +# --- Test 28: LIB_MODEL selection --- +class TestAsap7LibModel(PlatformTestCase): + def test_default_nldm(self): + d = self.run_with_env("asap7") + self.assertTrue("/NLDM/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/NLDM")) + + def test_ccs_model(self): + d = self.run_with_env("asap7", {"LIB_MODEL": "CCS"}) + self.assertTrue("/CCS/" in d["LIB_DIR"] or d["LIB_DIR"].endswith("/CCS")) + + +# --- Test 29: Corner temperature/voltage --- +class TestCornerTemperatureVoltage(PlatformTestCase): + def test_asap7_bc_corner(self): + d = self.run_with_env("asap7", {"CORNER": "BC"}) + self.assertEqual(d["TEMPERATURE"], "25C") + self.assertEqual(d["VOLTAGE"], "0.77") + + def test_asap7_wc_corner(self): + d = self.run_with_env("asap7", {"CORNER": "WC"}) + self.assertEqual(d["TEMPERATURE"], "100C") + self.assertEqual(d["VOLTAGE"], "0.63") + + def test_gf180_bc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertEqual(d["TEMPERATURE"], "-40c") + self.assertEqual(d["VOLTAGE"], "5.5") + + def test_gf180_wc_corner(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertEqual(d["TEMPERATURE"], "125c") + self.assertEqual(d["VOLTAGE"], "4.5") + + +# --- Test 30: Multi-VT expansion --- +class TestAsap7MultiVt(PlatformTestCase): + def test_single_vt_default(self): + """Default: ASAP7_USE_VT unset -> RVT only, no OTHER_VT additions""" + d = self.run_with_env("asap7") + gds = d["GDS_FILES"] + self.assertIn("28_R_", gds) + self.assertNotIn("28_L_", gds) + self.assertNotIn("28_L_1x", d.get("ADDITIONAL_LEFS", "")) + + def test_dual_vt(self): + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "RVT LVT"}) + self.assertIn("28_R_", d["GDS_FILES"]) + self.assertIn("28_L_", d["GDS_FILES"]) + + +# --- Test 31: FOOTPRINT_TCL conditional (ihp-sg13g2) --- +class TestIhpFootprintConditional(PlatformTestCase): + def test_no_footprint(self): + """No FOOTPRINT_TCL -> no IO lefs/libs added""" + d = self.run_with_env("ihp-sg13g2") + self.assertNotIn("sg13g2_io.lef", d.get("ADDITIONAL_LEFS", "")) + + def test_with_footprint(self): + """FOOTPRINT_TCL set -> IO lefs/libs/gds added""" + d = self.run_with_env("ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) + self.assertIn("sg13g2_io.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("bondpad_70x70.lef", d.get("ADDITIONAL_LEFS", "")) + self.assertIn("sg13g2_io_slow", d.get("SLOW_LIB_FILES", "")) + self.assertIn("sg13g2_io.gds", d.get("ADDITIONAL_GDS", "")) + + +# --- Test 32: $(PLATFORM) in paths --- +class TestPlatformVarInPaths(PlatformTestCase): + def test_sky130hd_platform_in_klayout(self): + d = self.run_with_env("sky130hd") + self.assertIn("sky130hd.lyt", d["KLAYOUT_TECH_FILE"]) + self.assertIn("sky130hd.lydrc", d["KLAYOUT_DRC_FILE"]) + self.assertIn("sky130hd.cdl", d["CDL_FILE"]) + + def test_sky130hs_platform_in_klayout(self): + d = self.run_with_env("sky130hs") + self.assertIn("sky130hs.lyt", d["KLAYOUT_TECH_FILE"]) + + +# --- Test 33: Make shim round-trip --- +class TestShimRoundTrip(PlatformTestCase): + """Verify config.py Make output format is consumable by foreach/eval.""" + + def test_make_output_format(self): + """Each line is 'export KEY=VALUE' or 'export KEY?=VALUE' with __SPACE__""" + for platform in PLATFORMS: + with self.subTest(platform=platform): + d = self.run_with_env(platform) + cfg = PLATFORM_MODULES[platform].get_config() + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_make() + for line in buf.getvalue().strip().split("\n"): + self.assertTrue( + line.startswith("export "), + f"Line doesn't start with 'export ': {line}", + ) + rest = line[7:] # strip "export " + self.assertIn("=", rest, f"No = in: {line}") + if "?=" in rest: + key, val = rest.split("?=", 1) + else: + key, val = rest.split("=", 1) + self.assertNotIn( + " ", + val, + f"Space in value (should be __SPACE__): {key}={val}", + ) + + def test_json_output_parseable(self): + """JSON output should be valid and parseable.""" + for platform in PLATFORMS: + with self.subTest(platform=platform): + self.run_with_env(platform) + cfg = PLATFORM_MODULES[platform].get_config() + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + self.assertIsInstance(data, dict) + self.assertGreater(len(data), 0) + + +# =================================================================== +# 3. Integration findings: design-config override semantics +# =================================================================== +class TestDesignConfigOverrides(PlatformTestCase): + """Tests discovered from Make integration comparison. + + When a design config.mk sets a variable with = or :=, it overrides + the platform config.py's ?= default. These tests verify the ?= + semantics work correctly end-to-end. + """ + + def test_conditional_overridden_by_immediate_assignment(self): + """nangate45/gcd: 'export ADDER_MAP_FILE :=' in design clears platform ?= default.""" + d = self.run_with_env("nangate45", {"ADDER_MAP_FILE": ""}) + self.assertEqual(d["ADDER_MAP_FILE"], "") + + def test_design_place_density_overrides_platform(self): + """asap7/gcd: design sets PLACE_DENSITY=0.35, overriding platform ?=0.60.""" + d = self.run_with_env("asap7", {"PLACE_DENSITY": "0.35"}) + self.assertEqual(d["PLACE_DENSITY"], "0.35") + + def test_design_pdn_tcl_overrides_platform(self): + """nangate45/gcd: design sets PDN_TCL, overriding platform ?= default.""" + d = self.run_with_env( + "nangate45", {"PDN_TCL": "/designs/nangate45/gcd/custom_pdn.tcl"} + ) + self.assertEqual(d["PDN_TCL"], "/designs/nangate45/gcd/custom_pdn.tcl") + + def test_ihp_design_place_density_overrides(self): + """ihp-sg13g2/gcd: design sets PLACE_DENSITY?=0.88, platform has ?=0.65.""" + d = self.run_with_env("ihp-sg13g2", {"PLACE_DENSITY": "0.88"}) + self.assertEqual(d["PLACE_DENSITY"], "0.88") + + +class TestGf180CornerVariants(PlatformTestCase): + """Tests for all 3 gf180 corners discovered from Make integration comparison.""" + + def test_bc_rcx_rules(self): + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertIn("bst.rules", d["RCX_RULES"]) + self.assertEqual(d["RCX_RC_CORNER"], "FuncRCmin") + + def test_wc_rcx_rules(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertIn("wst.rules", d["RCX_RULES"]) + self.assertEqual(d["RCX_RC_CORNER"], "FuncRCmax") + + def test_tc_rcx_rules(self): + d = self.run_with_env("gf180", {"CORNER": "TC"}) + self.assertIn("typ.rules", d["RCX_RULES"]) + self.assertEqual(d["RCX_RC_CORNER"], "FuncRCtyp") + + def test_bc_pwr_nets_uses_corner_voltage(self): + """PWR_NETS_VOLTAGES should use the corner-specific voltage.""" + d = self.run_with_env("gf180", {"CORNER": "BC"}) + self.assertEqual(d["PWR_NETS_VOLTAGES"], "VDD 5.5") + + def test_wc_pwr_nets_uses_corner_voltage(self): + d = self.run_with_env("gf180", {"CORNER": "WC"}) + self.assertEqual(d["PWR_NETS_VOLTAGES"], "VDD 4.5") + + def test_tc_pwr_nets_uses_corner_voltage(self): + d = self.run_with_env("gf180", {"CORNER": "TC"}) + self.assertEqual(d["PWR_NETS_VOLTAGES"], "VDD 5.0") + + def test_gds_layer_map_absolute_path(self): + d = self.run_with_env("gf180") + self.assertTrue(os.path.isabs(d["GDS_LAYER_MAP"])) + self.assertIn("edi2gds.layermap", d["GDS_LAYER_MAP"]) + + def test_klayout_lef_file(self): + d = self.run_with_env("gf180") + self.assertIn("tech_9t_5LM_1TM.lef", d["KLAYOUT_LEF_FILE"]) + + def test_tie_cell_and_endcap(self): + d = self.run_with_env("gf180") + self.assertEqual(d["TIE_CELL"], "gf180mcu_fd_sc_mcu9t5v0__filltie") + self.assertEqual(d["ENDCAP_CELL"], "gf180mcu_fd_sc_mcu9t5v0__endcap") + + def test_max_fanout(self): + d = self.run_with_env("gf180") + self.assertEqual(d["MAX_FANOUT"], "20") + + +class TestAsap7ExtraVarsFromIntegration(PlatformTestCase): + """Tests for asap7 variables verified against Make integration output.""" + + def test_platform_tcl(self): + d = self.run_with_env("asap7") + self.assertTrue(d["PLATFORM_TCL"].endswith("/liberty_suppressions.tcl")) + + def test_make_tracks(self): + d = self.run_with_env("asap7") + self.assertTrue(d["MAKE_TRACKS"].endswith("/openRoad/make_tracks.tcl")) + + def test_set_rc_tcl(self): + d = self.run_with_env("asap7") + self.assertTrue(d["SET_RC_TCL"].endswith("/setRC.tcl")) + + def test_lib_dir_default(self): + d = self.run_with_env("asap7") + self.assertTrue(d["LIB_DIR"].endswith("/lib/NLDM")) + + def test_macro_rows_halo(self): + d = self.run_with_env("asap7") + self.assertEqual(d["MACRO_ROWS_HALO_X"], "2") + self.assertEqual(d["MACRO_ROWS_HALO_Y"], "2") + + def test_corner_temps_and_voltages(self): + d = self.run_with_env("asap7") + self.assertEqual(d["BC_TEMPERATURE"], "25C") + self.assertEqual(d["TC_TEMPERATURE"], "0C") + self.assertEqual(d["WC_TEMPERATURE"], "100C") + self.assertEqual(d["BC_VOLTAGE"], "0.77") + self.assertEqual(d["TC_VOLTAGE"], "0.70") + self.assertEqual(d["WC_VOLTAGE"], "0.63") + + def test_synth_minimum_keep_size(self): + d = self.run_with_env("asap7") + self.assertEqual(d["SYNTH_MINIMUM_KEEP_SIZE"], "1000") + + def test_ccs_lib_files_with_bc_additional(self): + """BC_CCS_LIB_FILES should include BC_ADDITIONAL_LIBS when set.""" + d = self.run_with_env("asap7", {"BC_ADDITIONAL_LIBS": "/extra/bc.lib"}) + self.assertIn("/extra/bc.lib", d["BC_CCS_LIB_FILES"]) + self.assertIn("_ccs_", d["BC_CCS_LIB_FILES"]) + + def test_wc_nldm_lib_files(self): + d = self.run_with_env("asap7") + self.assertIn("_SS_nldm_", d["WC_NLDM_LIB_FILES"]) + self.assertIn("_RVT_", d["WC_NLDM_LIB_FILES"]) + + def test_tc_nldm_lib_files(self): + d = self.run_with_env("asap7") + self.assertIn("_TT_nldm_", d["TC_NLDM_LIB_FILES"]) + self.assertIn("_RVT_", d["TC_NLDM_LIB_FILES"]) + + def test_wc_corner_lib_files(self): + """With CORNER=WC, LIB_FILES should use WC_NLDM_LIB_FILES.""" + d = self.run_with_env("asap7", {"CORNER": "WC"}) + self.assertIn("_SS_nldm_", d["LIB_FILES"]) + + def test_tc_corner_lib_files(self): + """With CORNER=TC, LIB_FILES should use TC_NLDM_LIB_FILES.""" + d = self.run_with_env("asap7", {"CORNER": "TC"}) + self.assertIn("_TT_nldm_", d["LIB_FILES"]) + + def test_ccs_model_corner_selection(self): + """With LIB_MODEL=CCS and CORNER=BC, LIB_FILES should use BC_CCS_LIB_FILES.""" + d = self.run_with_env("asap7", {"LIB_MODEL": "CCS", "CORNER": "BC"}) + self.assertIn("_ccs_", d["LIB_FILES"]) + + def test_lvt_design_vars(self): + """asap7/aes_lvt: ASAP7_USE_VT=LVT should set all primary VT vars to L tag.""" + d = self.run_with_env("asap7", {"ASAP7_USE_VT": "LVT"}) + self.assertIn("asap7sc7p5t_28_L_1x", d["SC_LEF"]) + self.assertIn("asap7sc7p5t_28_L_", d["GDS_FILES"]) + self.assertIn("TIEHIx1_ASAP7_75t_L", d["TIEHI_CELL_AND_PORT"]) + self.assertIn("BUFx2_ASAP7_75t_L", d["ABC_DRIVER_CELL"]) + self.assertIn("cells_latch_L.v", d["LATCH_MAP_FILE"]) + self.assertIn("TAPCELL_ASAP7_75t_L", d["TAP_CELL_NAME"]) + self.assertIn("FILLERxp5_ASAP7_75t_L", d["FILL_CELLS"]) + + +class TestIhpExtraVarsFromIntegration(PlatformTestCase): + """Tests for ihp-sg13g2 variables verified against Make integration output.""" + + def test_slow_lib_files(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("slow_1p08V_125C", d["SLOW_LIB_FILES"]) + + def test_fast_lib_files(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("fast_1p32V_m40C", d["FAST_LIB_FILES"]) + + def test_typ_lib_files(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("typ_1p20V_25C", d["TYP_LIB_FILES"]) + + def test_lib_files_defaults_to_typ(self): + """LIB_FILES ?= $(TYP_LIB_FILES)""" + d = self.run_with_env("ihp-sg13g2") + self.assertIn("typ_1p20V_25C", d["LIB_FILES"]) + + def test_core_margin(self): + d = self.run_with_env("ihp-sg13g2") + self.assertEqual(d["CORE_MARGIN"], "17.5") + + def test_io_filler_cells(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("sg13g2_Filler10000", d["IO_FILLER_CELLS"]) + self.assertIn("sg13g2_Filler200", d["IO_FILLER_CELLS"]) + + def test_io_bondpad_vars(self): + d = self.run_with_env("ihp-sg13g2") + self.assertEqual(d["IO_BONDPAD_SIZE"], "70") + self.assertEqual(d["IO_BONDPAD_NAME"], "bondpad_70x70") + self.assertEqual(d["IO_LENGTH"], "180") + self.assertEqual(d["IO_WIDTH"], "80") + self.assertEqual(d["IO_SEALRING_OFFSET"], "70") + + def test_gds_allow_empty_regex(self): + d = self.run_with_env("ihp-sg13g2") + self.assertIn("RM_IHPSG13", d["GDS_ALLOW_EMPTY"]) + self.assertIn("CORNER", d["GDS_ALLOW_EMPTY"]) + + def test_footprint_conditional_with_load_disabled(self): + """FOOTPRINT_TCL set but LOAD_ADDITIONAL_FILES=0 -> no IO additions.""" + d = self.run_with_env( + "ihp-sg13g2", + {"FOOTPRINT_TCL": "/some/file.tcl", "LOAD_ADDITIONAL_FILES": "0"}, + ) + self.assertNotIn("sg13g2_io.lef", d.get("ADDITIONAL_LEFS", "")) + + def test_slow_lib_with_footprint(self): + """FOOTPRINT_TCL set -> SLOW_LIB_FILES includes IO lib.""" + d = self.run_with_env("ihp-sg13g2", {"FOOTPRINT_TCL": "/some/file.tcl"}) + self.assertIn("sg13g2_io_slow", d["SLOW_LIB_FILES"]) + self.assertIn("sg13g2_stdcell_slow", d["SLOW_LIB_FILES"]) + + +# =================================================================== +# 4. Integration tests: make clean_all metadata +# =================================================================== +INTEGRATION_DESIGNS = [ + ("nangate45", "gcd"), + ("sky130hd", "gcd"), + ("gf180", "ibex"), + ("ihp-sg13g2", "gcd"), + ("asap7", "aes-mbff"), +] + + +@unittest.skipUnless(os.environ.get("RUN_INTEGRATION"), "set RUN_INTEGRATION=1 to run") +class TestMakeIntegration(unittest.TestCase): + """Run make DESIGN_CONFIG=... clean_all metadata through the shim. + + These tests verify the full config.mk shim -> config.py -> Make pipeline. + They require Make and the ORFS environment to be set up. + """ + + def test_make_metadata(self): + """Run make clean_all metadata and verify it succeeds.""" + for platform, design in INTEGRATION_DESIGNS: + with self.subTest(platform=platform, design=design): + design_config = f"designs/{platform}/{design}/config.mk" + result = subprocess.run( + [ + "make", + "clean_all", + "metadata", + f"DESIGN_CONFIG={design_config}", + ], + capture_output=True, + text=True, + cwd=os.path.abspath(FLOW_DIR), + timeout=300, + ) + self.assertEqual( + result.returncode, + 0, + f"make metadata failed for {platform}/{design}:\n" + f"stdout: {result.stdout[-2000:]}\n" + f"stderr: {result.stderr[-2000:]}", + ) + + +ALL_PLATFORMS = ["nangate45", "sky130hd", "sky130hs", "gf180", "ihp-sg13g2", "asap7"] + + +class TestUnexpandedOutput(PlatformTestCase): + """Verify config.py output uses $(PLATFORM_DIR) and $(PLATFORM) instead of absolute paths. + + bazel-orfs runs in a sandbox where platform files live at different paths. + config.py must output symbolic references so consumers can expand on their end: + - Make: $(eval) expands $(PLATFORM_DIR) and $(PLATFORM) + - bazel-orfs: Python substitution when the Bazel rule executes + """ + + def test_json_no_absolute_platform_dir(self): + """JSON output must not contain the absolute platform_dir path.""" + for platform in ALL_PLATFORMS: + with self.subTest(platform=platform): + pd = get_platform_dir(platform) + d = self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + + for key, value in data.items(): + self.assertNotIn( + pd, + value, + f"{platform}: {key} contains absolute path {pd!r} " + f"instead of $(PLATFORM_DIR). Value: {value!r}", + ) + + def test_make_no_absolute_platform_dir(self): + """Make output must not contain the absolute platform_dir path.""" + for platform in ALL_PLATFORMS: + with self.subTest(platform=platform): + pd = get_platform_dir(platform) + self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_make() + output = buf.getvalue() + + self.assertNotIn( + pd, + output, + f"{platform}: Make output contains absolute path {pd!r} " + f"instead of $(PLATFORM_DIR)", + ) + + def test_glob_results_unexpanded(self): + """GDS_FILES from glob must use $(PLATFORM_DIR), not absolute paths.""" + for platform in ["nangate45", "sky130hd", "sky130hs", "gf180"]: + with self.subTest(platform=platform): + pd = get_platform_dir(platform) + self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + + gds = data.get("GDS_FILES", "") + self.assertTrue(gds, f"{platform}: GDS_FILES is empty") + self.assertIn( + "$(PLATFORM_DIR)", + gds, + f"{platform}: GDS_FILES glob result missing $(PLATFORM_DIR): {gds!r}", + ) + self.assertNotIn( + pd, + gds, + f"{platform}: GDS_FILES contains absolute path: {gds!r}", + ) + + def test_platform_name_unexpanded(self): + """Variables using $(PLATFORM) in filenames must not expand it.""" + cases = [ + ( + "sky130hd", + [ + "KLAYOUT_TECH_FILE", + "KLAYOUT_DRC_FILE", + "CDL_FILE", + "KLAYOUT_LVS_FILE", + ], + ), + ("sky130hs", ["KLAYOUT_TECH_FILE"]), + ] + for platform, keys in cases: + with self.subTest(platform=platform): + self.run_with_env(platform) + mod = _load_config_module(platform) + cfg = mod.get_config() + + buf = io.StringIO() + with redirect_stdout(buf): + cfg.output_json() + data = json.loads(buf.getvalue()) + + for key in keys: + value = data.get(key, "") + self.assertIn( + "$(PLATFORM)", + value, + f"{platform}: {key} should contain $(PLATFORM), got: {value!r}", + ) + self.assertNotIn( + f"/{platform}.", + value, + f"{platform}: {key} contains expanded platform name: {value!r}", + ) + + +if __name__ == "__main__": + unittest.main()