forked from RedPitaya/RedPitaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.x86
253 lines (192 loc) · 8.75 KB
/
Makefile.x86
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
################################################################################
# versioning system
################################################################################
BUILD_NUMBER ?= 0
REVISION ?= devbuild
VER := $(shell cat apps-tools/ecosystem/info/info.json | grep version | sed -e 's/.*:\ *\"//' | sed -e 's/-.*//')
GIT_BRANCH_LOCAL = $(shell echo $(GIT_BRANCH) | sed -e 's/.*\///')
VERSION = $(VER)-$(BUILD_NUMBER)-$(REVISION)
export BUILD_NUMBER
export REVISION
export VERSION
SUBMODULE_UBT = ""
SUBMODULE_LIN = ""
SUBMODULE_APP = $(shell git submodule status Applications)
define GREET_MSG
##############################################################################
# Red Pitaya GNU/Linux Ecosystem
# Version: $(VER)
# Build: $(BUILD_NUMBER)
# Branch: $(GIT_BRANCH_LOCAL)
# Commit: $(GIT_COMMIT)
# U-Boot: $(SUBMODULE_UBT)
# Linux Kernel: $(SUBMODULE_LIN)
# Pro Applications: $(SUBMODULE_APP)
##############################################################################
endef
export GREET_MSG
################################################################################
# targets
################################################################################
all: fpga devicetree u-boot linux boot
install: linux-install devicetree-install boot
################################################################################
#
################################################################################
# check if download cache directory is available
DL ?= dl
TMP = tmp
INSTALL_DIR = build
$(DL):
mkdir -p $@
$(TMP):
mkdir -p $@
$(INSTALL_DIR):
mkdir -p $@
################################################################################
# X86 build (Vivado FPGA synthesis, FSBL, devicetree, U-Boot, Linux kernel)
################################################################################
UBOOT_TAG = xilinx-v2016.2
LINUX_TAG = branch-redpitaya-v2016.2
DTREE_TAG = xilinx-v2016.2
UBOOT_DIR = $(TMP)/u-boot-xlnx-$(UBOOT_TAG)
LINUX_DIR = $(TMP)/linux-xlnx-$(LINUX_TAG)
DTREE_DIR = $(TMP)/device-tree-xlnx-$(DTREE_TAG)
UBOOT_TAR = $(DL)/u-boot-xlnx-$(UBOOT_TAG).tar.gz
LINUX_TAR = $(DL)/linux-xlnx-$(LINUX_TAG).tar.gz
DTREE_TAR = $(DL)/device-tree-xlnx-$(DTREE_TAG).tar.gz
# it is possible to use an alternative download location (local) by setting environment variables
UBOOT_URL ?= https://github.com/Xilinx/u-boot-xlnx/archive/$(UBOOT_TAG).tar.gz
LINUX_URL ?= https://github.com/RedPitaya/linux-xlnx/archive/$(LINUX_TAG).tar.gz
DTREE_URL ?= https://github.com/Xilinx/device-tree-xlnx/archive/$(DTREE_TAG).tar.gz
LINUX_CFLAGS = "-O2 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard"
UBOOT_CFLAGS = "-O2 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=hard"
################################################################################
# FPGA build provides: $(FSBL), $(FPGA), $(DEVICETREE).
################################################################################
FPGA_TAR = fpga.zip
FPGA_PRJ_LST = classic logic_orig v0.94
FPGA_PRJ = logic_orig
.PHONY: fpga fpga_all
fpga: $(INSTALL_DIR)/fpga
$(INSTALL_DIR)/fpga: | $(FPGA_TAR)
mkdir -p $(INSTALL_DIR)/fpga
# extract FPGA bitstream images
unzip $(FPGA_TAR) -d $(INSTALL_DIR)/fpga
# copy archived FPGA bitstream images and decompress them
cp fpga/archive/*.xz $(INSTALL_DIR)/fpga
cd $(INSTALL_DIR)/fpga; xz -df *.xz
# backward compatibility, TODO, should be removed at next OS release
cp $(INSTALL_DIR)/fpga/logic_orig/fpga.bit $(INSTALL_DIR)/fpga/fpga_la.bit
cp $(INSTALL_DIR)/fpga/v0.94/fpga.bit $(INSTALL_DIR)/fpga/fpga_0.94.bit
cp $(INSTALL_DIR)/fpga/classic/fpga.bit $(INSTALL_DIR)/fpga/fpga_classic.bit
fpga_all: $(DTREE_DIR)
mkdir -p $(INSTALL_DIR)/fpga
for FPGA_PRJ_ITM in $(FPGA_PRJ_LST); do \
make -C fpga PRJ=$$FPGA_PRJ_ITM; \
mkdir -p $(INSTALL_DIR)/fpga/$$FPGA_PRJ_ITM; \
cp fpga/prj/$$FPGA_PRJ_ITM/out/red_pitaya.bit $(INSTALL_DIR)/fpga/$$FPGA_PRJ_ITM/fpga.bit; \
cp fpga/prj/$$FPGA_PRJ_ITM/sdk/fsbl/executable.elf $(INSTALL_DIR)/fpga/$$FPGA_PRJ_ITM/fsbl.elf; \
cp -r fpga/prj/$$FPGA_PRJ_ITM/sdk/dts $(INSTALL_DIR)/fpga/$$FPGA_PRJ_ITM ; \
cp fpga/prj/$$FPGA_PRJ_ITM/dts/fpga.dts $(INSTALL_DIR)/fpga/$$FPGA_PRJ_ITM/dts/ ; \
done
cd $(INSTALL_DIR)/fpga; zip -r ../../fpga.zip *
rm -rf $(INSTALL_DIR)/fpga
################################################################################
# U-Boot build provides: $(UBOOT)
################################################################################
UBOOT = $(TMP)/u-boot.elf
UBOOT_SCRIPT = $(INSTALL_DIR)/u-boot.scr
.PHONY: u-boot
u-boot: $(UBOOT) $(UBOOT_SCRIPT)
$(UBOOT_TAR): | $(DL)
curl -L $(UBOOT_URL) -o $@
$(UBOOT_DIR): $(UBOOT_TAR)
mkdir -p $@
tar -zxf $< --strip-components=1 --directory=$@
# Red Pitaya configuration
cp patches/u-boot/zynq-red-pitaya.dts $@/arch/arm/dts/zynq-red-pitaya.dts
cp patches/u-boot/zynq_red_pitaya_defconfig $@/configs/zynq_red_pitaya_defconfig
cp patches/u-boot/zynq_red_pitaya.h $@/include/configs/zynq_red_pitaya.h
patch -d $@ -p 1 < patches/u-boot/u-boot-xlnx-$(UBOOT_TAG)-config.patch
# add Lantiq PHY driver
cp patches/u-boot/lantiq.c $@/drivers/net/phy/lantiq.c
patch -d $@ -p 1 < patches/u-boot/u-boot-xlnx-$(UBOOT_TAG)-lantiq.patch
$(UBOOT): $(UBOOT_DIR) $(TMP)
make -C $< arch=ARM zynq_red_pitaya_defconfig
make -C $< arch=ARM CFLAGS=$(UBOOT_CFLAGS)
cp $(UBOOT_DIR)/u-boot $@
$(UBOOT_SCRIPT): $(INSTALL_DIR) $(UBOOT_DIR) $(UBOOT)
$(UBOOT_DIR)/tools/mkimage -A ARM -O linux -T script -C none -a 0 -e 0 -n "boot Debian" -d patches/u-boot/u-boot.script $@
################################################################################
# Linux build provides: $(LINUX)
################################################################################
LINUX = $(LINUX_DIR)/arch/arm/boot/uImage
.PHONY: linux linux-install
linux: $(LINUX)
$(LINUX_TAR): | $(DL)
curl -L $(LINUX_URL) -o $@
$(LINUX_DIR): $(LINUX_TAR)
mkdir -p $@
tar -zxf $< --strip-components=1 --directory=$@
$(LINUX): $(LINUX_DIR)
make -C $< mrproper
make -C $< ARCH=arm xilinx_zynq_defconfig
make -C $< ARCH=arm CFLAGS=$(LINUX_CFLAGS) -j $(shell grep -c ^processor /proc/cpuinfo) UIMAGE_LOADADDR=0x8000 uImage
linux-install: linux $(INSTALL_DIR)
cp $(LINUX_DIR)/arch/arm/boot/uImage $(INSTALL_DIR)
################################################################################
# device tree processing
################################################################################
DEVICETREE = $(TMP)/dts/devicetree.dtb
.PHONY: devicetree devicetree-install
devicetree: $(DEVICETREE)
$(DTREE_TAR): | $(DL)
curl -L $(DTREE_URL) -o $@
$(DTREE_DIR): $(DTREE_TAR)
mkdir -p $@
tar -zxf $< --strip-components=1 --directory=$@
$(DEVICETREE): $(DTREE_DIR) $(INSTALL_DIR)/fpga $(TMP)
cp -r $(INSTALL_DIR)/fpga/$(FPGA_PRJ)/dts $(TMP)
cat $(TMP)/dts/fpga.dts >> $(TMP)/dts/system.dts
tools/dtc/bin/dtc -I dts -O dtb -o $(DEVICETREE) -i $(TMP)/dts -i fpga/dts $(TMP)/dts/system.dts
tools/dtc/bin/dtc -I dts -O dtb -o $(TMP)/dts/amba_pl.dtbo -b 0 -@ patches/devicetree/amba_pl.dts
# create device tree source from binary for reference
tools/dtc/bin/dtc -I dtb -O dts --sort -o $(TMP)/dts/dtraw.dts $(DEVICETREE)
devicetree-install: $(DEVICETREE) $(INSTALL_DIR)
cp $(DEVICETREE) $(INSTALL_DIR)
cp $(TMP)/dts/dtraw.dts $(INSTALL_DIR)
cp $(TMP)/dts/amba_pl.dtbo $(INSTALL_DIR)
cp patches/devicetree/amba_pl.sh $(INSTALL_DIR)
cp patches/devicetree/rmamba_pl.sh $(INSTALL_DIR)
################################################################################
# boot file generator
################################################################################
BOOT = $(INSTALL_DIR)/boot.bin
.PHONY: boot
boot: $(BOOT)
FPGA = $(INSTALL_DIR)/fpga/$(FPGA_PRJ)/fpga.bit
FSBL = $(INSTALL_DIR)/fpga/$(FPGA_PRJ)/fsbl.elf
$(BOOT): $(INSTALL_DIR)/fpga $(UBOOT) $(INSTALL_DIR)
@echo img:{[bootloader] $(FSBL) $(FPGA) $(UBOOT) } > boot_uboot.bif
bootgen -image boot_uboot.bif -w -o $@
################################################################################
# tarball
################################################################################
ZIPFILE=ecosystem-$(VERSION).zip
zip: $(ZIPFILE)
$(ZIPFILE): install
cp -r OS/filesystem/* $(INSTALL_DIR)
# create version file
@echo "$$GREET_MSG" > $(INSTALL_DIR)/version.txt
# build zip file
cd $(INSTALL_DIR); zip -r ../$(ZIPFILE) *
################################################################################
#
################################################################################
clean:
-make -C $(LINUX_DIR) clean
make -C fpga clean
-make -C $(UBOOT_DIR) clean
# todo, remove downloaded libraries and symlinks
$(RM) $(INSTALL_DIR) -rf