Skip to content

Commit

Permalink
[dv,sw] sw Makefile refactor
Browse files Browse the repository at this point in the history
[sw] Makefile refactor

- added centrallized Makefile infra for maximizing reuse across SW
test, lib and boot_rom targets
- existing Make flows still remain (for the timebeing; will remove it
once all approve of this)
- all make commands are to be run from sw/ area
- updated with chip_info generation
- TODOs
  - add some documentation
  - need to fix support for external apps, eg coremark

[dv,sw] coremark port now works

- updates to get external app (coremark) compiling with the refactored
flow
- added ability to compile targets with external Makefiles with
STANDALONE_SW var
- added sw/benchmarks/srcs.mk to supply STANDALONE_CMD to build custom
app

[dv,sw] removed existing Makefiles (deprecated)
  • Loading branch information
Srikrishna Iyer authored and sriyerg committed Sep 25, 2019
1 parent 738377c commit 789c27c
Show file tree
Hide file tree
Showing 26 changed files with 439 additions and 250 deletions.
28 changes: 21 additions & 7 deletions hw/dv/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ SCRATCH_PATH ?= ${SCRATCH_ROOT}/${SCRATCH_LOC}
BUILD_DIR := ${SCRATCH_PATH}/${BUILD_LOC}
RUN_PATH ?= ${SCRATCH_PATH}/${TEST_NAME}
RUN_DIR := ${RUN_PATH}/${RUN_LOC}

SW_DIR := ${PRJ_DIR}/sw
SW_BUILD_DIR ?= ${RUN_DIR}/sw_build
SW_ROOT_DIR := ${PRJ_DIR}/sw

JOB_OPTS ?=
BUILD_JOB_OPTS ?= $(JOB_OPTS)
Expand All @@ -44,13 +44,27 @@ SEED ?= $(shell od -vAn -N4 -tu < /dev/random | xargs)
BUILD_LOG ?= ${BUILD_DIR}/build.log
RUN_LOG ?= ${RUN_DIR}/run.log
UVM_VERBOSITY ?= UVM_LOW
BUILD_OPTS +=
# command line version of BUILD_OPTS - CL_BUILD_OPTS - it should be empty here

####################################################################################################
## Options for SV build / C build / simulation run ##
## CL_ prefix represents command line versions of these options - they should be empty and only ##
## be set on the command line ##
####################################################################################################
# BUILD_OPTS are passed to the simulator during the SV testbench compile step
CL_BUILD_OPTS +=
RUN_OPTS += +UVM_NO_RELNOTES
# command line version of RUN_OPTS - CL_RUN_OPTS - it should be empty here
BUILD_OPTS +=

# RUN_OPTS are passed to the simulation executable that is invoked to run the simulation
CL_RUN_OPTS +=
CAPP_BUILD_OPTS ?=
RUN_OPTS += +UVM_NO_RELNOTES

# SW_OPTS are options for SW apps that come with their own Makefile (example coremark)
CL_SW_OPTS +=
SW_OPTS += ${CL_SW_OPTS}

# SW_FLAGS are compiler flags / directives that we can pass for each test using our own Makefiles
CL_SW_FLAGS +=
SW_FLAGS += ${CL_SW_FLAGS}

# default project-wide bus widths
TL_AW ?= 32
Expand Down
30 changes: 14 additions & 16 deletions hw/dv/tools/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,21 @@ pre_run:
/bin/bash ${MAKE_ROOT}/run_dir_limiter ${RUN_PATH} ${RUN_DIR_LIMIT}
env > ${RUN_DIR}/env_vars

# TODO: clean this (capp tooling infrastructure)
capp: pre_run
ifneq (${CAPP_NAME},)
# Recursive make calls
make distclean -C ${SW_DIR}/boot_rom
make -C ${SW_DIR}/boot_rom
make distclean -C ${SW_DIR}/${CAPP_DIR} MAKEFLAGS=$(CAPP_BUILD_OPTS)
make -C ${SW_DIR}/${CAPP_DIR} MAKEFLAGS=$(CAPP_BUILD_OPTS) \
PROGRAM_CFLAGS=$(PROGRAM_CFLAGS)

