1#!/bin/bash
2
3set -e
4
5TARGET=microblaze-linux-musl
6LINUX_ARCH=microblaze
7
8J=$(expr $(nproc) / 2)
9TOOLCHAIN_INSTALL=/usr/local
10TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin
11CROSS_SYSROOT=${TOOLCHAIN_INSTALL}/$TARGET/sys-root
12
13GCC_PATCH0_URL=https://raw.githubusercontent.com/Xilinx/meta-xilinx/refs/tags/xlnx-rel-v2024.1/meta-microblaze/recipes-devtools/gcc/gcc-12/0009-Patch-microblaze-Fix-atomic-boolean-return-value.patch
14
15export PATH=${TOOLCHAIN_BIN}:$PATH
16
17#
18# Grab all of the source for the toolchain bootstrap.
19#
20
21wget https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz
22wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
23wget https://www.musl-libc.org/releases/musl-1.2.2.tar.gz
24wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.70.tar.xz
25
26tar axf binutils-2.37.tar.xz
27tar axf gcc-11.2.0.tar.xz
28tar axf musl-1.2.2.tar.gz
29tar axf linux-5.10.70.tar.xz
30
31mv binutils-2.37 src-binu
32mv gcc-11.2.0 src-gcc
33mv musl-1.2.2 src-musl
34mv linux-5.10.70 src-linux
35
36#
37# Patch gcc
38#
39
40wget -O - ${GCC_PATCH0_URL} | patch -d src-gcc -p1
41
42mkdir -p bld-hdr bld-binu bld-gcc bld-musl
43mkdir -p ${CROSS_SYSROOT}/usr/include
44
45#
46# Install kernel headers
47#
48
49cd src-linux
50make headers_install ARCH=${LINUX_ARCH} INSTALL_HDR_PATH=${CROSS_SYSROOT}/usr
51cd ..
52
53#
54# Build binutils
55#
56
57cd bld-binu
58../src-binu/configure --disable-werror \
59  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET}
60make -j${J}
61make install
62cd ..
63
64#
65# Build gcc, just the compiler so far.
66#
67
68cd bld-gcc
69../src-gcc/configure --disable-werror --disable-shared \
70  --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET} \
71  --enable-languages=c --disable-libssp --disable-libsanitizer \
72  --disable-libatomic --disable-libgomp --disable-libquadmath
73make -j${J} all-gcc
74make install-gcc
75cd ..
76
77#
78# Build musl.
79# We won't go through the extra step of building shared libraries
80# because we don't actually use them in QEMU docker testing.
81#
82
83cd bld-musl
84../src-musl/configure --prefix=/usr --host=${TARGET} --disable-shared
85make -j${j}
86make install DESTDIR=${CROSS_SYSROOT}
87cd ..
88
89#
90# Go back and build the compiler runtime
91#
92
93cd bld-gcc
94make -j${j}
95make install
96cd ..
97