forked from Koheron/koheron-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
164 lines (134 loc) · 5.53 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# http://clarkgrubb.com/makefile-style-guide
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
CONFIG ?= examples/red-pitaya/led-blinker/config.yml
SDK_PATH ?= .
MODE ?= development
HOST ?= 192.168.1.100
TMP ?= tmp
KOHERON_VERSION := 0.16.1
VIVADO_VERSION := 2017.2
.PHONY: help
help:
@echo ' - all : (Default goal) build the instrument: fpga, server and web'
@echo ' - run : Run the instrument'
@echo ' - fpga : Build the FPGA bitstream'
@echo ' - server : Build the server'
@echo ' - web : Build the web interface'
@echo ' - os : Build the operating system'
@echo ' - image : Build the root file system (run as root)'
@echo ' - block_design : Build the Vivado block design interactively'
@echo ' - open_project : Open the Vivado .xpr project'
# Directory for storing the build artifacts
PROJECT_PATH := $(dir $(CONFIG))
TMP_PROJECT_PATH := $(TMP)/$(PROJECT_PATH)
# Python script that manages the instrument configuration
MAKE_PY := SDK_PATH=$(SDK_PATH) python $(SDK_PATH)/make.py
MEMORY_YML := $(TMP_PROJECT_PATH)/memory.yml
# Number of CPU cores available for parallel execution
N_CPUS := $(shell nproc 2> /dev/null || echo 1)
NAME := $(shell $(MAKE_PY) --name $(CONFIG) $(TMP_PROJECT_PATH)/name && cat $(TMP_PROJECT_PATH)/name)
###############################################################################
# INSTRUMENT
###############################################################################
# The instrument is packaged in a zip file that contains:
# - FPGA bitstream
# - TCP / Websocket server
# - Bash configuration script
# - Web files (HTML, CSS, Javascript)
BITSTREAM := $(TMP_PROJECT_PATH)/$(NAME).bit # FPGA bitstream
SERVER := $(TMP_PROJECT_PATH)/serverd # TCP / Websocket server executable that communicates with the FPGA:
START_SH := $(TMP_PROJECT_PATH)/start.sh # Bash script that configures the Zynq registers (clocks...)
# Zip file that contains all the files needed to run the instrument:
INSTRUMENT_ZIP := $(TMP_PROJECT_PATH)/$(NAME).zip
$(INSTRUMENT_ZIP): server $(BITSTREAM) $(START_SH) web
zip --junk-paths $(INSTRUMENT_ZIP) $(BITSTREAM) $(SERVER) $(START_SH) $(WEB_ASSETS)
@echo [$@] OK
# Make builds the instrument zip file by default
.PHONY: all
all: $(INSTRUMENT_ZIP)
# The "run" target launches the instrument on the Zynq board
# this is done via the HTTP API (see os/api)
.PHONY: run
run: $(INSTRUMENT_ZIP)
curl -v -F $(NAME).zip=@$(INSTRUMENT_ZIP) http://$(HOST)/api/instruments/upload
curl http://$(HOST)/api/instruments/run/$(NAME)
@echo
###############################################################################
# FPGA BITSTREAM
###############################################################################
FPGA_PATH := $(SDK_PATH)/fpga
FPGA_MK ?= $(FPGA_PATH)/fpga.mk
include $(FPGA_MK)
###############################################################################
# TCP / WEBSOCKET SERVER
###############################################################################
SERVER_PATH := $(SDK_PATH)/server
SERVER_MK ?= $(SERVER_PATH)/server.mk
include $(SERVER_MK)
###############################################################################
# WEB FILES
###############################################################################
WEB_PATH := $(SDK_PATH)/web
WEB_MK ?= $(WEB_PATH)/web.mk
include $(WEB_MK)
###############################################################################
# LINUX OS
###############################################################################
OS_PATH := $(SDK_PATH)/os
OS_MK ?= $(OS_PATH)/os.mk
include $(OS_MK)
###############################################################################
# TESTS
###############################################################################
TESTS_PATH := $(SDK_PATH)/tests
TESTS_MK ?= $(TESTS_PATH)/tests.mk
include $(TESTS_MK)
###############################################################################
# PYTHON
###############################################################################
PYTHON_PATH := $(SDK_PATH)/python
PYTHON_MK ?= $(PYTHON_PATH)/python.mk
include $(PYTHON_MK)
###############################################################################
# SETUP TARGETS
###############################################################################
.PHONY: setup
setup: setup_fpga setup_server setup_web setup_os
.PHONY: setup_base
setup_base:
sudo apt-get install -y g++-arm-linux-gnueabihf
sudo apt-get install -y python-pip
sudo apt-get install -y curl
sudo apt-get install -y npm
pip install -r $(SDK_PATH)/requirements.txt
pip install $(SDK_PATH)/python
.PHONY: setup_fpga
setup_fpga: setup_base
sudo rm -f /usr/bin/gmake && sudo ln -s make /usr/bin/gmake
.PHONY: setup_server
setup_server: setup_base
.PHONY: setup_web
setup_web: setup_base
sudo apt-get install -y nodejs
sudo rm -f /usr/bin/node && sudo ln -s /usr/bin/nodejs /usr/bin/node
npm install typescript
npm install @types/[email protected] @types/[email protected] websocket @types/node
.PHONY: setup_os
setup_os: setup_base
sudo apt-get install -y libssl-dev bc device-tree-compiler qemu-user-static zerofree
sudo apt-get install -y lib32stdc++6 lib32z1 u-boot-tools
###############################################################################
# CLEAN TARGETS
###############################################################################
# The "clean" target only removes the files related to the instrument specified by $(NAME)
# Use "clean_all" to remove everything
.PHONY: clean
clean:
rm -rf $(patsubst %/.,%,$(TMP_PROJECT_PATH))
.PHONY: clean_all
clean_all:
rm -rf $(TMP)