# Copy outputs over to run area
cp $(SW_DIR)/boot_rom/boot_rom.vmem ${RUN_DIR}/rom.vmem
cp ${SW_DIR}/${CAPP_DIR}/${CAPP_NAME}.vmem ${RUN_DIR}/main.vmem
cp ${SW_DIR}/${CAPP_DIR}/${CAPP_NAME}.dis ${RUN_DIR}/main.dis
cp ${SW_DIR}/${CAPP_DIR}/${CAPP_NAME}.map ${RUN_DIR}/main.map
sw_build: pre_run
ifneq (${SW_NAME},)
mkdir -p ${SW_BUILD_DIR}
$(MAKE) -C $(SW_ROOT_DIR) \
SW_DIR=boot_rom \
SW_BUILD_DIR=$(SW_BUILD_DIR)/rom \
MAKEFLAGS="$(SW_OPTS)"
$(MAKE) -C $(SW_ROOT_DIR) \
SW_DIR=$(SW_DIR) \
SW_NAME=$(SW_NAME) \
SW_BUILD_DIR=$(SW_BUILD_DIR)/sw \
MAKEFLAGS="$(SW_OPTS)"
endif

simulate: capp
simulate: sw_build
$(RUN_JOB_OPTS) cd ${RUN_DIR} && ${SIMX} ${RUN_OPTS} ${CL_RUN_OPTS}

post_run: simulate
Expand All @@ -77,6 +74,7 @@ clean:
compile \
post_compile \
compile_result \
sw_build \
pre_run \
simulate \
post_run \
Expand Down
23 changes: 11 additions & 12 deletions hw/top_earlgrey/dv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
DV_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
export DUT_TOP := top_earlgrey_asic
export TB_TOP := tb
export RV_TOOLS := /edascratch/ms_edatools/riscv-tools/rv32ic/bin
FUSESOC_CORE := lowrisc:dv:chip_sim:0.1
COMPILE_KEY ?= default

Expand All @@ -28,33 +27,33 @@ UVM_TEST ?= chip_base_test
UVM_TEST_SEQ ?= chip_base_vseq

ifeq (${TEST_NAME},chip_sanity)
CAPP_DIR = examples/hello_world
CAPP_NAME = hello_world
SW_DIR = examples/hello_world
SW_NAME = hello_world
endif

ifeq (${TEST_NAME},chip_flash_test)
CAPP_DIR = tests/flash_ctrl
CAPP_NAME = flash_test
SW_DIR = tests/flash_ctrl
SW_NAME = flash_test
RUN_OPTS += +cpu_test_timeout_ns=15000000
endif

ifeq (${TEST_NAME},chip_sha256_test)
CAPP_DIR = tests/hmac
CAPP_NAME = sha256_test
SW_DIR = tests/hmac
SW_NAME = sha256_test
RUN_OPTS += +cpu_test_timeout_ns=4000000
endif

ifeq (${TEST_NAME},chip_rv_timer_test)
CAPP_DIR = tests/rv_timer
CAPP_NAME = rv_timer_test
SW_DIR = tests/rv_timer
SW_NAME = rv_timer_test
RUN_OPTS += +cpu_test_timeout_ns=4000000
endif

ifeq (${TEST_NAME},coremark)
CAPP_DIR = coremark
CAPP_NAME = coremark
SW_DIR = benchmarks/coremark
SW_NAME = coremark
RUN_OPTS += +cpu_test_timeout_ns=20000000
CAPP_BUILD_OPTS += ITERATIONS=1
SW_OPTS += ITERATIONS=1
endif

