Skip to content

Commit 938187d

Browse files
committed
init
0 parents  commit 938187d

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Raspberry Pi Cross Compiler
2+
3+
Raspberry Pi cross-compiler toolchain which contains:
4+
5+
| Name | Version |
6+
|:---------|:--------|
7+
| GCC | 12.2.0 |
8+
| glibc | 2.36 |
9+
| Binutils | 2.40 |
10+
| GDB | 10.2 |
11+
12+
## Supported OS
13+
14+
* Host OS: any x64 Linux machine
15+
* Target OS: Raspberry Pi OS Bookworm 64-bit
16+
17+
## Usage
18+
19+
* Build Docker image:
20+
21+
```shell
22+
docker build -t cross-pi-gcc docker
23+
```
24+
25+
* Build cross-compiler toolchain:
26+
27+
```shell
28+
docker run -it --rm -v ~/out:/out cross-pi-gcc -c build.sh
29+
```
30+
31+
**Note:** The `cross-gcc-12.2.0-pi_64.tar.gz` file will saved to `~/out` directory.

build.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
3+
GCC_VERSION=12.2.0
4+
GLIBC_VERSION=2.36
5+
BINUTILS_VERSION=2.40
6+
GDB_VERSION=10.2
7+
8+
LANGUAGES=c,c++,fortran
9+
10+
FOLDER_VERSION=64
11+
KERNEL=kernel8
12+
ARCH=armv8-a+fp+simd
13+
TARGET=aarch64-linux-gnu
14+
15+
BUILDDIR=/tmp
16+
DOWNLOADDIR=$BUILDDIR/build_toolchains
17+
INSTALLDIR=$BUILDDIR/cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION
18+
SYSROOTDIR=$BUILDDIR/cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION/$TARGET/libc
19+
20+
mkdir -p $DOWNLOADDIR
21+
mkdir -p $INSTALLDIR
22+
23+
cd $DOWNLOADDIR
24+
25+
if [ ! -d "linux" ]; then
26+
git clone --depth=1 https://github.com/raspberrypi/linux
27+
fi
28+
29+
if [ ! -d "gcc-$GCC_VERSION" ]; then
30+
wget -q https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
31+
32+
tar xf gcc-$GCC_VERSION.tar.gz
33+
rm -f gcc-$GCC_VERSION.tar.gz
34+
35+
mkdir -p gcc-$GCC_VERSION/build
36+
37+
cd gcc-$GCC_VERSION
38+
sed -i 's/#include <limits.h>/#include <linux\/limits.h>/' libsanitizer/asan/asan_linux.cpp # patch
39+
40+
contrib/download_prerequisites
41+
rm -f *.tar.*
42+
cd $DOWNLOADDIR
43+
fi
44+
45+
if [ ! -d "binutils-$BINUTILS_VERSION" ]; then
46+
wget -q https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.bz2
47+
48+
tar xf binutils-$BINUTILS_VERSION.tar.bz2
49+
rm -rf binutils-$BINUTILS_VERSION.tar.bz2
50+
51+
mkdir -p binutils-$BINUTILS_VERSION/build
52+
fi
53+
54+
if [ ! -d "glibc-$GLIBC_VERSION" ]; then
55+
wget -q https://ftp.gnu.org/gnu/glibc/glibc-$GLIBC_VERSION.tar.bz2
56+
57+
tar xf glibc-$GLIBC_VERSION.tar.bz2
58+
rm -rf glibc-$GLIBC_VERSION.tar.bz2
59+
60+
mkdir -p glibc-$GLIBC_VERSION/build
61+
fi
62+
63+
if [ ! -d "gdb-$GDB_VERSION" ]; then
64+
wget -q https://ftp.gnu.org/gnu/gdb/gdb-$GDB_VERSION.tar.xz
65+
66+
tar xf gdb-$GDB_VERSION.tar.xz
67+
rm -rf gdb-$GDB_VERSION.tar.xz
68+
69+
mkdir -p gdb-$GDB_VERSION/build
70+
fi
71+
72+
PATH=$BUILDDIR/cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION/bin:$PATH
73+
74+
echo "Building Kernel Headers ..."
75+
cd $DOWNLOADDIR/linux
76+
make -s ARCH=arm64 INSTALL_HDR_PATH=$SYSROOTDIR/usr headers_install
77+
mkdir -p $SYSROOTDIR/usr/lib
78+
79+
echo "Building Binutils ..."
80+
rm -rf $DOWNLOADDIR/binutils-$BINUTILS_VERSION/build/*
81+
cd $DOWNLOADDIR/binutils-$BINUTILS_VERSION/build
82+
83+
../configure --target=$TARGET --prefix= --with-arch=$ARCH --with-sysroot=/$TARGET/libc --with-build-sysroot=$SYSROOTDIR --disable-multilib
84+
make -s -j$(nproc)
85+
make -s install-strip DESTDIR=$INSTALLDIR
86+
87+
echo "Building GCC and glibc ..."
88+
rm -rf $DOWNLOADDIR/gcc-$GCC_VERSION/build/*
89+
cd $DOWNLOADDIR/gcc-$GCC_VERSION/build
90+
91+
../configure --prefix= --target=$TARGET --enable-languages=$LANGUAGES --with-sysroot=/$TARGET/libc --with-build-sysroot=$SYSROOTDIR --with-arch=$ARCH --disable-multilib
92+
make -s -j$(nproc) all-gcc
93+
make -s install-strip-gcc DESTDIR=$INSTALLDIR
94+
95+
rm -rf $DOWNLOADDIR/glibc-$GLIBC_VERSION/build/*
96+
cd $DOWNLOADDIR/glibc-$GLIBC_VERSION/build
97+
98+
../configure --prefix=/usr --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-arch=$ARCH --with-sysroot=/$TARGET/libc --with-build-sysroot=$SYSROOTDIR --with-headers=$SYSROOTDIR/usr/include --with-lib=$SYSROOTDIR/usr/lib --disable-multilib libc_cv_forced_unwind=yes
99+
make -s install-bootstrap-headers=yes install-headers DESTDIR=$SYSROOTDIR
100+
make -s -j$(nproc) csu/subdir_lib
101+
install csu/crt1.o csu/crti.o csu/crtn.o $SYSROOTDIR/usr/lib
102+
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $SYSROOTDIR/usr/lib/libc.so
103+
touch $SYSROOTDIR/usr/include/gnu/stubs.h $SYSROOTDIR/usr/include/bits/stdio_lim.h
104+
105+
cd $DOWNLOADDIR/gcc-$GCC_VERSION/build
106+
make -s -j$(nproc) all-target-libgcc
107+
make -s install-target-libgcc DESTDIR=$INSTALLDIR
108+
109+
cd $DOWNLOADDIR/glibc-$GLIBC_VERSION/build
110+
make -s -j$(nproc)
111+
make -s install DESTDIR=$SYSROOTDIR
112+
113+
cd $DOWNLOADDIR/gcc-$GCC_VERSION/build
114+
make -s -j$(nproc)
115+
make -s install-strip DESTDIR=$INSTALLDIR
116+
117+
cd $DOWNLOADDIR"/gcc-"$GCC_VERSION
118+
cat gcc/limitx.h gcc/glimits.h gcc/limity.h >$(dirname $($TARGET-gcc -print-libgcc-file-name))/include-fixed/limits.h
119+
120+
echo "Building GDB ..."
121+
rm -rf $DOWNLOADDIR/gdb-$GDB_VERSION/build/*
122+
cd $DOWNLOADDIR/gdb-$GDB_VERSION/build
123+
124+
../configure --prefix= --target=$TARGET --with-arch=$ARCH --with-float=hard
125+
make -s -j$(nproc)
126+
make -s install DESTDIR=$INSTALLDIR
127+
128+
echo "Creating TAR archive ..."
129+
cd $BUILDDIR
130+
tar czf cross-gcc-$GCC_VERSION-pi_$FOLDER_VERSION.tar.gz cross-pi-gcc-$GCC_VERSION-$FOLDER_VERSION
131+
mkdir -p /out
132+
mv cross-gcc-$GCC_VERSION-pi_$FOLDER_VERSION.tar.gz /out

docker/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ubuntu
2+
3+
WORKDIR /rpi-cross
4+
5+
RUN apt-get update \
6+
&& apt-get install -y \
7+
gperf flex texinfo gawk gfortran bison build-essential unzip wget git libncurses-dev autoconf automake \
8+
rsync python3 \
9+
&& git clone https://github.com/lindevs/cross-compiler-raspberrypi.git . \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
ENTRYPOINT ["/bin/bash"]

0 commit comments

Comments
 (0)