-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathMakefile
145 lines (110 loc) · 4.58 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
# 'make' builds everything
# 'make clean' deletes everything except source files and Makefile
#
# You need to set NAME, PART and PROC for your project.
# NAME is the base name for most of the generated files.
# solves problem with awk while building linux kernel
# solution taken from http://www.googoolia.com/wp/2015/04/21/awk-symbol-lookup-error-awk-undefined-symbol-mpfr_z_sub/
LD_LIBRARY_PATH =
NAME = led_blinker
PART = xc7z010clg400-1
PROC = ps7_cortexa9_0
FILES = $(wildcard cores/*.v)
CORES = $(FILES:.v=)
VIVADO = vivado -nolog -nojournal -mode batch
XSCT = xsct
RM = rm -rf
INITRAMFS_TAG = 3.20
LINUX_TAG = 6.6
DTREE_TAG = xilinx_v2024.2
INITRAMFS_DIR = tmp/initramfs-$(INITRAMFS_TAG)
LINUX_DIR = tmp/linux-$(LINUX_TAG)
DTREE_DIR = tmp/device-tree-xlnx-$(DTREE_TAG)
LINUX_TAR = tmp/linux-$(LINUX_TAG).tar.xz
DTREE_TAR = tmp/device-tree-xlnx-$(DTREE_TAG).tar.gz
INITRAMFS_URL = https://dl-cdn.alpinelinux.org/alpine/v$(INITRAMFS_TAG)/releases/armv7/netboot/initramfs-lts
LINUX_URL = https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$(LINUX_TAG).32.tar.xz
DTREE_URL = https://github.com/Xilinx/device-tree-xlnx/archive/$(DTREE_TAG).tar.gz
SSBL_URL = https://github.com/pavel-demin/ssbl/releases/latest/download/ssbl.elf
RTL8188_TAR = tmp/rtl8188eu-main.tar.gz
RTL8188_URL = https://github.com/pavel-demin/rtl8188eu/archive/main.tar.gz
.PRECIOUS: tmp/cores/% tmp/%.xpr tmp/%.xsa tmp/%.bit tmp/%.fsbl/executable.elf tmp/%.tree/system-top.dts
all: tmp/$(NAME).bit boot.bin boot-rootfs.bin
cores: $(addprefix tmp/, $(CORES))
xpr: tmp/$(NAME).xpr
bit: tmp/$(NAME).bit
$(LINUX_TAR):
mkdir -p $(@D)
curl -L $(LINUX_URL) -o $@
$(DTREE_TAR):
mkdir -p $(@D)
curl -L $(DTREE_URL) -o $@
$(RTL8188_TAR):
mkdir -p $(@D)
curl -L $(RTL8188_URL) -o $@
$(INITRAMFS_DIR):
mkdir -p $@
curl -L $(INITRAMFS_URL) | gunzip | cpio -id --directory=$@
patch -d $@ -p 0 < patches/initramfs.patch
rm -rf $@/etc/modprobe.d $@/lib/firmware $@/lib/modules $@/var
$(LINUX_DIR): $(LINUX_TAR) $(RTL8188_TAR)
mkdir -p $@
tar -Jxf $< --strip-components=1 --directory=$@
mkdir -p $@/drivers/net/wireless/realtek/rtl8188eu
tar -zxf $(RTL8188_TAR) --strip-components=1 --directory=$@/drivers/net/wireless/realtek/rtl8188eu
patch -d tmp -p 0 < patches/linux-$(LINUX_TAG).patch
cp patches/cma.c $@/drivers/char
cp patches/xilinx_devcfg.c $@/drivers/char
cp patches/xilinx_zynq_defconfig $@/arch/arm/configs
$(DTREE_DIR): $(DTREE_TAR)
mkdir -p $@
tar -zxf $< --strip-components=1 --directory=$@
tmp/ssbl.elf:
mkdir -p $(@D)
curl -L $(SSBL_URL) -o $@
zImage.bin: $(LINUX_DIR)
make -C $< mrproper
make -C $< ARCH=arm -j $(shell nproc 2> /dev/null || echo 1) \
CROSS_COMPILE=arm-linux-gnueabihf- LOADADDR=0x8000 \
xilinx_zynq_defconfig zImage modules
cp $</arch/arm/boot/zImage $@
initrd.bin: $(INITRAMFS_DIR)
cd $< && find . | sort | cpio -o -H newc | gzip -9 -n > ../../$@
truncate -s 4M $@
boot.bin: tmp/$(NAME).fsbl/executable.elf tmp/ssbl.elf initrd.dtb zImage.bin initrd.bin
echo "img:{[bootloader] tmp/$(NAME).fsbl/executable.elf tmp/ssbl.elf [load=0x2000000] initrd.dtb [load=0x2008000] zImage.bin [load=0x3000000] initrd.bin}" > tmp/boot.bif
bootgen -image tmp/boot.bif -w -o $@
boot-rootfs.bin: tmp/$(NAME).fsbl/executable.elf tmp/ssbl.elf rootfs.dtb zImage.bin
echo "img:{[bootloader] tmp/$(NAME).fsbl/executable.elf tmp/ssbl.elf [load=0x2000000] rootfs.dtb [load=0x2008000] zImage.bin}" > tmp/boot-rootfs.bif
bootgen -image tmp/boot-rootfs.bif -w -o $@
initrd.dtb: tmp/$(NAME).tree/system-top.dts
dtc -I dts -O dtb -o $@ -i tmp/$(NAME).tree -i dts dts/initrd.dts
rootfs.dtb: tmp/$(NAME).tree/system-top.dts
dtc -I dts -O dtb -o $@ -i tmp/$(NAME).tree -i dts dts/rootfs.dts
tmp/cores/%: cores/%.v
mkdir -p $(@D)
$(VIVADO) -source scripts/core.tcl -tclargs $* $(PART)
tmp/%.xpr: projects/% $(addprefix tmp/, $(CORES))
mkdir -p $(@D)
$(VIVADO) -source scripts/project.tcl -tclargs $* $(PART)
tmp/%.xsa: tmp/%.xpr
mkdir -p $(@D)
$(VIVADO) -source scripts/hwdef.tcl -tclargs $*
tmp/%.bit: tmp/%.xpr
mkdir -p $(@D)
$(VIVADO) -source scripts/bitstream.tcl -tclargs $*
tmp/%.fsbl/executable.elf: tmp/%.xsa
mkdir -p $(@D)
$(XSCT) scripts/fsbl.tcl $* $(PROC)
cp patches/red_pitaya_fsbl_hooks.c $(@D)
patch $(@D)/fsbl_hooks.c patches/fsbl.patch
make -C $(@D)
tmp/%.tree/system-top.dts: tmp/%.xsa $(DTREE_DIR)
mkdir -p $(@D)
$(XSCT) scripts/devicetree.tcl $* $(PROC) $(DTREE_DIR)
sed -i 's|#include|/include/|' $@
clean:
$(RM) zImage.bin initrd.bin boot.bin boot-rootfs.bin initrd.dtb rootfs.dtb tmp
$(RM) .Xil usage_statistics_webtalk.html usage_statistics_webtalk.xml
$(RM) vivado*.jou vivado*.log
$(RM) webtalk*.jou webtalk*.log