Package the RISCV emulator (Spike).
[fedora-riscv.git] / Makefile
1 # Refer to the README file to understand how Fedora on RISC-V is
2 # bootstrapped.
3
4 # Note these are chosen very specifically to ensure the different
5 # versions work together.  Don't blindly update to the latest
6 # versions.  See also:
7 # https://github.com/riscv/riscv-pk/issues/18#issuecomment-206115996
8 RISCV_QEMU_COMMIT               = 94f5eb73091fb4fe272db3e943f173ecc0f78ffd
9 RISCV_QEMU_SHORTCOMMIT          = 94f5eb73
10 RISCV_FESVR_COMMIT              = 0f34d7ad311f78455a674224225f5b3056efba1d
11 RISCV_FESVR_SHORTCOMMIT         = 0f34d7ad
12 RISCV_ISA_SIM_COMMIT            = 3bfc00ef2a1b1f0b0472a39a866261b00f67027e
13 RISCV_ISA_SIM_SHORTCOMMIT       = 3bfc00ef
14 RISCV_GNU_TOOLCHAIN_COMMIT      = 728afcddcb0526a0f6560c4032da82805f054d58
15 RISCV_GNU_TOOLCHAIN_SHORTCOMMIT = 728afcdd
16 RISCV_PK_COMMIT                 = 85ae17aa149b9ea114bdd70cc30ea7e73813fb48
17 RISCV_PK_SHORTCOMMIT            = 85ae17aa
18
19 # For the correct versions, see
20 # riscv-gnu-toolchain/Makefile.in *_version variables
21 BINUTILS_VERSION = 2.25.1
22 GLIBC_VERSION    = 2.22
23 GCC_VERSION      = 5.3.0
24 NEWLIB_VERSION   = 2.2.0
25
26 all: stage1 stage2 stage3 stage4
27
28 # Stage 1
29
30 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
31         stage1-riscv-qemu/riscv-qemu.spec \
32         stamp-riscv-qemu-installed \
33         stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
34         stage1-riscv-fesvr/riscv-fesvr.spec \
35         stamp-riscv-fesvr-installed \
36         stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
37         stage1-riscv-isa-sim/riscv-isa-sim.spec \
38         stamp-riscv-isa-sim-installed
39
40 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
41         rm -f $@ $@-t
42         wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
43         mv $@-t $@
44
45 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
46         sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
47             -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
48             < $^ > $@-t
49         mv $@-t $@
50
51 stamp-riscv-qemu-installed:
52         rm -f $@
53         @rpm -q riscv-qemu >/dev/null || { \
54           echo "ERROR: You must install riscv-qemu:"; \
55           echo; \
56           echo "       dnf copr enable rjones/riscv"; \
57           echo "       dnf install riscv-qemu"; \
58           echo; \
59           echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
60           echo; \
61           exit 1; \
62         }
63         @qemu-system-riscv --version || { \
64           echo "ERROR: qemu-system-riscv is not working."; \
65           echo "Make sure you installed the riscv-qemu package."; \
66           exit 1; \
67         }
68         touch $@
69
70 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
71         rm -f $@ $@-t
72         wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
73         mv $@-t $@
74
75 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
76         sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
77             -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
78             < $^ > $@-t
79         mv $@-t $@
80
81 stamp-riscv-fesvr-installed:
82         rm -f $@
83         @rpm -q riscv-fesvr >/dev/null || { \
84           echo "ERROR: You must install riscv-fesvr:"; \
85           echo; \
86           echo "       dnf copr enable rjones/riscv"; \
87           echo "       dnf install riscv-fesvr"; \
88           echo; \
89           echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
90           echo; \
91           exit 1; \
92         }
93         touch $@
94
95 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
96         rm -f $@ $@-t
97         wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
98         mv $@-t $@
99
100 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
101         sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
102             -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
103             < $^ > $@-t
104         mv $@-t $@
105
106 stamp-riscv-isa-sim-installed:
107         rm -f $@
108         @rpm -q riscv-isa-sim >/dev/null || { \
109           echo "ERROR: You must install riscv-isa-sim:"; \
110           echo; \
111           echo "       dnf copr enable rjones/riscv"; \
112           echo "       dnf install riscv-isa-sim"; \
113           echo; \
114           echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
115           echo; \
116           exit 1; \
117         }
118         touch $@
119
120 # Stage 2
121
122 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
123         stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
124         stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
125         stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
126         stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
127         stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
128         stamp-riscv-gnu-toolchain-installed \
129         stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
130         stage2-riscv-pk/riscv-pk.spec \
131         stamp-riscv-pk-installed
132
133 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
134         rm -f $@ $@-t
135         wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
136         mv $@-t $@
137
138 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
139         rm -f $@ $@-t
140         wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
141         mv $@-t $@
142
143 # GCC 5 no longer compiles with GCC 6 unless we patch it.
144 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
145 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
146         rm -f $@ $@-t
147         wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
148         zcat $@-t | tar xf -
149         cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
150         tar zcf $@-t gcc-$(GCC_VERSION)
151         rm -r gcc-$(GCC_VERSION)
152         mv $@-t $@
153
154 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
155         rm -f $@ $@-t
156         wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
157         mv $@-t $@
158
159 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
160         rm -f $@ $@-t
161         wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
162         mv $@-t $@
163
164 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
165         sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
166             -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
167             -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
168             -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
169             -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
170             -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
171             < $^ > $@-t
172         mv $@-t $@
173
174 stamp-riscv-gnu-toolchain-installed:
175         rm -f $@
176         @rpm -q riscv-gnu-toolchain >/dev/null || { \
177           echo "ERROR: You must install riscv-gnu-toolchain:"; \
178           echo; \
179           echo "       dnf copr enable rjones/riscv"; \
180           echo "       dnf install riscv-gnu-toolchain"; \
181           echo; \
182           echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
183           echo; \
184           exit 1; \
185         }
186         @riscv64-unknown-elf-gcc --version || { \
187           echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
188           echo "Make sure you installed the riscv-gnu-toolchain package."; \
189           exit 1; \
190         }
191         touch $@
192
193 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
194         rm -f $@ $@-t
195         wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
196         mv $@-t $@
197
198 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
199         sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
200             -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
201             < $^ > $@-t
202         mv $@-t $@
203
204 stamp-riscv-pk-installed:
205         rm -f $@
206         @rpm -q riscv-pk >/dev/null || { \
207           echo "ERROR: You must install riscv-pk:"; \
208           echo; \
209           echo "       dnf copr enable rjones/riscv"; \
210           echo "       dnf install riscv-pk"; \
211           echo; \
212           echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
213           echo; \
214           exit 1; \
215         }
216         touch $@
217
218 # Stage 3
219
220 stage3: stage3-kernel/linux-4.6.2.tar.xz \
221         stage3-kernel/linux-4.6.2/vmlinux
222
223 stage3-kernel/linux-4.6.2.tar.xz:
224         rm -f $@ $@-t
225         wget -O $@-t https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.6.2.tar.xz
226         mv $@-t $@
227
228 stage3-kernel/linux-4.6.2/vmlinux:
229         rm -rf stage3-kernel/linux-4.6.2
230         cat stage3-kernel/linux-4.6.2.tar.xz | tar -x --xz -C stage3-kernel
231         cd stage3-kernel/linux-4.6.2 && \
232         git init
233         cd stage3-kernel/linux-4.6.2 && \
234         git remote add origin https://github.com/lowrisc/riscv-linux.git
235         cd stage3-kernel/linux-4.6.2 && \
236         git fetch
237         cd stage3-kernel/linux-4.6.2 && \
238         git checkout -f -t origin/debug-v0.3
239         cd stage3-kernel/linux-4.6.2 && \
240         patch -p1 < spi_sd_power_hack.patch
241         cd stage3-kernel/linux-4.6.2 && \
242         make ARCH=riscv defconfig
243         cd stage3-kernel/linux-4.6.2 && \
244         make ARCH=riscv CONFIG_CROSS_COMPILE=riscv64-unknown-elf- vmlinux
245         ls -l $@
246
247 # Stage 4
248
249 stage4:
250         echo "XXX TO DO"
251         exit 1
252
253 .NOTPARALLEL: