Skip to content

Commit

Permalink
target: Switch to non-recursive Make system for sw
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Sep 4, 2024
1 parent 2bbc6da commit 51b25f4
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 336 deletions.
47 changes: 3 additions & 44 deletions target/sim/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ CLANG_FORMAT ?= $(shell which clang-format-10.0.1)
#########################

BIN_DIR ?= bin
PLATFORM_HEADERS_DIR ?= sw/shared/platform/generated
TARGET_ADDRMAP_DIR ?= $(abspath addrmap)
SOURCE_ADDRMAP_DIR ?= $(ROOT)/util/addrmap
DOCS_DIR ?= $(ROOT)/docs
Expand All @@ -75,6 +74,8 @@ SOURCE_HBMCTRL_DIR ?= $(ROOT)/hw/occamy/hbm_xbar_ctrl
SOURCE_QUADCTRL_DIR ?= $(ROOT)/hw/occamy/quadrant_s1_ctrl
SNITCH_TEST_DIR ?= $(SNITCH_ROOT)/target/common/test
TARGET_TEST_DIR ?= $(ROOT)/target/sim/test
SW_DIR = $(ROOT)/target/sim/sw
PLATFORM_HEADERS_DIR = $(SW_DIR)/shared/platform
CVA6_TRACE = trace_hart_0.log

# If the configuration file is overriden on the command-line (through
Expand Down Expand Up @@ -423,49 +424,7 @@ $(ADDRMAP_PDF): $(ADDRMAP_TEX) | $(TARGET_ADDRMAP_DIR)
# Software #
############

IDMAROOT = $(shell $(BENDER) path idma)

PLATFORM_HEADERS = $(PLATFORM_HEADERS_DIR)/occamy_cfg.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/occamy_base_addr.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/clint.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/occamy_soc_ctrl.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_cluster_peripheral.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_quad_peripheral.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_hbm_xbar_peripheral.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/idma.h

.PHONY: sw clean-headers clean-sw

sw: $(PLATFORM_HEADERS)
$(MAKE) -C sw/ all

clean-headers:
rm -f $(PLATFORM_HEADERS)

clean-sw: clean-headers
$(MAKE) -C sw/ clean

# REGGEN headers
$(PLATFORM_HEADERS_DIR)/clint.h: $(TARGET_CLINT_DIR)/clint.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/occamy_soc_ctrl.h: $(TARGET_SOCCTRL_DIR)/occamy_soc_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/snitch_cluster_peripheral.h: $(SNITCH_ROOT)/hw/snitch_cluster/src/snitch_cluster_peripheral/snitch_cluster_peripheral_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/snitch_quad_peripheral.h: $(TARGET_QUADCTRL_DIR)/occamy_quadrant_s1_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/snitch_hbm_xbar_peripheral.h: $(TARGET_HBMCTRL_DIR)/occamy_hbm_xbar_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/idma.h: $(IDMAROOT)/target/rtl/idma_reg64_1d.hjson
$(call reggen_generate_header,$@,$<)

# OCCAMYGEN headers
$(PLATFORM_HEADERS_DIR)/occamy_cfg.h: $(PLATFORM_HEADERS_DIR)/occamy_cfg.h.tpl $(CFG)
@echo "[OCCAMYGEN] Generating $@"
@$(OCCAMYGEN) -c $(CFG) --outdir $(PLATFORM_HEADERS_DIR) --cheader $<
$(PLATFORM_HEADERS_DIR)/occamy_base_addr.h: $(CFG)
@echo "[OCCAMYGEN] Generating $@"
@$(OCCAMYGEN) -c $(CFG) --outdir $(PLATFORM_HEADERS_DIR) -D $@
include sw.mk

##########
# Traces #
Expand Down
76 changes: 76 additions & 0 deletions target/sim/sw.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

###################
# General targets #
###################

.PHONY: sw clean-sw

all: sw
clean: clean-sw

####################
# Platform headers #
####################

IDMAROOT = $(shell $(BENDER) path idma)

