Skip to content

Commit

Permalink
updated make setup
Browse files Browse the repository at this point in the history
  • Loading branch information
marwaneltoukhy committed Nov 27, 2023
1 parent d9ddc78 commit 25f10a2
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 24 deletions.
69 changes: 45 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
MAKEFLAGS+=--warn-undefined-variables

export CARAVEL_ROOT?=$(PWD)/caravel
PRECHECK_ROOT?=${HOME}/mpw_precheck
export PRECHECK_ROOT?=${HOME}/mpw_precheck
export MCW_ROOT?=$(PWD)/mgmt_core_wrapper
SIM?=RTL

Expand All @@ -41,11 +41,11 @@ export DISABLE_LVS?=0

export ROOTLESS

ifeq ($(PDK),sky130A)
SKYWATER_COMMIT=f70d8ca46961ff92719d8870a18a076370b85f6c
export OPEN_PDKS_COMMIT?=78b7bc32ddb4b6f14f76883c2e2dc5b5de9d1cbc
export OPENLANE_TAG?=2023.07.19-1
MPW_TAG ?= mpw-9g
# ifeq ($(PDK),sky130A)
# SKYWATER_COMMIT=f70d8ca46961ff92719d8870a18a076370b85f6c
# export OPEN_PDKS_COMMIT?=78b7bc32ddb4b6f14f76883c2e2dc5b5de9d1cbc
# export OPENLANE_TAG?=2023.07.19-1
# MPW_TAG ?= mpw-9g

ifeq ($(CARAVEL_LITE),1)
CARAVEL_NAME := caravel-lite
Expand All @@ -57,25 +57,25 @@ else
CARAVEL_TAG := $(MPW_TAG)
endif

endif
# endif

ifeq ($(PDK),sky130B)
SKYWATER_COMMIT=f70d8ca46961ff92719d8870a18a076370b85f6c
export OPEN_PDKS_COMMIT?=78b7bc32ddb4b6f14f76883c2e2dc5b5de9d1cbc
export OPENLANE_TAG?=2023.07.19-1
MPW_TAG ?= mpw-9g
# ifeq ($(PDK),sky130B)
# SKYWATER_COMMIT=f70d8ca46961ff92719d8870a18a076370b85f6c
# export OPEN_PDKS_COMMIT?=78b7bc32ddb4b6f14f76883c2e2dc5b5de9d1cbc
# export OPENLANE_TAG?=2023.07.19-1
# MPW_TAG ?= mpw-9g

ifeq ($(CARAVEL_LITE),1)
CARAVEL_NAME := caravel-lite
CARAVEL_REPO := https://github.com/efabless/caravel-lite
CARAVEL_TAG := $(MPW_TAG)
else
CARAVEL_NAME := caravel
CARAVEL_REPO := https://github.com/efabless/caravel
CARAVEL_TAG := $(MPW_TAG)
endif
# ifeq ($(CARAVEL_LITE),1)
# CARAVEL_NAME := caravel-lite
# CARAVEL_REPO := https://github.com/efabless/caravel-lite
# CARAVEL_TAG := $(MPW_TAG)
# else
# CARAVEL_NAME := caravel
# CARAVEL_REPO := https://github.com/efabless/caravel
# CARAVEL_TAG := $(MPW_TAG)
# endif

endif
# endif

ifeq ($(PDK),gf180mcuD)

Expand All @@ -101,7 +101,9 @@ install:
rm -rf $(CARAVEL_ROOT) && sleep 2;\
fi
echo "Installing $(CARAVEL_NAME).."
git clone -b $(CARAVEL_TAG) $(CARAVEL_REPO) $(CARAVEL_ROOT) --depth=1
@mkdir -p $(CARAVEL_ROOT)
cd $(CARAVEL_ROOT) && \
curl -L $(CARAVEL_REPO)/tarball/$(CARAVEL_COMMIT) | tar -xvzC . --strip-components=1

# Install DV setup
.PHONY: simenv
Expand All @@ -114,7 +116,24 @@ simenv-cocotb:
docker pull efabless/dv:cocotb

.PHONY: setup
setup: check_dependencies install check-env install_mcw openlane pdk-with-volare setup-timing-scripts setup-cocotb precheck
# setup: check_dependencies install check-env install_mcw openlane pdk-with-volare setup-timing-scripts setup-cocotb precheck
setup: check-python check_dependencies setup-cocotb install-volare
# setup:
./venv/bin/$(PYTHON_BIN) -m pip install --upgrade --no-cache-dir requests
./venv/bin/$(PYTHON_BIN) -u scripts/get_tools.py --openlane_root $(OPENLANE_ROOT) --precheck_root $(PRECHECK_ROOT) --pdk_root $(PDK_ROOT) --caravel_root $(CARAVEL_ROOT) --mcw_root $(MCW_ROOT) --timing_root $(TIMING_ROOT)


