From d0908d00c08c77bc4ab727c7dfb7becdd0c51b2d Mon Sep 17 00:00:00 2001 From: Dan Petrisko Date: Thu, 21 Nov 2024 13:45:29 -0800 Subject: [PATCH] Flow updates (#24) * Updating to new flow * Update README --- .gitignore | 2 + .gitmodules | 3 + Makefile | 63 +++++++++++-------- Makefile.common | 129 ++++++++++++++++++++++++++++++++++++++ Makefile.env | 48 ++++++++++++++ README.md | 8 +-- black-parrot | 2 +- black-parrot-sdk | 2 +- black-parrot-tools | 2 +- docker/Makefile | 20 ------ docker/docker-compose.yml | 16 ----- mk/Makefile.docker | 21 +++++++ 12 files changed, 245 insertions(+), 71 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile.common create mode 100644 Makefile.env delete mode 100644 docker/Makefile delete mode 100644 docker/docker-compose.yml create mode 100644 mk/Makefile.docker diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50aa170 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bsg_cadenv/ +install/ diff --git a/.gitmodules b/.gitmodules index 06168c6..ce1f2f0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Makefile b/Makefile index 93e2074..9bda81e 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 0000000..7b46fdb --- /dev/null +++ b/Makefile.common @@ -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 + diff --git a/Makefile.env b/Makefile.env new file mode 100644 index 0000000..a8046cb --- /dev/null +++ b/Makefile.env @@ -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 := git@github.com: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 + diff --git a/README.md b/README.md index f860734..2abe38b 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. @@ -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 diff --git a/black-parrot b/black-parrot index 08edfb4..b22377d 160000 --- a/black-parrot +++ b/black-parrot @@ -1 +1 @@ -Subproject commit 08edfb479c7b5d55d665a63464785044c6b4cd35 +Subproject commit b22377d58f65588e046239c9a356a68337720057 diff --git a/black-parrot-sdk b/black-parrot-sdk index 4142f2d..62693ce 160000 --- a/black-parrot-sdk +++ b/black-parrot-sdk @@ -1 +1 @@ -Subproject commit 4142f2d151eb0745dfac3a468f5ecee9ea066d8f +Subproject commit 62693cecb0a4b6df4a3db1ab083766832db9161b diff --git a/black-parrot-tools b/black-parrot-tools index 2c2df67..1bf612d 160000 --- a/black-parrot-tools +++ b/black-parrot-tools @@ -1 +1 @@ -Subproject commit 2c2df677b8926de6520d58f5f2dd989751f43897 +Subproject commit 1bf612d065f5fb2a382a33b54a65fcf31798ef9d diff --git a/docker/Makefile b/docker/Makefile deleted file mode 100644 index b933f5e..0000000 --- a/docker/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -TOP ?= $(shell git rev-parse --show-toplevel) - -DOCKER ?= docker -DOCKER_COMPOSE ?= docker-compose -PLATFORM ?= ubuntu20.04 - -docker-image: - cd $(TOP)/docker; \ - $(DOCKER) build . -f Dockerfile.$(PLATFORM) -t black-parrot-sim --no-cache --build-arg USER_ID=$(shell id -u) --build-arg GROUP_ID=$(shell id -g) \ - -docker-compose: - cd $(TOP)/docker; \ - $(DOCKER_COMPOSE) build --build-arg USER_ID=$(shell id -u) --build-arg GROUP_ID=$(shell id -g) black-parrot-sim - $(DOCKER_COMPOSE) up -d - $(DOCKER_COMPOSE) exec bp su - build - -docker-run: - cd $(TOP); \ - $(DOCKER) run --volume=$(TOP):/home/build/black-parrot-sim --user $(shell id -u):$(shell id -g) -it black-parrot-sim - diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml deleted file mode 100644 index 69c902b..0000000 --- a/docker/docker-compose.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/) - -version: '3' - -# Define services -services: - - # App Service - bp: - # Configuration for building the docker image for the service - build: - context: . # Use an image built from the specified dockerfile in the current directory. - dockerfile: Dockerfile.ubuntu - volumes: - - .:/home/build/black-parrot - diff --git a/mk/Makefile.docker b/mk/Makefile.docker new file mode 100644 index 0000000..87fbff0 --- /dev/null +++ b/mk/Makefile.docker @@ -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) +