Extracted just the decompression stuff for this pull request.

All MachXO2 stuff will resume on
https://github.com/cr1901/prjtrellis/tree/facade
to avoid duplication of effort and merge hell

Signed-off-by: Andres Navarro <canavarro82@gmail.com>
diff --git a/devices.json b/devices.json
index ac5f989..a2095be 100644
--- a/devices.json
+++ b/devices.json
@@ -111,47 +111,6 @@
                 "fuzz": 1
             }
         }
-    },
-    "MachXO2" : {
-      "devices" : {
-            "LCMXO2-256HC": {
-                "packages": ["QFN32"],
-                "idcode": "0x012b8043",
-                "frames": 186,
-                "bits_per_frame": 504,
-                "pad_bits_after_frame": 0,
-                "pad_bits_before_frame": 0,
-                "max_row" : 7,
-                "max_col" : 10,
-                "col_bias" : 1,
-                "fuzz": 1
-            },
-
-            "LCMXO2-1200HC": {
-                "packages": ["QFN32"],
-                "idcode": "0x012ba043",
-                "frames": 333,
-                "bits_per_frame": 1080,
-                "pad_bits_after_frame": 0,
-                "pad_bits_before_frame": 0,
-                "max_row" : 12,
-                "max_col" : 22,
-                "col_bias" : 1,
-                "fuzz": 1
-            },
-            "LCMXO2-4000HC": {
-                "packages": ["TQFP144"],
-                "idcode": "0x012bc043",
-                "frames": 623,
-                "bits_per_frame": 1560,
-                "pad_bits_after_frame": 0,
-                "pad_bits_before_frame": 0,
-                "max_row" : 22,
-                "max_col" : 32,
-                "col_bias" : 1,
-                "fuzz": 1
-            }
-        }
     }
   }
 }
diff --git a/diamond.sh b/diamond.sh
index 24d7339..b23aff5 100755
--- a/diamond.sh
+++ b/diamond.sh
@@ -92,28 +92,11 @@
 		LSE_ARCH="ECP5UM5G"
 		;;
 
-	LCMXO2-256HC)
-		PACKAGE="${DEV_PACKAGE:-QFN32}"
-		DEVICE="LCMXO2-256HC"
-		LSE_ARCH="MachXO2"
-		;;
-
-	LCMXO2-1200HC)
-		PACKAGE="${DEV_PACKAGE:-QFN32}"
-		DEVICE="LCMXO2-1200HC"
-		LSE_ARCH="MachXO2"
-		;;
-
 	LCMXO2-2000HC)
 		PACKAGE="${DEV_PACKAGE:-TQFP100}"
 		DEVICE="LCMXO2-2000HC"
 		LSE_ARCH="MachXO2"
 		;;
-	LCMXO2-4000HC)
-		PACKAGE="${DEV_PACKAGE:-TQFP144}"
-		DEVICE="LCMXO2-4000HC"
-		LSE_ARCH="MachXO2"
-		;;
 	LCMXO2-7000HC)
 		PACKAGE="${DEV_PACKAGE:-TQFP144}"
 		DEVICE="LCMXO2-7000HC"
