[util] hack to enable top_englishbreakfast generation

- flash hjson generation needs to happen before alert counting
- otherwise the hjson update will not be picked up and the generated output may mismatch

Signed-off-by: Timothy Chen <timothytim@google.com>

[util] Add back option that was removed

Signed-off-by: Timothy Chen <timothytim@google.com>

[util] revert hacks made for top_englishbreakfast.

Now that topgen is multi-pass, the original flow will work.

Signed-off-by: Timothy Chen <timothytim@google.com>
diff --git a/hw/top_englishbreakfast/data/top_englishbreakfast.hjson b/hw/top_englishbreakfast/data/top_englishbreakfast.hjson
index 3b2ce4b..3802d7e 100644
--- a/hw/top_englishbreakfast/data/top_englishbreakfast.hjson
+++ b/hw/top_englishbreakfast/data/top_englishbreakfast.hjson
@@ -643,7 +643,7 @@
   // list all modules that expose alerts
   // first item goes to LSB of the alert source
   alert_module: [ "aes", "sensor_ctrl", "lc_ctrl",
-                  "sram_ctrl_main", "sram_ctrl_ret"]
+                  "sram_ctrl_main", "sram_ctrl_ret", "flash_ctrl"]
 
   // generated list of alerts:
   alert: [
diff --git a/util/topgen.py b/util/topgen.py
index b100619..cda48cf 100755
--- a/util/topgen.py
+++ b/util/topgen.py
@@ -22,7 +22,7 @@
 from reggen import gen_dv, gen_rtl, validate
 from topgen import amend_clocks, get_hjsonobj_xbars
 from topgen import intermodule as im
-from topgen import merge_top, search_ips, validate_top
+from topgen import merge_top, search_ips, check_flash, validate_top
 from topgen.c import TopGenC
 
 # Common header for generated files
@@ -880,6 +880,9 @@
     hjson_dir = Path(args.topcfg).parent
 
     for ip in generated_list:
+        # For modules that are generated prior to gathering, we need to take it from
+        # the ouptput path.  For modules not generated before, it may exist in a
+        # pre-defined area already.
         log.info("Appending {}".format(ip))
         if ip == 'clkmgr' or (pass_idx > 0):
             ip_hjson = Path(out_path) / "ip/{}/data/autogen/{}.hjson".format(
@@ -953,6 +956,9 @@
 
     completecfg = merge_top(topcfg, ip_objs, xbar_objs)
 
+    # Generate flash controller and flash memory
+    generate_flash(topcfg, out_path)
+
     # Generate PLIC
     if not args.no_plic and \
        not args.alert_handler_only and \
@@ -976,9 +982,6 @@
     # Generate rstmgr
     generate_rstmgr(completecfg, out_path)
 
-    # Generate flash
-    generate_flash(completecfg, out_path)
-
     # Generate top only modules
     # These modules are not templated, but are not in hw/ip
     generate_top_only(top_only_list, out_path, topname)
diff --git a/util/topgen/__init__.py b/util/topgen/__init__.py
index d469f1e..d8a3400 100644
--- a/util/topgen/__init__.py
+++ b/util/topgen/__init__.py
@@ -5,4 +5,4 @@
 from .lib import get_hjsonobj_xbars, search_ips  # noqa: F401
 # noqa: F401 These functions are used in topgen.py
 from .merge import amend_clocks, merge_top  # noqa: F401
-from .validate import validate_top  # noqa: F401
+from .validate import validate_top, check_flash  # noqa: F401