PLATFORM_HEADERS = $(PLATFORM_HEADERS_DIR)/occamy_cfg.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/occamy_base_addr.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/clint.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/occamy_soc_ctrl.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_cluster_peripheral.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_quad_peripheral.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/snitch_hbm_xbar_peripheral.h
PLATFORM_HEADERS += $(PLATFORM_HEADERS_DIR)/idma.h

# REGGEN headers
$(PLATFORM_HEADERS_DIR)/clint.h: $(TARGET_CLINT_DIR)/clint.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/occamy_soc_ctrl.h: $(TARGET_SOCCTRL_DIR)/occamy_soc_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/snitch_cluster_peripheral.h: $(SNITCH_ROOT)/hw/snitch_cluster/src/snitch_cluster_peripheral/snitch_cluster_peripheral_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/snitch_quad_peripheral.h: $(TARGET_QUADCTRL_DIR)/occamy_quadrant_s1_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/snitch_hbm_xbar_peripheral.h: $(TARGET_HBMCTRL_DIR)/occamy_hbm_xbar_reg.hjson
$(call reggen_generate_header,$@,$<)
$(PLATFORM_HEADERS_DIR)/idma.h: $(IDMAROOT)/target/rtl/idma_reg64_1d.hjson
$(call reggen_generate_header,$@,$<)

# OCCAMYGEN headers
$(PLATFORM_HEADERS_DIR)/occamy_cfg.h: $(PLATFORM_HEADERS_DIR)/occamy_cfg.h.tpl $(CFG)
@echo "[OCCAMYGEN] Generating $@"
@$(OCCAMYGEN) -c $(CFG) --outdir $(PLATFORM_HEADERS_DIR) --cheader $<
$(PLATFORM_HEADERS_DIR)/occamy_base_addr.h: $(CFG)
@echo "[OCCAMYGEN] Generating $@"
@$(OCCAMYGEN) -c $(CFG) --outdir $(PLATFORM_HEADERS_DIR) -D $@

.PHONY: clean-headers
clean-sw: clean-headers
clean-headers:
rm -f $(PLATFORM_HEADERS)

##################
# Subdirectories #
##################

include $(SNITCH_ROOT)/target/snitch_cluster/sw/toolchain.mk
include sw/host/toolchain.mk
include sw/device/runtime/runtime.mk

HOST_APPS = sw/host/apps/hello_world
HOST_APPS += sw/host/apps/test_sys_dma
HOST_APPS += sw/host/apps/offload

DEVICE_APPS = sw/device/apps/blas/axpy
DEVICE_APPS += sw/device/apps/blas/gemm

# Include Makefile from each app subdirectory
$(foreach app,$(HOST_APPS) $(DEVICE_APPS), \
$(eval include $(app)/app.mk) \
)
16 changes: 0 additions & 16 deletions target/sim/sw/Makefile

This file was deleted.

28 changes: 0 additions & 28 deletions target/sim/sw/device/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

include $(abspath ../../common.mk)

APP := axpy
$(APP)_BUILD_DIR ?= $(SNITCH_ROOT)/target/snitch_cluster/sw/apps/blas/$(APP)/build
$(APP)_BUILD_DIR ?= $(SW_DIR)/device/apps/blas/$(APP)/build
SRC_DIR := $(SNITCH_ROOT)/sw/blas/$(APP)/src
SRCS := $(SRC_DIR)/main.c

include $(SNITCH_ROOT)/sw/apps/common.mk
include $(SNITCH_ROOT)/target/snitch_cluster/sw/apps/common.mk
include $(SW_DIR)/device/apps/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

include $(abspath ../../common.mk)

APP := gemm
$(APP)_BUILD_DIR ?= $(SNITCH_ROOT)/target/snitch_cluster/sw/apps/blas/$(APP)/build
$(APP)_BUILD_DIR ?= $(SW_DIR)/device/apps/blas/$(APP)/build
SRC_DIR := $(SNITCH_ROOT)/sw/blas/$(APP)/src
SRCS := $(SRC_DIR)/main.c
$(APP)_INCDIRS := $(SNITCH_ROOT)/sw/blas

