forked from maia-sdr/plutosdr-fw
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
385 lines (297 loc) · 14.9 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#VIVADO_VERSION ?= 2020.1
#VIVADO_VERSION ?= 2022.1
export ADI_IGNORE_VERSION_CHECK = 1
SKIP_LEGAL=1
# Use Buildroot External Linaro GCC 7.3-2018.05 arm-linux-gnueabihf Toolchain
#CROSS_COMPILE = arm-linux-gnueabihf-
CROSS_COMPILE = arm-none-linux-gnueabihf-
TOOLS_PATH = PATH="$(CURDIR)/buildroot/output/host/bin:$(CURDIR)/buildroot/output/host/sbin:$(PATH)"
TOOLCHAIN = $(CURDIR)/buildroot/output/host/bin/$(CROSS_COMPILE)gcc
ABSOLUTE_PATH=$(shell cd `dirname "${BASH_SOURCE[0]}"` && pwd)
BOARD=$(ABSOLUTE_PATH/board)/datv/board
BR2_EXTERNAL=$(ABSOLUTE_PATH)/datv
BR2_PACKAGE_BUSYBOX_CONFIG=$(BR2_EXTERNAL)/datv/board/pluto/busybox-1.25.0.config
BR2_EXTERNAL_PLUTOSDR_PATH=$(shell cd `dirname "${BASH_SOURCE[0]}"` && pwd)/datv
NCORES = $(shell grep -c ^processor /proc/cpuinfo)
VIVADO_SETTINGS ?= /opt/Xilinx/Vivado/$(VIVADO_VERSION)/settings64.sh
VSUBDIRS = maia-sdr buildroot linux u-boot-xlnx
#VERSION=$(shell git describe --abbrev=4 --always --tags)
PATCH=$(shell cd datv && ./applypatch.sh )
$(shell git log --pretty=format:"%h - %ad : %s" > datv/board/pluto/overlay/root/fwhistory.txt)
#LATEST_TAG=$(shell git describe --abbrev=0 --tags)
LATEST_TAG=maia-sdr-v0.4.1
UBOOT_VERSION=$(shell echo -n "PlutoSDR " && cd u-boot-xlnx && git describe --abbrev=0 --dirty --always --tags)
HAVE_VIVADO= $(shell bash -c "source $(VIVADO_SETTINGS) > /dev/null 2>&1 && vivado -version > /dev/null 2>&1 && echo 1 || echo 0")
#XSA_URL ?= http://github.com/maia-sdr/plutosdr-fw/releases/download/${LATEST_TAG}/system_top.xsa
ifeq (1, ${HAVE_VIVADO})
VIVADO_INSTALL= $(shell bash -c "source $(VIVADO_SETTINGS) > /dev/null 2>&1 && vivado -version | head -1 | awk '{print $2}'")
ifeq (, $(findstring $(VIVADO_VERSION), $(VIVADO_INSTALL)))
$(warning *** This repository has only been tested with $(VIVADO_VERSION),)
$(warning *** and you have $(VIVADO_INSTALL))
$(warning *** Please 1] set the path to Vivado $(VIVADO_VERSION) OR)
$(warning *** 2] remove $(VIVADO_INSTALL) from the path OR)
$(error " 3] export VIVADO_VERSION=v20xx.x")
endif
endif
##PATCH COMMAND NEED TO BE INVOCATED
ifneq (1, ${PATCH})
$(warning patch granted $(PATCH))
endif
TARGET ?= pluto
SUPPORTED_TARGETS:=pluto sidekiqz2 plutoplus e200
XSA_FILE ?= datv/bitstream/${TARGET}/system_top.xsa
$(warning *** Building target $(TARGET),)
# Include target specific constants
include scripts/$(TARGET).mk
ifeq (, $(shell which dfu-suffix))
$(warning "No dfu-utils in PATH consider doing: sudo apt-get install dfu-util")
TARGETS = build/pluto.frm build/boot.frm sdimg
else
TARGETS = build/$(TARGET).dfu build/uboot-env.dfu build/pluto.frm build/boot.dfu build/boot.frm sdimg
endif
ifeq ($(findstring $(TARGET),$(SUPPORTED_TARGETS)),)
all:
@echo "Invalid `TARGET variable ; valid values are: pluto, sidekiqz2, plutoplus" &&
exit 1
else
all: clean-build $(TARGETS) zip-all legal-info
endif
.NOTPARALLEL: all
TARGET_DTS_FILES:=$(foreach dts,$(TARGET_DTS_FILES),build/$(dts))
TOOLCHAIN:
make BR2_EXTERNAL=$(ABSOLUTE_PATH)/datv -C buildroot ARCH=arm zynq_plutodatv_defconfig
make -C buildroot toolchain
build:
mkdir -p $@
%: build/%
cp $< $@
### u-boot ###
u-boot-xlnx/u-boot u-boot-xlnx/tools/mkimage: TOOLCHAIN
# $(TOOLS_PATH) make -C u-boot-xlnx ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zynq_$(TARGET)_defconfig
$(TOOLS_PATH) make -C u-boot-xlnx ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zynq_$(TARGET)_defconfig
$(TOOLS_PATH) make -C u-boot-xlnx ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) UBOOTVERSION="$(UBOOT_VERSION)"
.PHONY: u-boot-xlnx/u-boot
build/u-boot.elf: u-boot-xlnx/u-boot | build
cp $< $@
build/uboot-env.txt: u-boot-xlnx/u-boot TOOLCHAIN | build
$(TOOLS_PATH) CROSS_COMPILE=$(CROSS_COMPILE) scripts/get_default_envs.sh > $@
build/uboot-env.bin: build/uboot-env.txt
u-boot-xlnx/tools/mkenvimage -s 0x20000 -o $@ $<
### Linux ###
linux/arch/arm/boot/zImage: TOOLCHAIN
$(TOOLS_PATH) make -C linux -j $(NCORES) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zynq_$(TARGET)_linux_defconfig zImage UIMAGE_LOADADDR=0x8000
$(TOOLS_PATH) make -C linux -j $(NCORES) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zynq_$(TARGET)_linux_defconfig uImage UIMAGE_LOADADDR=0x8000
## $(TOOLS_PATH) make -C linux ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) defconfig zynq_$(TARGET)_defconfig
##$(TOOLS_PATH) make BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=$(ABSOLUTE_PATH)/datv/configs/zynq_$(TARGET)datv_linux_defconfig -C linux -j $(NCORES) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zImage UIMAGE_LOADADDR=0x8000
.PHONY: linux/arch/arm/boot/zImage
.PHONY: linux/arch/arm/boot/uImage
build/zImage: linux/arch/arm/boot/zImage | build
cp $< $@
build/uImage: linux/arch/arm/boot/uImage | build
cp $< $@
### Device Tree ###
linux/arch/arm/boot/dts/%.dtb: TOOLCHAIN linux/arch/arm/boot/dts/%.dts linux/arch/arm/boot/dts/zynq-pluto-sdr.dtsi linux/arch/arm/boot/dts/zynq-pluto-sdr-maiasdr.dtsi
$(TOOLS_PATH) DTC_FLAGS=-@ make -C linux -j $(NCORES) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) $(notdir $@)
build/%.dtb: linux/arch/arm/boot/dts/%.dtb | build
dtc -q -@ -I dtb -O dts $< | sed 's/axi {/amba {/g' | dtc -q -@ -I dts -O dtb -o $@
### maia-kmod ###
maia-sdr/maia-kmod/maia-sdr.ko: TOOLCHAIN
$(TOOLS_PATH) make -C linux ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules_prepare
$(TOOLS_PATH) make -C maia-sdr/maia-kmod ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) KERNEL_SRC=../../linux
.PHONY: maia-sdr/maia-kmod/maia-sdr.ko
buildroot/board/$(TARGET)/maia-sdr.ko: maia-sdr/maia-kmod/maia-sdr.ko | build
cp $< $@
### maia-httpd ###
#
maia-sdr/maia-httpd/target/armv7-unknown-linux-gnueabihf/release/maia-httpd: TOOLCHAIN
cd maia-sdr/maia-httpd && \
$(TOOLS_PATH) cargo build --release --target armv7-unknown-linux-gnueabihf \
--config target.armv7-unknown-linux-gnueabihf.linker=\"arm-linux-gnueabihf-gcc\"
.PHONY: maia-sdr/maia-httpd/target/armv7-unknown-linux-gnueabihf/release/maia-httpd
buildroot/board/$(TARGET)/maia-httpd: maia-sdr/maia-httpd/target/armv7-unknown-linux-gnueabihf/release/maia-httpd | build
cp $< $@
### maia-wasm ###
maia-sdr/maia-wasm/pkg:
cd maia-sdr/maia-wasm && wasm-pack build --target web
.PHONY: maia-sdr/maia-wasm/pkg
buildroot/board/$(TARGET)/maia-wasm:
mkdir $@
buildroot/board/$(TARGET)/maia-wasm/pkg: maia-sdr/maia-wasm/pkg | build buildroot/board/$(TARGET)/maia-wasm
cp -r $< buildroot/board/$(TARGET)/maia-wasm/
buildroot/board/$(TARGET)/maia-wasm/assets: maia-sdr/maia-wasm/assets | build buildroot/board/$(TARGET)/maia-wasm
cp -r $< buildroot/board/$(TARGET)/maia-wasm/
maia-wasm: buildroot/board/$(TARGET)/maia-wasm/pkg buildroot/board/$(TARGET)/maia-wasm/assets
.PHONY: maia-wasm
### DATV
### nco-kmod ###
linux_driver/nco_counter_core/nco_counter_core.ko: TOOLCHAIN
$(TOOLS_PATH) make -C linux ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules_prepare
$(TOOLS_PATH) make -C linux_driver/nco_counter_core ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) KERNEL_SRC=../../linux
.PHONY: linux_driver/nco_counter_core/nco_counter_core.ko
$(BR2_EXTERNAL)/board/pluto/overlay/lib/modules/nco_counter_core.ko: linux_driver/nco_counter_core/nco_counter_core.ko | build
cp $< $@
## Plutostream
pluto-ori-ps/pluto_stream: TOOLCHAIN
$(TOOLS_PATH) make pluto_stream -C pluto-ori-ps VER=$(VERSION) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE)
.PHONY: pluto-ori-ps/pluto_stream
$(BR2_EXTERNAL)/board/pluto/overlay/root/pluto_stream: pluto-ori-ps/pluto_stream | build
cp $< $@
## Plutomqttctrl
pluto-ori-ps/pluto_mqtt_ctrl: TOOLCHAIN
$(TOOLS_PATH) make pluto_mqtt_ctrl -C pluto-ori-ps ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE)
$(TOOLS_PATH) PAPR_ORI=$(BR2_EXTERNAL)/board/pluto/overlay/root make install -C pluto-ori-ps ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE)
.PHONY: pluto-ori-ps/pluto_mqtt_ctrl
$(BR2_EXTERNAL)/board/pluto/overlay/root/pluto_mqtt_ctrl: pluto-ori-ps/pluto_mqtt_ctrl | build
cp $< $@
## Longmynd
longmynd/longmynd: TOOLCHAIN
$(TOOLS_PATH) env=local make longmynd -C longmynd ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE)
.PHONY: longmynd/longmynd
$(BR2_EXTERNAL)/board/pluto/overlay/root/datv/longmynd: longmynd/longmynd | build
cp $< $@
### Buildroot ###
buildroot/output/images/rootfs.cpio.gz:
@echo device-fw $(VERSION)> $(BR2_EXTERNAL)/board/pluto/VERSIONS
@$(foreach dir,$(VSUBDIRS),echo $(dir) $(shell cd $(dir) && git describe --abbrev=4 --dirty --always --tags) >> $(BR2_EXTERNAL)/board/pluto/VERSIONS;)
make BR2_EXTERNAL=$(ABSOLUTE_PATH)/datv -C buildroot ARCH=arm zynq_plutodatv_defconfig
## make -C buildroot ARCH=arm zynq_$(TARGET)_defconfig
ifneq (1, ${SKIP_LEGAL})
make -C buildroot legal-info
scripts/legal_info_html.sh "$(COMPLETE_NAME)" "$(CURDIR)/buildroot/board/pluto/VERSIONS"
cp build/LICENSE.html buildroot/board/pluto/msd/LICENSE.html
endif
make -C buildroot BUSYBOX_CONFIG_FILE=$(BR2_EXTERNAL)/board/pluto/busybox-1.25.0.config all
.PHONY: buildroot/output/images/rootfs.cpio.gz
## Invoke again buildroot to add datv bin in rootfs
build/rootfs.cpio.gz: buildroot/output/images/rootfs.cpio.gz $(BR2_EXTERNAL)/board/pluto/overlay/lib/modules/nco_counter_core.ko $(BR2_EXTERNAL)/board/pluto/overlay/root/pluto_mqtt_ctrl $(BR2_EXTERNAL)/board/pluto/overlay/root/pluto_stream $(BR2_EXTERNAL)/board/pluto/overlay/root/datv/longmynd | build
make -C buildroot BUSYBOX_CONFIG_FILE=$(BR2_EXTERNAL)/board/pluto/busybox-1.25.0.config all
cp $< $@
build/$(TARGET).itb: u-boot-xlnx/tools/mkimage build/zImage build/rootfs.cpio.gz $(TARGET_DTS_FILES) build/system_top.bit
u-boot-xlnx/tools/mkimage -f scripts/$(TARGET).its $@
build/system_top.xsa: | build
ifneq ($(XSA_FILE),)
cp $(XSA_FILE) $@
else ifneq ($(XSA_URL),)
wget -T 3 -t 1 -N --directory-prefix build $(XSA_URL)
else ifeq (1, ${HAVE_VIVADO})
#bash -c "source $(VIVADO_SETTINGS) && make -C maia-sdr/maia-hdl/projects/$(TARGET) && cp maia-sdr/maia-hdl/projects/$(TARGET)/$(TARGET).sdk/system_top.xsa $@"
#unzip -l $@ | grep -q ps7_init || cp maia-sdr/maia-hdl/projects/$(TARGET)/$(TARGET).srcs/sources_1/bd/system/ip/system_sys_ps7_0/ps7_init* build/
ifeq ($(TARGET),pluto)
bash -c "source $(VIVADO_SETTINGS) && make -C ../hdl/projects/pluto-ori && cp ../hdl/projects/pluto-ori/pluto.sdk/system_top.xsa $@"
unzip -l $@ | grep -q ps7_init || cp ../hdl/projects/pluto-ori/pluto.srcs/sources_1/bd/system/ip/system_sys_ps7_0/ps7_init* build/
endif
ifeq ($(TARGET),plutoplus)
bash -c "source $(VIVADO_SETTINGS) && make -C ../hdl/projects/pluto-ori-plus && cp ../hdl/projects/pluto-ori-plus/pluto.sdk/system_top.xsa $@"
unzip -l $@ | grep -q ps7_init || cp ../hdl/projects/pluto-ori-plus/pluto.srcs/sources_1/bd/system/ip/system_sys_ps7_0/ps7_init* build/
endif
ifeq ($(TARGET),e200)
bash -c "source $(VIVADO_SETTINGS) && make -C ../hdl/projects/pluto-ori-e200 && cp ../hdl/projects/pluto-ori-e200/e200.sdk/system_top.xsa $@"
unzip -l $@ | grep -q ps7_init || cp ../hdl/projects/pluto-ori-e200/e200.srcs/sources_1/bd/system/ip/system_sys_ps7_0/ps7_init* build/
endif
#bash -c "source $(VIVADO_SETTINGS) && make -C ../hdl/projects/pluto-ori-plus"
endif
### TODO: Build system_top.xsa from src if dl fails ...
build/fsbl.elf build/system_top.bit : build/system_top.xsa
rm -Rf build/sdk
ifeq (1, ${HAVE_VIVADO})
bash -c "source $(VIVADO_SETTINGS) && xsct scripts/create_fsbl_project.tcl"
else
unzip -o build/system_top.xsa system_top.bit -d build
endif
build/boot.bin: build/fsbl.elf build/u-boot.elf
@echo img:{[bootloader] $^ } > build/boot.bif
ifeq (1, ${HAVE_VIVADO})
bash -c "source $(VIVADO_SETTINGS) && bootgen -image build/boot.bif -w -o $@"
cp build/sdk/fsbl/Release/fsbl.elf build/fsbl.elf
else
cp datv/bitstream/$(TARGET)/fsbl.elf build/fsbl.elf
bash -c "bootgen -image build/boot.bif -w -o $@"
endif
### MSD update firmware file ###
build/pluto.frm: build/$(TARGET).itb
md5sum $< | cut -d ' ' -f 1 > [email protected]
cat $< [email protected] > $@
build/boot.frm: build/boot.bin build/uboot-env.bin scripts/target_mtd_info.key
cat $^ | tee $@ | md5sum | cut -d ' ' -f1 | tee -a $@
### DFU update firmware file ###
build/%.dfu: build/%.bin
cp $< $<.tmp
dfu-suffix -a $<.tmp -v $(DEVICE_VID) -p $(DEVICE_PID)
mv $<.tmp $@
build/$(TARGET).dfu: build/$(TARGET).itb
cp $< $<.tmp
dfu-suffix -a $<.tmp -v $(DEVICE_VID) -p $(DEVICE_PID)
mv $<.tmp $@
SDIMGDIR = build/sdimg
sdimg: build | build/rootfs.cpio.gz
mkdir -p $(SDIMGDIR)
cp datv/bitstream/$(TARGET)/fsbl.elf $(SDIMGDIR)/fsbl.elf
cp build/system_top.bit $(SDIMGDIR)/system_top.bit
cp build/u-boot.elf $(SDIMGDIR)/u-boot.elf
cp linux/arch/arm/boot/uImage $(SDIMGDIR)/uImage
ifeq ($(TARGET),pluto)
cp build/zynq-pluto-sdr-maiasdr.dtb $(SDIMGDIR)/devicetree.dtb
endif
ifeq ($(TARGET),plutoplus)
cp build/zynq-plutoplus-maiasdr.dtb $(SDIMGDIR)/devicetree.dtb
endif
ifeq ($(TARGET),e200)
cp build/zynq-e200.dtb $(SDIMGDIR)/devicetree.dtb
endif
cp build/uboot-env.txt $(SDIMGDIR)/uEnv.txt
cp build/rootfs.cpio.gz $(SDIMGDIR)/ramdisk.image.gz
mkimage -A arm -T ramdisk -C gzip -d $(SDIMGDIR)/ramdisk.image.gz $(SDIMGDIR)/uramdisk.image.gz
touch $(SDIMGDIR)/boot.bif
echo "img : {[bootloader] $(SDIMGDIR)/fsbl.elf $(SDIMGDIR)/system_top.bit $(SDIMGDIR)/u-boot.elf}" > $(SDIMGDIR)/boot.bif
bootgen -image $(SDIMGDIR)/boot.bif -w -o i $(SDIMGDIR)/BOOT.bin
rm $(SDIMGDIR)/fsbl.elf
rm $(SDIMGDIR)/system_top.bit
rm $(SDIMGDIR)/u-boot.elf
rm $(SDIMGDIR)/ramdisk.image.gz
rm $(SDIMGDIR)/boot.bif
clean-build:
rm -f $(notdir $(wildcard build/*))
rm -rf build/*
clean:
make -C u-boot-xlnx clean
make -C linux clean
make -C buildroot clean
make -C maia-sdr/maia-hdl clean
cd maia-sdr/maia-httpd; cargo clean
cd maia-sdr/maia-wasm; cargo clean
rm -f $(notdir $(wildcard build/*))
rm -rf build/*
zip-all: $(TARGETS)
mkdir -p Release && cd build && zip -r ../Release/$(ZIP_ARCHIVE_PREFIX)-fw-$(VERSION).zip *.dfu *.frm sdimg
dfu-$(TARGET): build/$(TARGET).dfu
dfu-util -D build/$(TARGET).dfu -a firmware.dfu
dfu-util -e
dfu-sf-uboot: build/boot.dfu build/uboot-env.dfu
echo "Erasing u-boot be careful - Press Return to continue... " && read key && \
dfu-util -D build/boot.dfu -a boot.dfu && \
dfu-util -D build/uboot-env.dfu -a uboot-env.dfu
dfu-util -e
dfu-all: build/$(TARGET).dfu build/boot.dfu build/uboot-env.dfu
echo "Erasing u-boot be careful - Press Return to continue... " && read key && \
dfu-util -D build/$(TARGET).dfu -a firmware.dfu && \
dfu-util -D build/boot.dfu -a boot.dfu && \
dfu-util -D build/uboot-env.dfu -a uboot-env.dfu
dfu-util -e
dfu-ram: build/$(TARGET).dfu
sshpass -p analog ssh root@$(TARGET) '/usr/sbin/device_reboot ram;'
sleep 7
dfu-util -D build/$(TARGET).dfu -a firmware.dfu
dfu-util -e
jtag-bootstrap: build/u-boot.elf build/ps7_init.tcl build/system_top.bit scripts/run.tcl scripts/run-xsdb.tcl
$(TOOLS_PATH) $(CROSS_COMPILE)strip build/u-boot.elf
zip -j build/$(ZIP_ARCHIVE_PREFIX)-$@-$(VERSION).zip $^
sysroot: buildroot/output/images/rootfs.cpio.gz
tar czfh build/sysroot-$(VERSION).tar.gz --hard-dereference --exclude=usr/share/man --exclude=dev --exclude=etc -C buildroot/output staging
legal-info: buildroot/output/images/rootfs.cpio.gz
ifneq (1, ${SKIP_LEGAL})
tar czvf build/legal-info-$(VERSION).tar.gz -C buildroot/output legal-info
endif
git-update-all:
git submodule update --recursive --remote
git-pull:
git pull --recurse-submodules