diff --git a/fuzzers/MachXO2/003-plc_lut_init/empty.ncl b/fuzzers/MachXO2/003-plc_lut_init/empty.ncl
deleted file mode 100644
index cbdac0a..0000000
--- a/fuzzers/MachXO2/003-plc_lut_init/empty.ncl
+++ /dev/null
@@ -1,12 +0,0 @@
-::FROM-WRITER;
-design top
-{
-   device
-   {
-       architecture xo2c00;
-       device LCMXO2-4000HC;
-       package TQFP144;
-       performance "6";
-   }
-
-}
diff --git a/fuzzers/MachXO2/003-plc_lut_init/fuzzer.py b/fuzzers/MachXO2/003-plc_lut_init/fuzzer.py
deleted file mode 100644
index 2e779ba..0000000
--- a/fuzzers/MachXO2/003-plc_lut_init/fuzzer.py
+++ /dev/null
@@ -1,46 +0,0 @@
-from fuzzconfig import FuzzConfig
-import nonrouting
-import fuzzloops
-import nets
-import pytrellis
-import re
-
-cfg = FuzzConfig(job="PLCINIT", family="MachXO2", device="LCMXO2-4000HC", ncl="empty.ncl", tiles=["R9C9:PLC"])
-
-
-def get_lut_function(init_bits):
-    sop_terms = []
-    lut_inputs = ["A", "B", "C", "D"]
-    for i in range(16):
-        if init_bits[i]:
-            p_terms = []
-            for j in range(4):
-                if i & (1 << j) != 0:
-                    p_terms.append(lut_inputs[j])
-                else:
-                    p_terms.append("~" + lut_inputs[j])
-            sop_terms.append("({})".format("*".join(p_terms)))
-    if len(sop_terms) == 0:
-        lut_func = "0"
-    else:
-        lut_func = "+".join(sop_terms)
-    return lut_func
-
-
-def main():
-    pytrellis.load_database("../../../database")
-    cfg.setup()
-    empty_bitfile = cfg.build_design(cfg.ncl, {})
-    cfg.ncl = "lut.ncl"
-
-    def per_slice(slicen):
-        for k in range(2):
-            def get_substs(bits):
-                return dict(slice=slicen, k=str(k), lut_func=get_lut_function(bits))
-            nonrouting.fuzz_word_setting(cfg, "SLICE{}.K{}.INIT".format(slicen, k), 16, get_substs, empty_bitfile)
-
-    fuzzloops.parallel_foreach(["A", "B", "C", "D"], per_slice)
-
-
-if __name__ == "__main__":
-    main()
diff --git a/fuzzers/MachXO2/003-plc_lut_init/lut.ncl b/fuzzers/MachXO2/003-plc_lut_init/lut.ncl
deleted file mode 100644
index 2df3dc3..0000000
--- a/fuzzers/MachXO2/003-plc_lut_init/lut.ncl
+++ /dev/null
@@ -1,25 +0,0 @@
-::FROM-WRITER;
-design top
-{
-   device
-   {
-       architecture xo2c00;
-       device LCMXO2-4000HC;
-       package TQFP144;
-       performance "6";
-   }
-
-   comp SLICE_0
-   {
-      logical
-      {
-         cellmodel-name SLICE;
-         program "MODE:LOGIC "
-                 "K${k}::H${k}=${lut_func} "
-                 "F${k}:F ";
-         primitive K${k} i3_4_lut;
-      }
-      site R9C9${slice};
-   }
-
-}
diff --git a/metadata/MachXO2/LCMXO2-1200HC/globals.json b/metadata/MachXO2/LCMXO2-1200HC/globals.json
deleted file mode 100644
index a408e0b..0000000
--- a/metadata/MachXO2/LCMXO2-1200HC/globals.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-  "quadrants": {
-  },
-  "taps": {
-  },
-  "spines": {
-  }
-}
diff --git a/metadata/MachXO2/LCMXO2-256HC/globals.json b/metadata/MachXO2/LCMXO2-256HC/globals.json
deleted file mode 100644
index a408e0b..0000000
--- a/metadata/MachXO2/LCMXO2-256HC/globals.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-  "quadrants": {
-  },
-  "taps": {
-  },
-  "spines": {
-  }
-}
diff --git a/metadata/MachXO2/LCMXO2-4000HC/globals.json b/metadata/MachXO2/LCMXO2-4000HC/globals.json
deleted file mode 100644
index a408e0b..0000000
--- a/metadata/MachXO2/LCMXO2-4000HC/globals.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-  "quadrants": {
-  },
-  "taps": {
-  },
-  "spines": {
-  }
-}
diff --git a/tools/extract_tilegrid.py b/tools/extract_tilegrid.py
index 2b6b2ac..1411d66 100755
--- a/tools/extract_tilegrid.py
+++ b/tools/extract_tilegrid.py
@@ -17,7 +17,6 @@
 
 import sys, re
 import json, argparse