include $(SNITCH_ROOT)/sw/apps/common.mk
include $(SNITCH_ROOT)/target/snitch_cluster/sw/apps/common.mk
include $(SW_DIR)/device/apps/common.mk

44 changes: 19 additions & 25 deletions target/sim/sw/device/apps/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

# Usage of absolute paths is required to externally include
# this Makefile from multiple different locations
MK_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
ROOT = $(abspath $(MK_DIR)/../../../../../)
$(APP)_RISCV_CFLAGS += -I$(SW_DIR)/shared/runtime
MEMORY_LD = $(SW_DIR)/device/apps/memory.ld
ORIGIN_LD = $(SW_DIR)/host/apps/offload/build/origin.ld
$(APP)_RISCV_LDFLAGS += -L$(dir $(ORIGIN_LD))
LD_DEPS = $(ORIGIN_LD)

SNITCH_ROOT = $(shell bender path snitch_cluster)
include $(SNITCH_ROOT)/target/snitch_cluster/sw/toolchain.mk
include $(SNITCH_ROOT)/target/snitch_cluster/sw/apps/common.mk

SNRT_DIR = $(SNITCH_ROOT)/sw/snRuntime
SW_DIR = $(ROOT)/target/sim/sw
SNRT_BUILDDIR = $(SW_DIR)/device/runtime/build
# Path relative to the app including this Makefile
BUILDDIR = $(abspath build)
RISCV_OBJCOPY_FLAGS = -O binary
RISCV_OBJCOPY_FLAGS += --remove-section=.comment
RISCV_OBJCOPY_FLAGS += --remove-section=.riscv.attributes
RISCV_OBJCOPY_FLAGS += --remove-section=.debug_info
RISCV_OBJCOPY_FLAGS += --remove-section=.debug_abbrev
RISCV_OBJCOPY_FLAGS += --remove-section=.debug_line
RISCV_OBJCOPY_FLAGS += --remove-section=.debug_str
RISCV_OBJCOPY_FLAGS += --remove-section=.debug_aranges

RISCV_CFLAGS += -I$(SNRT_DIR)/src
RISCV_CFLAGS += -I$(SNRT_DIR)/api
RISCV_CFLAGS += -I$(SNRT_DIR)/src/omp
RISCV_CFLAGS += -I$(SNRT_DIR)/api/omp
RISCV_CFLAGS += -I$(SNRT_DIR)/vendor/riscv-opcodes
RISCV_CFLAGS += -I$(SW_DIR)/device/runtime/src
RISCV_CFLAGS += -I$(SW_DIR)/shared/platform/generated
RISCV_CFLAGS += -I$(SW_DIR)/shared/platform
RISCV_CFLAGS += -I$(SW_DIR)/shared/runtime
BIN = $(abspath $(addprefix $($(APP)_BUILD_DIR)/,$(addsuffix .bin,$(APP))))

# Linker paths
MEMORY_LD = $(SW_DIR)/device/apps/memory.ld
$(info memory.ld path: $(MEMORY_LD))
ORIGIN_LD = $(BUILDDIR)/origin.ld
RISCV_LDFLAGS += -L$(dir $(ORIGIN_LD))
$(BIN): $(ELF) | $($(APP)_BUILD_DIR)
$(RISCV_OBJCOPY) $(RISCV_OBJCOPY_FLAGS) $< $@

$(APP): $(BIN)
75 changes: 0 additions & 75 deletions target/sim/sw/device/runtime/Makefile

This file was deleted.

12 changes: 12 additions & 0 deletions target/sim/sw/device/runtime/runtime.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2023 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

SNRT_TARGET_DIR = $(SW_DIR)/device/runtime
SNRT_HAL_HDRS_DIR = $(PLATFORM_HEADERS_DIR)
SNRT_HAL_HDRS = $(PLATFORM_HEADERS)
SNRT_INCDIRS = $(SW_DIR)/shared/runtime

include $(SNITCH_ROOT)/target/snitch_cluster/sw/runtime/runtime.mk
File renamed without changes.
21 changes: 0 additions & 21 deletions target/sim/sw/host/Makefile

This file was deleted.

Loading

0 comments on commit 51b25f4

Please sign in to comment.