ifeq (${TEST_NAME},chip_csr_hw_reset)
Expand Down
5 changes: 4 additions & 1 deletion hw/top_earlgrey/dv/env/chip_env_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ package chip_env_pkg;
`include "dv_macros.svh"

// local parameters and types
parameter NUM_GPIOS = 16;
parameter NUM_GPIOS = 16;
parameter string ROM_MEM_IMG = "sw_build/rom/rom.vmem";
parameter string SW_MEM_IMG = "sw_build/sw/sw.vmem";

typedef virtual pins_if #(NUM_GPIOS) gpio_vif;
typedef virtual mem_bkdr_if mem_bkdr_vif;

Expand Down
4 changes: 2 additions & 2 deletions hw/top_earlgrey/dv/env/seq_lib/chip_base_vseq.sv
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class chip_base_vseq extends dv_base_vseq #(
// routine to backdoor load cpu test hex image and bring the cpu out of reset (if required)
// TODO(sriyerg): for future implementation
virtual task cpu_init();
cfg.mem_bkdr_vifs[Rom].load_mem_from_file("rom.vmem");
cfg.mem_bkdr_vifs[Rom].load_mem_from_file(ROM_MEM_IMG);
cfg.mem_bkdr_vifs[FlashBank0].set_mem();
cfg.mem_bkdr_vifs[FlashBank1].set_mem();

// TODO: the location of the main execution image should be randomized for either bank in future
cfg.mem_bkdr_vifs[FlashBank0].load_mem_from_file("main.vmem");
cfg.mem_bkdr_vifs[FlashBank0].load_mem_from_file(SW_MEM_IMG);
cpu_test_state = CpuTestRunning;
endtask

Expand Down
34 changes: 34 additions & 0 deletions sw/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

####################################################################################################
## Generate a baremetal application for the microcontroller ##
## Mandatory variables that need to be set over the command line: ##
## SW_DIR: this is the partial directory path to the SW test being built starting from sw/ ##
## ex: if running hello_world.c, then SW_DIR=examples/hello_world ##
## At this location, there needs to be a 'srcs.mk' file that contains the list of ##
## SW_SRCS to be built for that SW test. ##
## SW_NAME: This is the name of the SW test begin run. Optional if SW_DIR name (last dir) is ##
## the same as the SW test name. ##
## ##
## Optional variables: ##
## SW_BUILD_DIR: This is the output location for generating all sources ##
## SW_FLAGS Global args to pass on to the compiler ##
## SW_OPTS Global args to pass on to the sub-make commands ##
####################################################################################################


# Generate a baremetal application for the microcontroller
SW_ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SW_DIR ?= examples/hello_world

# sources
STANDALONE_SW ?= 0
include ${SW_DIR}/srcs.mk
include exts/common/srcs.mk
include lib/srcs.mk

# common options and rules
include opts.mk
include rules.mk
24 changes: 0 additions & 24 deletions sw/benchmarks/coremark/Makefile

This file was deleted.

13 changes: 13 additions & 0 deletions sw/benchmarks/coremark/srcs.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

COREMARK_DIR = $(SW_ROOT_DIR)/vendor/$(SW_NAME)
COREMARK_PORT = $(SW_ROOT_DIR)/$(SW_DIR)/top_earlgrey
STANDALONE_SW := 1
STANDALONE_CMD = $(MAKE) $(IMG_OUTPUTS) -C $(COREMARK_DIR) \
PORT_DIR=$(COREMARK_PORT) \
SW_DIR=$(SW_DIR) \
SW_ROOT_DIR=$(SW_ROOT_DIR) \
SW_BUILD_DIR=$(SW_BUILD_DIR) \
MAKEFLAGS=$(MAKEFLAGS)
108 changes: 58 additions & 50 deletions sw/benchmarks/coremark/top_earlgrey/core_portme.mak
Original file line number Diff line number Diff line change
@@ -1,82 +1,90 @@
#File : core_portme.mak

NAME = coremark
PORTME_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROGRAM_DIR := $(PORTME_DIR)/../
include ${SW_ROOT_DIR}/opts.mk

include ${PROGRAM_DIR}/../../exts/common/options.mk
PORT_CLEAN := $(OUTFILES)
PORT_CLEAN := $(IMG_OUTPUTS)

# FLAG : EXE, OEXT
# Extensions of generated outputs
OEXT = .o
EXE = .elf

# FLAG : OPATH
# Path to the output folder. Default - current folder.
OPATH = $(SW_BUILD_DIR)/

# Flag : OUTFLAG
# Use this flag to define how to to get an executable (e.g -o)
OUTFLAG= -T $(LINKER_SCRIPT) -L$(LIB_DIR) -l$(LIB_NAME) -Xlinker -Map=coremark.map -o
# Flag : CC
# Use this flag to define compiler to use
CC = $(RV_TOOLS)/riscv32-unknown-elf-gcc
# Flag : LD
# Use this flag to define compiler to use
LD = $(RV_TOOLS)/riscv32-unknown-elf-ld
# Flag : AS
# Use this flag to define compiler to use
AS = $(RV_TOOLS)/riscv32-unknown-elf-as
# Use this flag to define how to to get an executable (e.g -o)
OUTFLAG = $(LINK_OPTS) -o

# Flag : CFLAGS
# Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -DTOTAL_DATA_SIZE=6000 -DMAIN_HAS_NOARGC=1
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
CFLAGS += $(PORT_CFLAGS) $(XCFLAGS) -I$(PORT_DIR) -I. -I$(LIB_DIR)
#Flag : LFLAGS_END
# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts).
# Note : On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
#SEPARATE_COMPILE=1
# Use this flag to define compiler options. Note, you can add compiler options
# from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -DTOTAL_DATA_SIZE=6000 -DMAIN_HAS_NOARGC=1
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
CFLAGS += $(PORT_CFLAGS) $(XCFLAGS) -I$(PORT_DIR) -I. $(INCS)

# Flag : LFLAGS_END
# Define any libraries needed for linking or other flags that should come
# at the end of the link line (e.g. linker scripts).
# Note : On certain platforms, the default clock_gettime implementation
# is supported but requires linking of librt.
LFLAGS_END =

# Flag : SEPARATE_COMPILE
# Do compile and link steps separately. Not needed at this point.

# You must also define below how to create an object file, and how to link.
OBJOUT = -o
LFLAGS =
OBJOUT = -o
LFLAGS =
ASFLAGS =
OFLAG = -o
COUT = -c
OFLAG = -o
COUT = -c

LFLAGS_END =
# Flag : PORT_SRCS
# Port specific source files can be added here
# You may also need cvt.c if the fcvt functions are not provided as intrinsics by your compiler!
# Port specific source files can be added here
# You may also need cvt.c if the fcvt functions are not provided as intrinsics by your compiler!
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(EXT_SRCS)
vpath %.c $(PORT_DIR)
vpath %.s $(PORT_DIR)

# Flag : LOAD
# For a simple port, we assume self hosted compile and run, no load needed.
# For a simple port, we assume self hosted compile and run, no load needed.

# Flag : RUN
# For a simple port, we assume self hosted compile and run, simple invocation of the executable
# For a simple port, we assume self hosted compile and run, simple invocation of the executable

# Flag : MKDIR
MKDIR = mkdir -p

LOAD = echo "Please set LOAD to the process of loading the executable to the flash"
RUN = echo "Please set LOAD to the process of running the executable (e.g. via jtag, or board reset)"

OEXT = .o
EXE = .elf

$(OPATH)$(PORT_DIR)/%$(OEXT) : %.c
$(OPATH)%$(OEXT) : %.c
$(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@

$(OPATH)%$(OEXT) : %.c
$(OPATH)%$(OEXT) : %.s
$(AS) $(ASFLAGS) $< $(OBJOUT) $@

$(OPATH)%$(OEXT) : $(PORT_DIR)/%.c
$(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@

$(OPATH)$(PORT_DIR)/%$(OEXT) : %.s
$(OPATH)%$(OEXT) : $(PORT_DIR)/%.s
$(AS) $(ASFLAGS) $< $(OBJOUT) $@

# Target : port_pre% and port_post%
# For the purpose of this simple port, no pre or post steps needed.
%.vmem: %.bin
srec_cat $^ -binary -offset 0x0 -byte-swap 4 -o $@ -vmem

.PHONY : port_clean port_prebuild port_postbuild port_prerun port_postrun port_preload port_postload
%.bin: %.elf
$(OBJCOPY) -O binary $^ $@

port_postbuild:
$(RV_TOOLS)/riscv32-unknown-elf-objcopy -O binary coremark.elf coremark.bin
srec_cat coremark.bin -binary -offset 0x0 -byte-swap 4 -o coremark.vmem -vmem
$(RV_TOOLS)/riscv32-unknown-elf-objdump -SD coremark.elf > coremark.dis
%.dis: %.elf
$(OBJDUMP) -SD $^ > $@

# FLAG : OPATH
# Path to the output folder. Default - current folder.
OPATH = ./
MKDIR = mkdir -p
$(SW_BUILD_DIR)/$(IMG_NAME).elf: $(OUTFILE)
$(MAKE) $(OUTFILE)
mv $(OUTFILE) $@

# Target : port_pre% and port_post%

.PHONY : port_clean port_prebuild port_postbuild port_prerun port_postrun port_preload port_postload
Loading

0 comments on commit 789c27c

Please sign in to comment.