-import machxo2_tiles
 
 tile_re = re.compile(
     r'^Tile\s+([A-Z0-9a-z_/]+)\s+\((\d+), (\d+)\)\s+bitmap offset\s+\((\d+), (\d+)\)\s+\<([A-Z0-9a-z_/]+)>\s*$')
@@ -26,10 +25,6 @@
     r'^\s+([A-Z0-9_]+) \((-?\d+), (-?\d+)\)')
 
 parser = argparse.ArgumentParser(description=__doc__)
-parser.add_argument('family', type=str,
-                    help="device family")
-parser.add_argument('device', type=str,
-                    help="device name")
 parser.add_argument('infile', type=argparse.FileType('r'),
                     help="input file from bstool")
 parser.add_argument('outfile', type=argparse.FileType('w'),
@@ -39,38 +34,19 @@
     args = parser.parse_args(argv[1:])
     tiles = {}
     current_tile = None
-    family = args.family
-    device = args.device
     for line in args.infile:
         tile_m = tile_re.match(line)
         if tile_m:
             name = tile_m.group(6)
-            if (family == "ECP5"):
-                current_tile = {
-                    "type": tile_m.group(1),
-                    "start_bit": int(tile_m.group(4)),
-                    "start_frame": int(tile_m.group(5)),
-                    "rows": int(tile_m.group(2)),
-                    "cols": int(tile_m.group(3)),
-                    "sites": []
-                }
-                identifier = name + ":" + tile_m.group(1)
-            elif (family == "MachXO2"):
-                # MachXO2 has the frames/bit and the rows/cols index reversed
-                # compared to ECP5
-                current_tile = {
-                    "type": tile_m.group(1),
-                    "start_bit": int(tile_m.group(5)),
-                    "start_frame": int(tile_m.group(4)),
-                    "rows": int(tile_m.group(3)),
-                    "cols": int(tile_m.group(2)),
-                    "sites": []
-                }
-                identifier = machxo2_tiles.fix_name(name, device) + ":" + tile_m.group(1)
-            else:
-                print("Unknown family: " + family)
-                sys.exit(1)
-
+            current_tile = {
+                "type": tile_m.group(1),
+                "start_bit": int(tile_m.group(4)),
+                "start_frame": int(tile_m.group(5)),
+                "rows": int(tile_m.group(2)),
+                "cols": int(tile_m.group(3)),
+                "sites": []
+            }
+            identifier = name + ":" + tile_m.group(1)
             assert identifier not in tiles
             tiles[identifier] = current_tile
         else:
diff --git a/tools/get_tilegrid_all.py b/tools/get_tilegrid_all.py
index 5882891..5e687b9 100755
--- a/tools/get_tilegrid_all.py
+++ b/tools/get_tilegrid_all.py
@@ -23,7 +23,7 @@
         for device in sorted(devices["families"][family]["devices"].keys()):
             diamond.run(device, "work_tilegrid/wire.v")
             output_file = path.join(database.get_db_subdir(family, device), "tilegrid.json")
-            extract_tilegrid.main(["extract_tilegrid", family, device, "work_tilegrid/wire.tmp/output.test", output_file])
+            extract_tilegrid.main(["extract_tilegrid", "work_tilegrid/wire.tmp/output.test", output_file])
 
 
 if __name__ == "__main__":
diff --git a/tools/html_tilegrid.py b/tools/html_tilegrid.py
index 67e1b09..cc7e683 100755
--- a/tools/html_tilegrid.py
+++ b/tools/html_tilegrid.py
@@ -46,7 +46,6 @@
 
     max_row = device_info["max_row"]
     max_col = device_info["max_col"]
-    col_bias = device_info["col_bias"]
 
     tiles = []
     for i in range(max_row + 1):
@@ -72,10 +71,10 @@
     for trow in tiles:
         print("<tr>", file=f)
         row_max_height = 0
-        for tloc in trow[col_bias:]:
+        for tloc in trow:
             row_max_height = max(row_max_height, len(tloc))
         row_height = max(75, 30 * row_max_height)
-        for tloc in trow[col_bias:]:
+        for tloc in trow:
             print("<td style='border: 2px solid black; height: {}px'>".format(row_height), file=f)
             for tile in tloc:
                 print(
diff --git a/tools/machxo2_tiles.py b/tools/machxo2_tiles.py
deleted file mode 100644
index 6def0de..0000000
--- a/tools/machxo2_tiles.py
+++ /dev/null
@@ -1,103 +0,0 @@
-"""
-This helps fix missing tile positions in the MachXO2 family
-"""
-
-import re, sys
-import database
-
-rc_regex = re.compile(r"[A-Za-z0-9_]*R(\d+)C(\d+)")
-# MachXO2-specific
-center_regex = re.compile(r"CENTER(\d+)")
-centerb_regex = re.compile(r"CENTER_B")
-centert_regex = re.compile(r"CENTER_T")
-centerebr_regex = re.compile(r"CENTER_EBR(\d+)")
-t_regex = re.compile(r"[A-Za-z0-9_]*T(\d+)")
-b_regex = re.compile(r"[A-Za-z0-9_]*B(\d+)")
-l_regex = re.compile(r"[A-Za-z0-9_]*L(\d+)")
-r_regex = re.compile(r"[A-Za-z0-9_]*R(\d+)")
-
-def append_position(left_side, row, col):
-    return left_side + "_R" + str(row) + "C" + str(col)
-
-def update_name(name, center_col, ebr_row, right, bottom):
-    # Match in order of most-specific to least-specific
-    # (E.g. CENTER matches "R" regex too)
-    left = 1
-    top = 0
-
-    row = top
-    col = left
-
-    rc = rc_regex.match(name)
-    if rc:
-        # no need to rename
-        return name
-
-    centert = centert_regex.match(name)
-    if centert:
-        row = top
-        col = center_col
-        return append_position(name, row, col)
-
-    centerb = centerb_regex.match(name)
-    if centerb:
-        row = bottom
-        col = center_col
-        return append_position(name, row, col)
-
-    centerebr = centerebr_regex.match(name)
-    if centerebr:
-        row = ebr_row
-        col = center_col+1
-        return append_position(name, row, col)
-
-    center = center_regex.match(name)
-    if center:
-        row = int(center.group(1))
-        col = center_col
-        return append_position(name, row, col)
-
-    t = t_regex.match(name)
-    if t:
-        row = top
-        col = int(t.group(1))
-        return append_position(name, row, col)
-
-    b = b_regex.match(name)
-    if b:
-        row = bottom
-        col = int(b.group(1))
-        return append_position(name, row, col)
-
-    l = l_regex.match(name)
-    if l:
-        row = int(l.group(1))
-        col = left
-        return append_position(name, row, col)
-
-    r = r_regex.match(name)
-    if r:
-        row = int(r.group(1))
-        col = right
-        return append_position(name, row, col)
-
-def fix_name(name, device):
-
-    device_info = database.get_devices()["families"]["MachXO2"]["devices"][device]
-    max_row = device_info["max_row"]
-    max_col = device_info["max_col"]
-
-    if (device == 'LCMXO2-256HC'):
-        center_col = 5
-        ebr_row = 0 # don't care
-    elif (device == 'LCMXO2-1200HC'):
-        center_col = 13
-        ebr_row = 6
-    elif (device == 'LCMXO2-4000HC'):
-        center_col = 16
-        ebr_row = 11
-    else:
-        print("unknown device: " + device)
-        sys.exit(1)
-
-    return update_name(name, center_col, ebr_row, max_col, max_row)