Merge "Update bazel airgap prep script with removed chisel dependency"
diff --git a/util/bazel_airgapped.patch b/util/bazel_airgapped.patch
new file mode 100644
index 0000000..98cb12a
--- /dev/null
+++ b/util/bazel_airgapped.patch
@@ -0,0 +1,155 @@
+diff --git a/BUILD.bazel b/BUILD.bazel
+index b131709..b297981 100644
+--- a/BUILD.bazel
++++ b/BUILD.bazel
+@@ -17,14 +17,7 @@ filegroup(
+         "//hw:check_tool_requirements.core",
+         "@axi2sramcrs//:BUILD",
+         "@isp_yocto//:BUILD",
+-    ] + select({
+-        "//rules:airgapped_env": [
+-            "@fastvdma_core//:fastvdma.core",
+-            "@kelvin_core//:kelvin.core",
+-        ],
+-        "//conditions:default": [
+-            "//hw/top_matcha/ip/dma/chisel:fastvdma.core",
+-            "@kelvin_hw//hdl/chisel:kelvin.core",
+-        ],
+-    }),
++        "@fastvdma_core//:fastvdma.core",
++        "@kelvin_core//:kelvin.core",
++    ],
+ )
+diff --git a/hw/BUILD b/hw/BUILD
+index ec4c0d3..56ce85c 100644
+--- a/hw/BUILD
++++ b/hw/BUILD
+@@ -83,14 +83,7 @@ filegroup(
+     srcs = glob(["**"]) + [
+         "//hw/top_matcha:all_files",
+         "@lowrisc_opentitan//hw/dv:all_files",
+-    ] + select({
+-        "//rules:airgapped_env": [
+-            "@fastvdma_core//:all_files",
+-            "@kelvin_core//:all_files",
+-        ],
+-        "//conditions:default": [
+-            "//hw/top_matcha/ip/dma/chisel:fastvdma_core",
+-            "@kelvin_hw//hdl/chisel:kelvin_core",
+-        ],
+-    }),
++        "@fastvdma_core//:all_files",
++        "@kelvin_core//:all_files",
++    ],
+ )
+diff --git a/hw/top_matcha/ip/dma/chisel/BUILD b/hw/top_matcha/ip/dma/chisel/BUILD
+deleted file mode 100644
+index 2a102ea..0000000
+--- a/hw/top_matcha/ip/dma/chisel/BUILD
++++ /dev/null
+@@ -1,45 +0,0 @@
+-# Copyright 2023 Google LLC
+-#
+-# Licensed under the Apache License, Version 2.0 (the "License");
+-# you may not use this file except in compliance with the License.
+-# You may obtain a copy of the License at
+-#
+-#     http://www.apache.org/licenses/LICENSE-2.0
+-#
+-# Unless required by applicable law or agreed to in writing, software
+-# distributed under the License is distributed on an "AS IS" BASIS,
+-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-# See the License for the specific language governing permissions and
+-# limitations under the License.
+-
+-genrule(
+-    name = "fastvdma_verilog",
+-    srcs = [
+-        "//hw/top_matcha/ip/dma/chisel/src:DMATop.sv"
+-    ],
+-    outs = [
+-        "fastvdma.sv",
+-    ],
+-
+-    cmd = """
+-    cat $(location //hw/top_matcha/ip/dma/chisel/src:DMATop.sv) >> $(location fastvdma.sv)
+-    """,
+-    visibility = ["//visibility:public"],
+-)
+-
+-# Generate fastvdma.core from this template so it can sit at the same GenDir as
+-# the RTL file.
+-genrule(
+-    name = "fastvdma_core",
+-    srcs = [
+-        "fastvdma.core.in",
+-        "fastvdma_verilog",
+-    ],
+-    outs = [
+-        "fastvdma.core",
+-    ],
+-    cmd = """
+-    cp -f $(location fastvdma.core.in) $(location fastvdma.core)
+-    """,
+-    visibility = ["//visibility:public"],
+-)
+diff --git a/hw/top_matcha/ip/dma/chisel/src/BUILD b/hw/top_matcha/ip/dma/chisel/src/BUILD
+deleted file mode 100644
+index 745cb3f..0000000
+--- a/hw/top_matcha/ip/dma/chisel/src/BUILD
++++ /dev/null
+@@ -1,54 +0,0 @@
+-# Copyright 2024 Google LLC
+-#
+-# Licensed under the Apache License, Version 2.0 (the "License");
+-# you may not use this file except in compliance with the License.
+-# You may obtain a copy of the License at
+-#
+-#     http://www.apache.org/licenses/LICENSE-2.0
+-#
+-# Unless required by applicable law or agreed to in writing, software
+-# distributed under the License is distributed on an "AS IS" BASIS,
+-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-# See the License for the specific language governing permissions and
+-# limitations under the License.
+-
+-load("@kelvin_hw//rules:chisel.bzl", "chisel_cc_library", "chisel_library")
+-
+-package(default_visibility = ["//visibility:public"])
+-
+-chisel_library(
+-    name = "fastvdma_tlul",
+-    srcs = [
+-        "DMAConfig.scala",
+-        "DMATop.scala",
+-        "bus/TLUL.scala",
+-        "csr/CSR.scala",
+-        "csr/CSRBusBundle.scala",
+-        "csr/CSRRegBundle.scala",
+-        "csr/ClearCSR.scala",
+-        "csr/SetCSR.scala",
+-        "csr/SimpleCSR.scala",
+-        "csr/StatusCSR.scala",
+-        "frontend/BusBase.scala",
+-        "frontend/TLULCSR.scala",
+-        "frontend/TLULReader.scala",
+-        "frontend/TLULWriter.scala",
+-        "worker/AddressGenerator.scala",
+-        "worker/AddressGeneratorCtlBundle.scala",
+-        "worker/InterruptBundle.scala",
+-        "worker/InterruptController.scala",
+-        "worker/SyncBundle.scala",
+-        "worker/TransferSplitter.scala",
+-        "worker/WorkerCSRWrapper.scala",
+-        "worker/XferDescBundle.scala",
+-    ],
+-    deps = [
+-    ],
+-)
+-
+-chisel_cc_library(
+-    name = "fastvdma_cc_library",
+-    chisel_lib = ":fastvdma_tlul",
+-    emit_class = "DMAController.EmitDMA",
+-    module_name = "DMATop",
+-)
diff --git a/util/prep-bazel-airgapped-build.sh b/util/prep-bazel-airgapped-build.sh
index 75a470f..905771e 100755
--- a/util/prep-bazel-airgapped-build.sh
+++ b/util/prep-bazel-airgapped-build.sh
@@ -46,7 +46,7 @@
 
 : "${BAZEL_VERSION:=$(cat ${REPO_TOP}/.bazelversion)}"
 
