Skip to content

Commit

Permalink
Flow updates (#24)
Browse files Browse the repository at this point in the history
* Updating to new flow

* Update README
  • Loading branch information
dpetrisko authored Nov 21, 2024
1 parent 351b140 commit d0908d0
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bsg_cadenv/
install/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
path = black-parrot
url = https://github.com/black-parrot/black-parrot/
branch = master
ignore = dirty
[submodule "black-parrot-sdk"]
path = black-parrot-sdk
url = https://github.com/black-parrot-sdk/black-parrot-sdk/
branch = master
ignore = dirty
[submodule "black-parrot-tools"]
path = black-parrot-tools
url = https://github.com/black-parrot/black-parrot-tools/
branch = master
ignore = dirty
63 changes: 36 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
TOP ?= $(shell git rev-parse --show-toplevel)
include $(TOP)/Makefile.common
include $(TOP)/Makefile.env

export BP_RTL_DIR := $(TOP)/black-parrot
export BP_TOOLS_DIR := $(TOP)/black-parrot-tools
export BP_SDK_DIR := $(TOP)/black-parrot-sdk
include $(BP_SIM_MK_DIR)/Makefile.docker

checkout:
git fetch --all
git submodule update --init
$(MAKE) -C $(BP_RTL_DIR) checkout
$(MAKE) -C $(BP_TOOLS_DIR) checkout
$(MAKE) -C $(BP_SDK_DIR) checkout
checkout: ## checkout submodules, but not recursively
@$(MKDIR) -p $(BP_SIM_TOUCH_DIR)
@$(GIT) fetch --all
@$(GIT) submodule sync
@$(GIT) submodule update --init
@$(MAKE) -C $(BP_SIM_RTL_DIR) checkout BP_RTL_DIR=$(BP_SIM_RTL_DIR)
@$(MAKE) -C $(BP_SIM_TOOLS_DIR) checkout BP_TOOLS_DIR=$(BP_SIM_TOOLS_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) checkout BP_SDK_DIR=$(BP_SIM_SDK_DIR)

prep_lite: checkout
$(MAKE) -C $(BP_RTL_DIR) libs_lite
$(MAKE) -C $(BP_TOOLS_DIR) tools_lite
$(MAKE) -C $(BP_SDK_DIR) sdk_lite
$(MAKE) -C $(BP_SDK_DIR) prog_lite
apply_patches: ## applies patches to submodules
apply_patches: build.patch
$(eval $(call bsg_fn_build_if_new,patch,$(CURDIR),$(BP_SIM_TOUCH_DIR)))
%/.patch_build: checkout
@$(MAKE) -C $(BP_SIM_RTL_DIR) apply_patches BP_RTL_DIR=$(BP_SIM_RTL_DIR)
@$(MAKE) -C $(BP_SIM_TOOLS_DIR) apply_patches BP_TOOLS_DIR=$(BP_SIM_TOOLS_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) apply_patches BP_SDK_DIR=$(BP_SIM_SDK_DIR)
@echo "Patching successful, ignore errors"

prep_lite: ## Minimal preparation for simulation
prep_lite: apply_patches
@$(MAKE) -C $(BP_SIM_RTL_DIR) libs_lite BP_RTL_DIR=$(BP_SIM_RTL_DIR)
@$(MAKE) -C $(BP_SIM_TOOLS_DIR) tools_lite BP_TOOLS_DIR=$(BP_SIM_TOOLS_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) sdk_lite BP_SDK_DIR=$(BP_SIM_SDK_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) prog_lite BP_SDK_DIR=$(BP_SIM_SDK_DIR)

prep: ## Standard preparation for simulation
prep: prep_lite
$(MAKE) -C $(BP_RTL_DIR) libs
$(MAKE) -C $(BP_TOOLS_DIR) tools
$(MAKE) -C $(BP_SDK_DIR) sdk
$(MAKE) -C $(BP_SDK_DIR) prog
@$(MAKE) -C $(BP_SIM_RTL_DIR) libs BP_RTL_DIR=$(BP_SIM_RTL_DIR)
@$(MAKE) -C $(BP_SIM_TOOLS_DIR) tools BP_TOOLS_DIR=$(BP_SIM_TOOLS_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) sdk BP_SDK_DIR=$(BP_SIM_SDK_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) prog BP_SDK_DIR=$(BP_SIM_SDK_DIR)

prep_bsg: ## Extra preparation for BSG users
prep_bsg: prep
$(MAKE) -C $(BP_RTL_DIR) libs_bsg
$(MAKE) -C $(BP_TOOLS_DIR) tools_bsg
$(MAKE) -C $(BP_SDK_DIR) sdk_bsg
$(MAKE) -C $(BP_SDK_DIR) prog_bsg

## This target just wipes the whole repo clean.
# Use with caution.
bleach_all:
cd $(TOP); git clean -fdx; git submodule deinit -f .
@$(MAKE) -C $(BP_SIM_RTL_DIR) libs_bsg BP_RTL_DIR=$(BP_SIM_RTL_DIR)
@$(MAKE) -C $(BP_SIM_TOOLS_DIR) tools_bsg BP_TOOLS_DIR=$(BP_SIM_TOOLS_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) sdk_bsg BP_SDK_DIR=$(BP_SIM_SDK_DIR)
@$(MAKE) -C $(BP_SIM_SDK_DIR) prog_bsg BP_SDK_DIR=$(BP_SIM_SDK_DIR)

129 changes: 129 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#############################
# Makefile functions
#############################
# Saves initial values so that we can filter them later
VARS_OLD := $(.VARIABLES)

define bsg_fn_upper
$(shell echo $(1) | tr a-z A-Z)
endef
define bsg_fn_lower
$(shell echo $(1) | tr A-Z a-z)
endef
bsg_var_blank :=
define bsg_var_newline

$(bsg_var_blank)
endef

bsg_var_percent := %

define bsg_fn_patch_if_new
$(eval apply_stage_patch := git apply --ignore-whitespace --ignore-space-change)
$(eval apply_commit_patch := git am --ignore-whitespace --ignore-space-change)
$(eval check_patch := $(apply_stage_patch) --check --reverse)
$(eval src_root := $(1))
$(eval patch_root := $(2))
$(eval patch_list := $(wildcard $(patch_root)/*.patch))
$(eval patch_is_top := $(findstring patches,$(lastword $(subst /, ,$(dir $(patch_root))))))
for p in $(patch_list); \
do \
echo "Checking if patch $$p is applicable"; \
cd $(src_root); $(check_patch) $$p && continue; \
echo "Patch is unapplied..."; \
if [ ! -z "$$patch_is_top" ]; then \
echo "Applying patch to sub-directory $(src_root);" \
cd $(src_root); $(apply_commit_patch) $$p; \
echo "Patch applied!"; \
else \
echo "Applying patch to top-level $(src_root);" \
cd $(src_root); $(apply_stage_patch) $$p; \
echo "Patch applied!"; \
fi \
done
endef

define bsg_fn_build_tag
$(eval name := $(1))
$(eval src_dir := $(2))
$(eval touch_dir := $(3))
$(eval tag := $(4))
$(eval internal_target := $(src_dir)/.$(name)_build)
$(eval external_target := build.$(name))
$(eval rebuild_target := rebuild.$(name))
$(external_target): | $(tag)
$(rebuild_target):
rm -f $(touch_dir)/$(name).*
+$(MAKE) $(tag)
$(tag):
+$(MAKE) $(internal_target)
touch $(tag)
endef

define bsg_fn_build_if_missing
$(eval name := $(1))
$(eval src_dir := $(2))
$(eval touch_dir := $(3))
$(eval tag := $(addprefix $(touch_dir)/$(name).,any))
$(call bsg_fn_build_tag,$(name),$(src_dir),$(touch_dir),$(tag))
endef

define bsg_fn_build_if_new
$(eval name := $(1))
$(eval src_dir := $(2))
$(eval touch_dir := $(3))
$(eval hash := $(shell cd $(src_dir); git rev-parse HEAD))
$(eval tag := $(addprefix $(touch_dir)/$(name).,$(hash)))
$(call bsg_fn_build_tag,$(name),$(src_dir),$(touch_dir),$(tag))
endef


define bsg_fn_info
$(eval $@_msg = $(1))
$(eval $@_prefix = "BSG-INFO: ")
echo "${$@_prefix} ${$@_msg}";
endef

define bsg_fn_warn
$(eval $@_msg = $(1))
$(eval $@_prefix = "BSG-WARN: ")
echo "${$@_prefix} ${$@_msg}";
endef

define bsg_fn_error
$(eval $@_msg = $(1))
$(eval $@_prefix = "BSG-ERROR: ")
echo "${$@_prefix} ${$@_msg}"; \
exit -1;
endef

# Global Makefile settings
SHELL := /bin/bash
MAKEFLAGS += --warn-undefined-variables

# Global help target
.DEFAULT_GOAL: help
.PHONY: help
help: ## prints this message
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}'

# Global reset
.PHONY: bleach_all
bleach_all: ## wipes the whole repo clean. Use with caution
@cd $(TOP); git clean -ffdx; git submodule deinit -f .

#############################
# Paths
#############################
BP_SIM_DIR ?= $(TOP)
BP_SIM_MK_DIR ?= $(BP_SIM_DIR)/mk
BP_SIM_RTL_DIR ?= $(BP_SIM_DIR)/black-parrot
BP_SIM_TOOLS_DIR ?= $(BP_SIM_DIR)/black-parrot-tools
BP_SIM_SDK_DIR ?= $(BP_SIM_DIR)/black-parrot-sdk
BP_SIM_DOCKER_DIR ?= $(BP_SIM_DIR)/docker
BP_SIM_INSTALL_DIR ?= $(BP_SIM_DIR)/install
BP_SIM_TOUCH_DIR ?= $(BP_SIM_INSTALL_DIR)/touchfiles

BSG_CADENV_DIR ?= $(BP_SIM_DIR)/install/bsg_cadenv

48 changes: 48 additions & 0 deletions Makefile.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

##########################################################
## User configuration
##########################################################
# Available platforms: ubuntu20.04
DOCKER_PLATFORM ?= ubuntu20.04

##########################################################
## Cad environment
##########################################################
ifneq ($(MAKECMDGOALS),help)
include $(BSG_CADENV_DIR)/cadenv.mk
%/cadenv.mk:
# BSG users leverage a machine-specific cadenv
# Here, we add sourcing to get these variables as well
@$(eval CADENV_URL := [email protected]:bespoke-silicon-group/bsg_cadenv)
@$(eval CADENV_EXISTS := $(shell git ls-remote --exit-code $(CADENV_URL) HEAD 2> /dev/null))
# Recursive make to include the new fragment
if [ -f "$(BSG_CADENV_DIR)/cadenv.mk" ]; then \
echo "bsg_cadenv already exists"; \
elif [[ ! -z "$(CADENV_EXISTS)" ]]; then \
echo "Cloning bsg_cadenv from $(CADENV_URL)"; \
git clone --recurse-submodules $(CADENV_URL) $(@D); \
else \
echo "bsg_cadenv not found"; \
mkdir -p $(@D); \
touch $@; \
fi
@echo "Successfully built $@!"
endif

#############################
# Cad settings
#############################

#############################
# Environment detection
#############################
CENTOS7 := $(if $(findstring CentOS Linux release 7,$(shell cat /etc/centos-release 2>/dev/null)),1,0)

##############################
# Executables
##############################
DOCKER ?= docker
GIT ?= git
CD ?= cd
MKDIR ?= mkdir

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Users who just want to test their setup and run a minimal BlackParrot test shoul
make prep_lite

# Running your first test
make -C black-parrot/bp_top/syn tire_kick
make -C black-parrot/bp_top/syn build.verilator sim.verilator

This should output (roughly)

Expand Down Expand Up @@ -101,9 +101,7 @@ For a painless Ubuntu build, download and install [Docker Desktop](https://www.d

git clone https://github.com/black-parrot/black-parrot-sim.git
cd black-parrot-sim
make -C docker docker-image docker-run
# An alternate flow using docker-compose
# make -C docker docker-compose
make docker-image docker-run

Then follow the [Tire Kick](#-tire-kick) directions above starting with "cd black-parrot-sim" or the "Full" directions below. The repo directory will be mounted inside the container.

Expand All @@ -122,7 +120,7 @@ Then follow the [Tire Kick](#-tire-kick) directions above starting with "cd blac
make prep

# Running your first test
make -C black-parrot/bp_top/syn build.sc sim.sc COSIM_P=1
make -C black-parrot/bp_top/syn build.verilator sim.verilator COSIM_P=1

## Continuing Onward

Expand Down
2 changes: 1 addition & 1 deletion black-parrot
Submodule black-parrot updated 146 files
2 changes: 1 addition & 1 deletion black-parrot-tools
20 changes: 0 additions & 20 deletions docker/Makefile

This file was deleted.

16 changes: 0 additions & 16 deletions docker/docker-compose.yml

This file was deleted.

21 changes: 21 additions & 0 deletions mk/Makefile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

docker-image: ## creates a black-parrot-sim docker image
@$(eval USER_ID := $(shell id -u))
@$(eval GROUP_ID := $(shell id -g))
@$(eval CONTAINER_NAME := black-parrot-sim)
@$(CD) $(BP_SIM_DOCKER_DIR); \
$(DOCKER) build . -f Dockerfile.$(DOCKER_PLATFORM) \
--build-arg USER_ID=$(USER_ID) \
--build-arg GROUP_ID=$(GROUP_ID) \
-t $(CONTAINER_NAME)

docker-run: ## mounts black-parrot-sim as a docker image
@$(eval USER_ID := $(shell id -u))
@$(eval GROUP_ID := $(shell id -g))
@$(eval CONTAINER_NAME := black-parrot-sim)
$(CD) $(BP_SIM_DIR); \
$(DOCKER) run \
--volume=$(BP_SIM_DIR):/home/build/black-parrot-sim \
--user $(USER_ID):$(GROUP_ID) \
-it $(CONTAINER_NAME)

0 comments on commit d0908d0

Please sign in to comment.