blob: 83fffba2e51a8f9543979283f44369eb2accf131 [file] [log] [blame]
#!/usr/bin/env python3
#
# fix_vddio_pad_gds.py ---
#
# Special-purpose script that does the work of what ought to be a simple
# binary diff and patch. Except that no such thing exists as a standard
# offering on most Linux systems, so instead of adding another OS
# package requirement, I'm just writing a binary search-and-replace in
# python.
#
# The purpose of the patch is to add metal3 resistor ID markers to the
# sky130_fd_io__hvc_clampv2 cell. Also add labels for VDDIO_Q
# in the isolated metal3 regions formed by the resistors, in the
# sky130_fd_io__top_power_hvc_wpadv2 cell.
#
import sys
if len(sys.argv) != 2:
print('Usage: fix_vddio_pad_gds.py <filename>')
sys.exit(1)
else:
file_name = sys.argv[1]
# Metal 3 resistor at (0.495um 63.12um 24.395um 63.56um)
add_data_1 = b'\x00\x04\x08\x00\x00\x06\x0d\x02\x00\x46\x00\x06\x0e\x02\x00\x0d\x00\x2c\x10\x03\x00\x00\x01\xef\x00\x00\xf6\x90\x00\x00\x5f\x4b\x00\x00\xf6\x90\x00\x00\x5f\x4b\x00\x00\xf8\x48\x00\x00\x01\xef\x00\x00\xf8\x48\x00\x00\x01\xef\x00\x00\xf6\x90\x00\x04\x11\x00'
# Metal 3 resistor at (0.495um 69.07um 24.395um 69.51um)
add_data_2 = b'\x00\x04\x08\x00\x00\x06\x0d\x02\x00\x46\x00\x06\x0e\x02\x00\x0d\x00\x2c\x10\x03\x00\x00\xc4\xd6\x00\x00\xf6\x90\x00\x01\x22\x32\x00\x00\xf6\x90\x00\x01\x22\x32\x00\x00\xf8\x48\x00\x00\xc4\xd6\x00\x00\xf8\x48\x00\x00\xc4\xd6\x00\x00\xf6\x90\x00\x04\x11\x00'
# Metal 3 resistor at (50.39um 63.12um 74.29um 63.56um)
add_data_3 = b'\x00\x04\x08\x00\x00\x06\x0d\x02\x00\x46\x00\x06\x0e\x02\x00\x0d\x00\x2c\x10\x03\x00\x00\x01\xef\x00\x01\x0d\xce\x00\x00\x5f\x4b\x00\x01\x0d\xce\x00\x00\x5f\x4b\x00\x01\x0f\x86\x00\x00\x01\xef\x00\x01\x0f\x86\x00\x00\x01\xef\x00\x01\x0d\xce\x00\x04\x11\x00'
# Metal 3 resistor at (50.39um 69.07um 74.29um 69.51um)
add_data_4 = b'\x00\x04\x08\x00\x00\x06\x0d\x02\x00\x46\x00\x06\x0e\x02\x00\x0d\x00\x2c\x10\x03\x00\x00\xc4\xd6\x00\x01\x0d\xce\x00\x01\x22\x32\x00\x01\x0d\xce\x00\x01\x22\x32\x00\x01\x0f\x86\x00\x00\xc4\xd6\x00\x01\x0f\x86\x00\x00\xc4\xd6\x00\x01\x0d\xce\x00\x04\x11\x00'
# VDDIO_Q label at (67.45um 66.22um) size 0.3um on MET3PIN
add_data_5 = b'\x00\x04\x0c\x00\x00\x06\x0d\x02\x00\x46\x00\x06\x16\x02\x00\x10\x00\x06\x17\x01\x00\x05\x00\x06\x1a\x01\x00\x00\x00\x0c\x1b\x05\x40\x4c\x66\x66\x66\x66\x66\x66\x00\x0c\x10\x03\x00\x01\x07\x7a\x00\x01\x02\xac\x00\x0c\x19\x06\x56\x44\x44\x49\x4f\x5f\x51\x00\x00\x04\x11\x00'
# VDDIO_Q label at (5.05um 66.22um) size 0.3um on MET3PIN
add_data_6 = b'\x00\x04\x0c\x00\x00\x06\x0d\x02\x00\x46\x00\x06\x16\x02\x00\x10\x00\x06\x17\x01\x00\x05\x00\x06\x1a\x01\x00\x00\x00\x0c\x1b\x05\x40\x4c\x66\x66\x66\x66\x66\x66\x00\x0c\x10\x03\x00\x00\x13\xba\x00\x01\x02\xac\x00\x0c\x19\x06\x56\x44\x44\x49\x4f\x5f\x51\x00\x00\x04\x11\x00'
# Append metal resistors after this data
orig_data_1 = b'\x00\x02\x9d\x33\x00\x00\x2b\x1b\x00\x02\x9d\xfb\x00\x00\x2a\x53\x00\x02\x9d\xfb\x00\x00\x2a\x53\x00\x02\x9d\x33\x00\x04\x11\x00'
# Append port labels after this data
orig_data_2 = b'\x00\x0c\x10\x03\x00\x00\x2d\x1e\x00\x00\x05\x23\x00\x0a\x19\x06\x50\x5f\x43\x4f\x52\x45\x00\x04\x11\x00'
# This is not efficient, but only needs to be done once.
with open(file_name, 'rb') as ifile:
data = ifile.read()
data = data.replace(orig_data_1, orig_data_1 + add_data_1 + add_data_2 + add_data_3 + add_data_4)
data = data.replace(orig_data_2, orig_data_2 + add_data_5 + add_data_6)
# Write back into the same file
with open(file_name, 'wb') as ofile:
ofile.write(data)
print("Done!")