-: "${BAZEL_AIRGAPPED_DIR:=bazel-airgapped_ot9d059106}"
+: "${BAZEL_AIRGAPPED_DIR:=bazel-airgapped-ot9d059106}"
 : "${BAZEL_DISTDIR:=bazel-distdir}"
 : "${BAZEL_CACHEDIR:=bazel-cache}"
 : "${BAZEL_PYTHON_WHEEL_REPO:=ot_python_wheels}"
@@ -96,6 +96,11 @@
 done
 shift $((OPTIND - 1))
 
+if [[ -z ${ROOTDIR} ]]; then
+  echo "source build/setup.sh first"
+  exit 1
+fi
+
 # We do not accept additional arguments.
 if [[ "$#" -gt 0 ]]; then
   echo "Unexpected arguments:" "$@" >&2
@@ -155,7 +160,7 @@
   ../bazel build @additional_distfiles//:archives.tar
   tar xvf bazel-bin/external/additional_distfiles/archives.tar \
     -C "../${BAZEL_DISTDIR}" \
-    --strip-components=3
+    --strip-components=2
   cd ..
   rm -rf bazel-repo
   echo "Done."
@@ -170,6 +175,18 @@
   echo "Preparing bazel offline cachedir ..."
   cd ${REPO_TOP}
   mkdir -p ${BAZEL_AIRGAPPED_DIR}/${BAZEL_CACHEDIR}
+
+  # Prepare airgap offline built cores
+  if [[ ! -f "${ROOTDIR}/out/matcha/hw/fastvdma_core/fastvdma.core" ]]; then
+    mkdir -p ${ROOTDIR}/out/matcha/hw/fastvdma_core
+    touch ${ROOTDIR}/out/matcha/hw/fastvdma_core/fastvdma.core
+  fi
+  if [[ ! -f "${ROOTDIR}/out/kelvin/hw/kelvin_core/kelvin.core" ]]; then
+    mkdir -p ${ROOTDIR}/out/kelvin/hw/kelvin_core
+    touch ${ROOTDIR}/out/kelvin/hw/kelvin_core/kelvin.core
+  fi
+  # Patch airgap build environment
+  git apply util/bazel_airgapped.patch
   # Make bazel forget everything it knows, then download everything.
   ${BAZEL_AIRGAPPED_DIR}/bazel clean --expunge
   # Only pick up the packages required by matcha
@@ -186,10 +203,13 @@
     @remotejdk11_linux//... \
     @rules_foreign_cc//toolchains/... \
     @rust_analyzer_1.67.0_tools//... \
-    @rust_linux_x86_64__x86_64-unknown-linux-gnu__nightly_tools//...
+    @rust_linux_x86_64__x86_64-unknown-linux-gnu__nightly_tools//... \
+    @org_chipsalliance_chisel_plugin//... \
+    @kelvin_hw//lib:chisel_lib
   cp -R $(${BAZEL_AIRGAPPED_DIR}/bazel info output_base)/external/${BAZEL_PYTHON_WHEEL_REPO} \
     ${BAZEL_AIRGAPPED_DIR}/
   echo "Done."
+  git reset --hard
 fi
 
 ################################################################################