-
Notifications
You must be signed in to change notification settings - Fork 135
/
Makefile
145 lines (112 loc) · 4.94 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#############################
## Configuration variables ##
#############################
# Useful globals
export SHELL := /bin/bash
export TERM := xterm-256color
# Keystone configuration
export KEYSTONE ?= $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
export KEYSTONE_BUILDROOT ?= $(KEYSTONE)/buildroot
export KEYSTONE_BR2_EXT ?= $(KEYSTONE)/overlays
export KEYSTONE_DRIVER ?= $(KEYSTONE)/linux-keystone-driver
export KEYSTONE_EXAMPLES ?= $(KEYSTONE)/examples
export KEYSTONE_RUNTIME ?= $(KEYSTONE)/runtime
export KEYSTONE_SDK ?= $(KEYSTONE)/sdk
export KEYSTONE_BOOTROM ?= $(KEYSTONE)/bootrom
export KEYSTONE_SM ?= $(KEYSTONE)/sm
export BUILDDIR ?= $(KEYSTONE)/build-$(KEYSTONE_PLATFORM)$(KEYSTONE_BITS)
export BUILDROOT_OVERLAYDIR ?= $(BUILDDIR)/overlay
export BUILDROOT_BUILDDIR ?= $(BUILDDIR)/buildroot.build
# options: generic, cva6, hifive_unmatched, mpfs
export KEYSTONE_PLATFORM ?= generic
export KEYSTONE_BITS ?= 64
include mkutils/args.mk
include mkutils/log.mk
BUILDROOT_CONFIGFILE ?= riscv$(KEYSTONE_BITS)_$(KEYSTONE_PLATFORM)_defconfig
ifeq ($(KEYSTONE_PLATFORM),mpfs)
EXTERNALS += microchip
ADDITIONAL_OVERLAYS := \$$(BR2_EXTERNAL_MCHP_PATH)/board/microchip/icicle/rootfs-overlay
endif
# Highest priority external
EXTERNALS += keystone
BUILDROOT_MAKEFLAGS := -C $(KEYSTONE_BUILDROOT) O=$(BUILDROOT_BUILDDIR)
BUILDROOT_MAKEFLAGS += BR2_EXTERNAL=$(call SEPERATE_LIST,:,$(addprefix $(KEYSTONE_BR2_EXT)/,$(EXTERNALS)))
#####################
## Generic targets ##
#####################
all: buildroot
$(BUILDDIR):
mkdir -p $@
###############
## Buildroot ##
###############
# Build directory
$(BUILDROOT_BUILDDIR): $(BUILDDIR)
mkdir -p $@
$(BUILDROOT_OVERLAYDIR): $(BUILDDIR)
mkdir -p $@
# Configuration
BUILDROOT_CCACHE ?= $(HOME)/.buildroot-ccache
$(BUILDROOT_BUILDDIR)/.config: $(BUILDROOT_BUILDDIR)
$(call log,info,Configuring Buildroot with $(BUILDROOT_CONFIGFILE))
$(MAKE) $(BUILDROOT_MAKEFLAGS) $(BUILDROOT_CONFIGFILE)
echo "BR2_ROOTFS_OVERLAY=\"$(BUILDROOT_OVERLAYDIR) $(ADDITIONAL_OVERLAYS)\"" >> $(BUILDROOT_BUILDDIR)/.config
echo "BR2_CCACHE_DIR=$(BUILDROOT_CCACHE)" >> $(BUILDROOT_BUILDDIR)/.config
# Overlay
$(BUILDROOT_OVERLAYDIR)/.done: $(BUILDROOT_OVERLAYDIR)
$(call log,info,Setting up overlay)
mkdir -p $(BUILDROOT_OVERLAYDIR)/root/.ssh
ssh-keygen -C 'root@keystone' -t rsa -f $(BUILDROOT_OVERLAYDIR)/root/.ssh/id-rsa -N ''
cp -f $(BUILDROOT_OVERLAYDIR)/root/.ssh/{id-rsa.pub,authorized_keys}
touch $@
# Main build target for buildroot. The specific subtarget to build can be overriden
# by setting the BUILDROOT_TARGET environment variable.
BUILDROOT_TARGET ?= all
.PHONY: buildroot
buildroot: $(BUILDROOT_BUILDDIR)/.config $(BUILDROOT_OVERLAYDIR)/.done
$(call log,info,Building Buildroot)
set -o pipefail ; $(MAKE) $(BUILDROOT_MAKEFLAGS) $(BUILDROOT_TARGET) 2>&1 | \
tee $(BUILDDIR)/build.log | LC_ALL=C grep -of scripts/grep.patterns
# Useful configuration target. This is meant as a development helper to keep
# the repository configuration in sync with what the user is doing. It
# automatically replaces the earlier specified configuration file in the
# BR2_EXTERNAL directory.
.PHONY: buildroot-configure
buildroot-configure: $(BUILDROOT_BUILDDIR)/.config
$(call log,info,Configuring Buildroot)
$(MAKE) $(BUILDROOT_MAKEFLAGS) menuconfig
$(call log,debug,Saving new defconfig)
$(MAKE) $(BUILDROOT_MAKEFLAGS) savedefconfig
sed -i '/BR2_ROOTFS_OVERLAY.*/d' $(KEYSTONE_BR2_EXT)/keystone/configs/$(BUILDROOT_CONFIGFILE)
.PHONY: linux-configure
linux-configure: $(BUILDROOT_BUILDDIR)/.config
$(call log,info,Configuring Linux)
$(MAKE) $(BUILDROOT_MAKEFLAGS) linux-menuconfig
$(call log,debug,Saving new defconfig)
$(MAKE) $(BUILDROOT_MAKEFLAGS) linux-savedefconfig
LINUX_BUILDDIR=$$($(MAKE) -s KEYSTONE_LOG_LEVEL=$(LOG_FATAL) $(BUILDROOT_MAKEFLAGS) linux-show-info | jq -r '.linux|.build_dir') ; \
LINUX_CONFIGFILE=$$(cat $(KEYSTONE_BR2_EXT)/keystone/configs/$(BUILDROOT_CONFIGFILE) | grep BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE | \
awk -F'=' '{ print $$2 }' | sed 's;$$(BR2_EXTERNAL_KEYSTONE_PATH);$(KEYSTONE_BR2_EXT)/keystone;g' | tr -d '"'); \
mv "$(BUILDROOT_BUILDDIR)/$$LINUX_BUILDDIR/defconfig" "$$LINUX_CONFIGFILE"
#################
## Run targets ##
#################
-include mkutils/plat/$(KEYSTONE_PLATFORM)/run.mk
PORT_ARGS :=
ifneq ($(KEYSTONE_PORT),)
PORT_ARGS += -p $(KEYSTONE_PORT)
endif
IP_ARGS :=
ifeq ($(KEYSTONE_IP),)
IP_ARGS += localhost
else
IP_ARGS += $(KEYSTONE_IP)
endif
CALL_LOGFILE ?= $(shell mktemp)
call:
$(call log,info,Calling command)
ssh -i $(BUILDROOT_BUILDDIR)/target/root/.ssh/id-rsa \
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-o ConnectTimeout=5 \
$(PORT_ARGS) root@$(IP_ARGS) $(KEYSTONE_COMMAND) 2>&1 | \
grep -v "Warning: Permanently added" | tee -a $(CALL_LOGFILE)