1 # Refer to the README file to understand how Fedora on RISC-V is
4 # Note these are chosen very specifically to ensure the different
5 # versions work together. Don't blindly update to the latest
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
19 # For the correct versions, see
20 # riscv-gnu-toolchain/Makefile.in *_version variables
21 BINUTILS_VERSION = 2.25.1
24 NEWLIB_VERSION = 2.2.0
26 # See linux-4.1.y-riscv branch of
27 # https://github.com/riscv/riscv-linux
28 KERNEL_VERSION = 4.1.26
30 # A local copy of Linux git repo so you don't have to keep downloading
31 # git commits (optional).
32 LOCAL_LINUX_GIT_COPY = $(HOME)/d/linux
34 # The root packages (plus their dependencies) that we want to
35 # cross-compile into the stage 3 chroot.
36 STAGE3_PACKAGES = gcc rpm-build
38 # Versions of cross-compiled packages.
41 all: stage1 stage2 stage3 stage4
45 stage1: stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz \
46 stage1-riscv-qemu/riscv-qemu.spec \
47 stamp-riscv-qemu-installed \
48 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz \
49 stage1-riscv-fesvr/riscv-fesvr.spec \
50 stamp-riscv-fesvr-installed \
51 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz \
52 stage1-riscv-isa-sim/riscv-isa-sim.spec \
53 stamp-riscv-isa-sim-installed
55 stage1-riscv-qemu/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz:
57 wget -O $@-t 'https://github.com/riscv/riscv-qemu/archive/$(RISCV_QEMU_COMMIT)/riscv-qemu-$(RISCV_QEMU_SHORTCOMMIT).tar.gz'
60 stage1-riscv-qemu/riscv-qemu.spec: stage1-riscv-qemu/riscv-qemu.spec.in
61 sed -e 's/@COMMIT@/$(RISCV_QEMU_COMMIT)/g' \
62 -e 's/@SHORTCOMMIT@/$(RISCV_QEMU_SHORTCOMMIT)/g' \
66 stamp-riscv-qemu-installed:
68 @rpm -q riscv-qemu >/dev/null || { \
69 echo "ERROR: You must install riscv-qemu:"; \
71 echo " dnf copr enable rjones/riscv"; \
72 echo " dnf install riscv-qemu"; \
74 echo "OR: you can build it yourself from the stage1-riscv-qemu directory."; \
78 @qemu-system-riscv --version || { \
79 echo "ERROR: qemu-system-riscv is not working."; \
80 echo "Make sure you installed the riscv-qemu package."; \
85 stage1-riscv-fesvr/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz:
87 wget -O $@-t 'https://github.com/riscv/riscv-fesvr/archive/$(RISCV_FESVR_COMMIT)/riscv-fesvr-$(RISCV_FESVR_SHORTCOMMIT).tar.gz'
90 stage1-riscv-fesvr/riscv-fesvr.spec: stage1-riscv-fesvr/riscv-fesvr.spec.in
91 sed -e 's/@COMMIT@/$(RISCV_FESVR_COMMIT)/g' \
92 -e 's/@SHORTCOMMIT@/$(RISCV_FESVR_SHORTCOMMIT)/g' \
96 stamp-riscv-fesvr-installed:
98 @rpm -q riscv-fesvr >/dev/null || { \
99 echo "ERROR: You must install riscv-fesvr:"; \
101 echo " dnf copr enable rjones/riscv"; \
102 echo " dnf install riscv-fesvr"; \
104 echo "OR: you can build it yourself from the stage1-riscv-fesvr directory."; \
110 stage1-riscv-isa-sim/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz:
112 wget -O $@-t 'https://github.com/riscv/riscv-isa-sim/archive/$(RISCV_ISA_SIM_COMMIT)/riscv-isa-sim-$(RISCV_ISA_SIM_SHORTCOMMIT).tar.gz'
115 stage1-riscv-isa-sim/riscv-isa-sim.spec: stage1-riscv-isa-sim/riscv-isa-sim.spec.in
116 sed -e 's/@COMMIT@/$(RISCV_ISA_SIM_COMMIT)/g' \
117 -e 's/@SHORTCOMMIT@/$(RISCV_ISA_SIM_SHORTCOMMIT)/g' \
121 stamp-riscv-isa-sim-installed:
123 @rpm -q riscv-isa-sim >/dev/null || { \
124 echo "ERROR: You must install riscv-isa-sim:"; \
126 echo " dnf copr enable rjones/riscv"; \
127 echo " dnf install riscv-isa-sim"; \
129 echo "OR: you can build it yourself from the stage1-riscv-isa-sim directory."; \
137 stage2: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz \
138 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz \
139 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz \
140 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz \
141 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz \
142 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec \
143 stamp-riscv-gnu-toolchain-installed \
144 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz \
145 stage2-riscv-pk/riscv-pk.spec \
146 stamp-riscv-pk-installed
148 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz:
150 wget -O $@-t https://github.com/lowRISC/riscv-gnu-toolchain/archive/$(RISCV_GNU_TOOLCHAIN_COMMIT)/riscv-gnu-toolchain-$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT).tar.gz
153 stage2-riscv-gnu-toolchain/binutils-$(BINUTILS_VERSION).tar.gz:
155 wget -O $@-t http://mirrors.kernel.org/gnu/binutils/binutils-$(BINUTILS_VERSION).tar.gz
158 # GCC 5 no longer compiles with GCC 6 unless we patch it.
159 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
160 stage2-riscv-gnu-toolchain/gcc-$(GCC_VERSION).tar.gz:
162 wget -O $@-t http://mirrors.kernel.org/gnu/gcc/gcc-$(GCC_VERSION)/gcc-$(GCC_VERSION).tar.gz
164 cd gcc-$(GCC_VERSION) && patch -p0 < ../stage2-riscv-gnu-toolchain/gcc-5-fix-compilation-with-gcc-6.patch
165 tar zcf $@-t gcc-$(GCC_VERSION)
166 rm -r gcc-$(GCC_VERSION)
169 stage2-riscv-gnu-toolchain/glibc-$(GLIBC_VERSION).tar.gz:
171 wget -O $@-t http://mirrors.kernel.org/gnu/glibc/glibc-$(GLIBC_VERSION).tar.gz
174 stage2-riscv-gnu-toolchain/newlib-$(NEWLIB_VERSION).tar.gz:
176 wget -O $@-t ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
179 stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec: stage2-riscv-gnu-toolchain/riscv-gnu-toolchain.spec.in
180 sed -e 's/@COMMIT@/$(RISCV_GNU_TOOLCHAIN_COMMIT)/g' \
181 -e 's/@SHORTCOMMIT@/$(RISCV_GNU_TOOLCHAIN_SHORTCOMMIT)/g' \
182 -e 's/@BINUTILS_VERSION@/$(BINUTILS_VERSION)/g' \
183 -e 's/@GCC_VERSION@/$(GCC_VERSION)/g' \
184 -e 's/@GLIBC_VERSION@/$(GLIBC_VERSION)/g' \
185 -e 's/@NEWLIB_VERSION@/$(NEWLIB_VERSION)/g' \
189 stamp-riscv-gnu-toolchain-installed:
191 @rpm -q riscv-gnu-toolchain >/dev/null || { \
192 echo "ERROR: You must install riscv-gnu-toolchain:"; \
194 echo " dnf copr enable rjones/riscv"; \
195 echo " dnf install riscv-gnu-toolchain"; \
197 echo "OR: you can build it yourself from the stage2-riscv-gnu-toolchain directory."; \
201 @riscv64-unknown-elf-gcc --version || { \
202 echo "ERROR: riscv64-unknown-elf-gcc (cross compiler) is not working."; \
203 echo "Make sure you installed the riscv-gnu-toolchain package."; \
208 stage2-riscv-pk/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz:
210 wget -O $@-t https://github.com/lowRISC/riscv-pk/archive/$(RISCV_PK_COMMIT)/riscv-pk-$(RISCV_PK_SHORTCOMMIT).tar.gz
213 stage2-riscv-pk/riscv-pk.spec: stage2-riscv-pk/riscv-pk.spec.in
214 sed -e 's/@COMMIT@/$(RISCV_PK_COMMIT)/g' \
215 -e 's/@SHORTCOMMIT@/$(RISCV_PK_SHORTCOMMIT)/g' \
219 stamp-riscv-pk-installed:
221 @rpm -q riscv-pk >/dev/null || { \
222 echo "ERROR: You must install riscv-pk:"; \
224 echo " dnf copr enable rjones/riscv"; \
225 echo " dnf install riscv-pk"; \
227 echo "OR: you can build it yourself from the stage2-riscv-pk directory."; \
235 stage3: stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux \
236 stage3-chroot-original/etc/fedora-release \
237 stage3-chroot/etc/fedora-release \
238 stage3-chroot/lib64/libc.so.6 \
239 stage3-chroot/bin/bash \
242 stage3-kernel/linux-$(KERNEL_VERSION)/vmlinux:
243 rm -rf stage3-kernel/linux-$(KERNEL_VERSION)
244 cp -a $(LOCAL_LINUX_GIT_COPY) stage3-kernel/linux-$(KERNEL_VERSION) || { \
245 mkdir stage3-kernel/linux-$(KERNEL_VERSION) && \
246 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
249 cd stage3-kernel/linux-$(KERNEL_VERSION) && \
250 git remote add riscv https://github.com/riscv/riscv-linux && \
252 git checkout -f linux-4.1.y-riscv && \
254 make ARCH=riscv defconfig && \
255 make ARCH=riscv CONFIG_CROSS_COMPILE=riscv64-unknown-elf- vmlinux
258 # Build an original (x86-64) chroot using supermin. We then aim to
259 # rebuild (using cross-compiled versions) every ELF binary in this
261 stage3-chroot-original/etc/fedora-release:
262 rm -rf stage3-chroot-original tmp-supermin.d
263 supermin --prepare $(STAGE3_PACKAGES) -o tmp-supermin.d
264 supermin --build -f chroot tmp-supermin.d -o stage3-chroot-original
266 @echo -n "Total files in chroot: "
267 @find stage3-chroot-original -type f | wc -l
268 @echo -n "ELF files to be rebuilt: "
269 @find stage3-chroot-original -type f | xargs file -N | grep -E '\bELF.*LSB\b' | wc -l
271 # Copy the original chroot to the final chroot, remove all the ELF
273 stage3-chroot/etc/fedora-release: stage3-chroot-original/etc/fedora-release
275 cp -a stage3-chroot-original stage3-chroot
276 find stage3-chroot -type d | xargs chmod u+w
277 find stage3-chroot -type f | xargs chmod u+w
278 find stage3-chroot -type f | xargs file -N | grep -E '\bELF.*LSB\b' | awk -F: '{print $$1}' | xargs rm -f
279 rm -f stage3-chroot/lib64/libc.so.6
281 # Copy in compiled glibc from the riscv-gnu-toolchain sysroot. Only
282 # copy files and symlinks, leave the target directory structure
284 stage3-chroot/lib64/libc.so.6:
285 mkdir -p stage3-chroot/usr/lib/audit
286 mkdir -p stage3-chroot/usr/lib/gconv
287 for f in `cd /usr/sysroot && find -type f -o -type l`; do \
288 cp -d /usr/sysroot/$$f stage3-chroot/$$f; \
290 cd stage3-chroot/lib64 && for f in ../lib/*; do ln -sf $$f; done
292 # Cross-compile bash.
293 stage3-chroot/bin/bash: bash-$(BASH_VERSION).tar.gz
295 cd bash-$(BASH_VERSION) && \
296 ./configure --host=riscv64-unknown-linux-gnu CFLAGS="--sysroot=/usr/sysroot" && \
298 cp bash-$(BASH_VERSION)/bash stage3-chroot/bin/
300 bash-$(BASH_VERSION).tar.gz:
302 wget -O $@-t ftp://ftp.gnu.org/gnu/bash/bash-$(BASH_VERSION).tar.gz
305 # Create the stage3 disk image.
306 # Note `-s +...' adds spare space to the disk image.
307 stage3-disk.img: stage3-chroot
308 cd stage3-chroot && virt-make-fs . ../$@ -t ext2 -F raw -s +4G