.PHONY: install-volare
install-volare:
rm -rf ./venv
$(PYTHON_BIN) -m venv ./venv
./venv/bin/$(PYTHON_BIN) -m pip install --upgrade --no-cache-dir pip
./venv/bin/$(PYTHON_BIN) -m pip install --upgrade --no-cache-dir volare

check-python:
ifeq ($(shell which python3),)
$(error Please install python 3.6+)
endif

# Openlane
blocks=$(shell cd openlane && find * -maxdepth 0 -type d)
Expand Down Expand Up @@ -317,6 +336,8 @@ check_dependencies:
mkdir $(PWD)/dependencies; \
fi

# export CARAVEL_COMMIT=$(shell python3 scripts/get_tools.py)


export CUP_ROOT=$(shell pwd)
export TIMING_ROOT?=$(shell pwd)/dependencies/timing-scripts
Expand Down
113 changes: 113 additions & 0 deletions scripts/get_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import argparse
import json
import os
import shutil
import tarfile
import requests
import volare
from rich.progress import Progress


def parse_json_file(url):
"""Parses a JSON file from the given URL.
Args:
url: The URL of the JSON file.
Returns:
A Python dictionary containing the parsed JSON data.
"""

response = requests.get(url)
if response.status_code != 200:
raise ValueError(f'Failed to get JSON data from {url}: {response.status_code}')

data = response.json()
json_data = json.dumps(data, indent=4)
# Write the JSON data to a file
with open('tool_versions.json', 'w') as file:
file.write(json_data)
return data


def download_tools(openlane_root, precheck_root, pdk_root, caravel_root, mcw_root, timing_root):
"""Downloads the tools from the upstream GitHub repo.
"""
url = 'https://raw.githubusercontent.com/efabless/central_CI/main/tools.json'
data = parse_json_file(url)
with Progress() as progress:
task = progress.add_task("[cyan]Downloading Tools...", total=6)
for key, value in data.items():
if key == "OpenLane":
progress.update(task, description="[cyan]Downloading OpenLane...")
download_tar("OpenLane", value['commit'], value['url'], openlane_root)
progress.update(task, completed=1)
elif key == "pdk":
progress.update(task, description="[cyan]Downloading pdk...")
volare.enable(pdk_root, "sky130", value['commit'])
progress.update(task, completed=1)
elif key == "precheck":
progress.update(task, description="[cyan]Downloading precheck...")
download_tar("precheck", value['commit'], value['url'], precheck_root)
progress.update(task, completed=1)
elif key == "caravel":
progress.update(task, description="[cyan]Downloading caravel...")
download_tar("caravel", value['commit'], value['url'], caravel_root)
progress.update(task, completed=1)
elif key == "mgmt_core_wrapper":
progress.update(task, description="[cyan]Downloading mgmt_core_wrapper...")
download_tar("mgmt_core_wrapper", value['commit'], value['url'], mcw_root)
progress.update(task, completed=1)
elif key == "timing_scripts":
progress.update(task, description="[cyan]Downloading timing_scripts...")
download_tar("timing_scripts", value['commit'], value['url'], timing_root)
progress.update(task, completed=1)


def download_tar(tool, version, url, tool_path):
if os.path.isdir(tool_path):
shutil.rmtree(tool_path)
os.makedirs(tool_path)
name = url.split("/")[-1]
owner = url.split("/")[-2]
# print(f"downloading {tool}")
response = requests.get(f'{url}/tarball/{version}')
if response.status_code != 200:
raise Exception(f"Failed to download {tool}")
with open(f'{os.path.dirname(tool_path)}/{version}.tar.gz', 'wb') as file:
file.write(response.content)
# print(f"extracting {os.path.dirname(tool_path)}/{version}.tar.gz")

tar = tarfile.open(f'{os.path.dirname(tool_path)}/{version}.tar.gz', 'r:gz')
tar.extractall(path=os.path.dirname(tool_path))
tar.close()
os.rename(f'{os.path.dirname(tool_path)}/{owner}-{name}-{version[0:7]}', f'{tool_path}')
os.remove(f'{os.path.dirname(tool_path)}/{version}.tar.gz')


def main():
parser = argparse.ArgumentParser()
parser.add_argument('--openlane_root', required=True,
help='Path to the OpenLANE root directory')
parser.add_argument('--precheck_root', required=True,
help='Path to the Precheck root directory')
parser.add_argument('--pdk_root', required=True,
help='Path to the PDK root directory')
parser.add_argument('--caravel_root', required=True,
help='Path to the Caravel root directory')
parser.add_argument('--mcw_root', required=True,
help='Path to the Mgmt Core Wrapper root directory')
parser.add_argument('--timing_root', required=True,
help='Path to the Timing Scripts root directory')

args = parser.parse_args()
download_tools(openlane_root=args.openlane_root,
precheck_root=args.precheck_root,
pdk_root=args.pdk_root,
caravel_root=args.caravel_root,
mcw_root=args.mcw_root,
timing_root=args.timing_root)


if __name__ == '__main__':
main()

0 comments on commit 25f10a2

Please sign in to comment.