[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:hardware:arm:gcc-10.x_aarch64_cross-compiler [2020/12/31 18:10 (UTC)] – corrected script code creation date typo exagahowtos:hardware:arm:gcc-10.x_aarch64_cross-compiler [2021/10/01 09:26 (UTC)] (current) – [AArch64 cross-compiling 'HOWTO' example] removed superfluous text exaga
Line 1: Line 1:
 <!-- Add your text below. We strongly advise to start with a Headline (see button bar above). --> <!-- Add your text below. We strongly advise to start with a Headline (see button bar above). -->
-====== Slackware ARM current gcc-10.2.x armv8 arm64 aarch64 cross-compiler for the Raspberry Pi 4 ======+====== Slackware ARM current gcc-10.3.x armv8 arm64 aarch64 cross-compiler for the Raspberry Pi 4 ======
  
 ===== Preface ===== ===== Preface =====
Line 10: Line 10:
 ===== Notes ===== ===== Notes =====
  
-Slackware ARM current was used on a Raspberry Pi 4 to build and install the gcc-9.2.0 aarch64-linux cross-compiler, and build the armv8 Linux kernel, modules, and device tree blob(s). This was to achieve the highest degree of compatibility possible.+Slackware ARM current was used on a Raspberry Pi 4 [4GB RAM] to build and install the gcc-10.3.0 aarch64-linux cross-compiler.  
 + 
 +The Linux kernel source downloaded is from the Raspberry Pi Github repository: https://github.com/raspberrypi/linux
  
 For usage see the commented section at the top of the script itself. It explains pretty much everything you need to know in order to get started and be successful. If you need to you can refer to the instructions on [[https://docs.slackware.com/howtos:hardware:arm:gcc-9.x_aarch64_cross-compiler|this page]] as they are exactly the same, apart from the version numbers.  For usage see the commented section at the top of the script itself. It explains pretty much everything you need to know in order to get started and be successful. If you need to you can refer to the instructions on [[https://docs.slackware.com/howtos:hardware:arm:gcc-9.x_aarch64_cross-compiler|this page]] as they are exactly the same, apart from the version numbers. 
Line 19: Line 21:
  
 As a pre-requisite, you should have;  As a pre-requisite, you should have; 
-  * a Raspberry Pi 4 running Slackware ARM current with as much unused storage space on your system as possible. \\ +  * a Raspberry Pi 3 or (i.e. a 64bit CPU) running Slackware ARM current with as much unused [>= 5GB] storage space on your system as possible. \\ 
   * [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/a/gawk-5.1.0-arm-1.txz|gawk]],   [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/git-2.29.2-arm-1.txz|git]], [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/bison-3.7.4-arm-1.txz|bison]] and [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/flex-2.6.4-arm-4.txz|flex]], already installed on your system. \\     * [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/a/gawk-5.1.0-arm-1.txz|gawk]],   [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/git-2.29.2-arm-1.txz|git]], [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/bison-3.7.4-arm-1.txz|bison]] and [[http://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/flex-2.6.4-arm-4.txz|flex]], already installed on your system. \\  
  
Line 25: Line 27:
 ===== Aarch64 cross-compiler script code ===== ===== Aarch64 cross-compiler script code =====
  
-Copy and paste the following code into a text file and save it under any name you like but best to keep the extension of ".sh". I used "SARPi64.SlackBuild-gcc-10.2.0-aarch64-cc.sh" for this purpose.+Download the 'SARPi64.SlackBuild-gcc-10.3-aarch64-cc.sh' file by clicking the link at the top of the script code (or copy and paste the code if you prefer) below.
  
-Make the file executable using 'chmod +x <filename>.sh' or 'chmod 755 <filename>.sh' command. +Make the file executable using 'chmod +x SARPi64.SlackBuild-gcc-10.3-aarch64-cc.sh' or 'chmod 755 SARPi64.SlackBuild-gcc-10.3-aarch64-cc.sh' command. 
  
 Refer to the commented top section of the script code for usage.  Refer to the commented top section of the script code for usage. 
  
-<code>+<file sh SARPi64.SlackBuild-gcc-10.3-aarch64-cc.sh> 
 #! /bin/bash #! /bin/bash
  
 ############################################################################## ##############################################################################
-# Slackware ARM gcc-10.2.0 aarch64 cross-compiler for Raspberry Pi+# Slackware ARM gcc-10.3.0 aarch64 cross-compiler for Raspberry Pi
 # #
-# SARPi64.SlackBuild-gcc-10.2.0-aarch64-cc [v3.0] - 2020-12-29+# SARPi64.SlackBuild-gcc-10.3.0-aarch64-cc [v3.0] - 2021-04-22
 # #
 # 2020-12-29 by Exaga     v3.0    gcc-10.x # 2020-12-29 by Exaga     v3.0    gcc-10.x
Line 48: Line 51:
 # #
 # This script downloads RPi Linux kernel source and the required binaries,  # This script downloads RPi Linux kernel source and the required binaries, 
-# and configures, builds, patches, and installs a gcc 10.2.x aarch64-linux +# and configures, builds, patches, and installs a gcc 10.3.x aarch64-linux 
 # cross-compiler on Slackware ARM current running on a Raspberry Pi 3/4. # cross-compiler on Slackware ARM current running on a Raspberry Pi 3/4.
 # #
Line 55: Line 58:
 # (e.g. /tmp/build-dir) and run it from there as a 'root' user.  # (e.g. /tmp/build-dir) and run it from there as a 'root' user. 
 # #
-# ~# chmod +x SARPi64.SlackBuild-gcc-10.2-aarch64-cc.sh +# ~# chmod +x SARPi64.SlackBuild-gcc-10.3-aarch64-cc.sh 
-# ~# ./SARPi64.SlackBuild-gcc-10.2-aarch64-cc.sh+# ~# ./SARPi64.SlackBuild-gcc-10.3-aarch64-cc.sh
 # #
 # You may install the cross-compiler anywhere you like, as long as it can be  # You may install the cross-compiler anywhere you like, as long as it can be 
Line 97: Line 100:
 # #
 ### IMPORTANT! ### ### IMPORTANT! ###
-Before running this build scriptexport the INSTALL_PATH on your  +This script will export the INSTALL_PATH variable into the $PATH.  
-# root 'user'Also do this each time you (re)boot your system so that +The PATH of the cross-compiler should always be the first item in  
-the location of the cross-compiler is always the first item in your +the $PATH. PATH command: 
-# $PATH. You can also add this command to your ~/.profile as a more +
-# permanent fixture. It's up to you if/how you do it. Example export +
-PATH command: +
  
 # ~# export PATH=/tmp/.gcc-cross/bin:$PATH # ~# export PATH=/tmp/.gcc-cross/bin:$PATH
Line 135: Line 135:
  
 # Required build packages-versions [* newer versions may exist] # Required build packages-versions [* newer versions may exist]
-BINUTILS_VERSION=binutils-2.35+BINUTILS_VERSION=binutils-2.36
 CLOOG_VERSION=cloog-0.18.1 CLOOG_VERSION=cloog-0.18.1
-GCC_VERSION=gcc-10.2.0 +GCC_VERSION=gcc-10.3.0 
-GLIBC_VERSION=glibc-2.32+GLIBC_VERSION=glibc-2.33
 GMP_VERSION=gmp-6.2.1 GMP_VERSION=gmp-6.2.1
 ISL_VERSION=isl-0.18 ISL_VERSION=isl-0.18
Line 187: Line 187:
 echo " ## Build: $GCC_VERSION  Kernel ${DEV_BRANCH} " echo " ## Build: $GCC_VERSION  Kernel ${DEV_BRANCH} "
 echo " ## Timestamp: $(date '+%F %T') " echo " ## Timestamp: $(date '+%F %T') "
-echo " ## SARPi64 Project [sarpi64.fatdog.eu] "+echo " ## SARPi64 Project [sarpi64.penthux.net] "
 echo " ############################################" echo " ############################################"
 echo  echo 
Line 199: Line 199:
 echo "Checking $ARCH_TARGET $INSTALL_PATH/bin \$PATH ..." echo "Checking $ARCH_TARGET $INSTALL_PATH/bin \$PATH ..."
 if [[ ! "$PATH" =~ $INSTALL_PATH ]]; then if [[ ! "$PATH" =~ $INSTALL_PATH ]]; then
-  echo "ERROR: $INSTALL_PATH/bin NOT found in \$PATH. Stopping build ..." +    export PATH=/"${INSTALL_PATH}"/bin:$PATH 
-  echo "Use command: export PATH=$INSTALL_PATH/bin:\$PATH+
-  exit +
 # echo -e $INSTALL_PATH/bin:$(cat $PATH) > $PATH || exit 1 # echo -e $INSTALL_PATH/bin:$(cat $PATH) > $PATH || exit 1
 else else
-  echo "Found $INSTALL_PATH\/bin in \$PATH : OK! ... "+    echo "Found $INSTALL_PATH\/bin in \$PATH : OK! ... "
 fi fi
  
Line 322: Line 320:
 make $PARALLEL_JOBS install-gcc make $PARALLEL_JOBS install-gcc
  
-# create gcc-10.2.0 libsanitizer asan_linux-cpp.patch file+# create gcc-10.3.0 libsanitizer asan_linux-cpp.patch file
 cd "$CWD" cd "$CWD"
 touch asan_linux-cpp.patch touch asan_linux-cpp.patch
 cat << EOF > asan_linux-cpp.patch cat << EOF > asan_linux-cpp.patch
---- gcc-10.2.0/libsanitizer/asan/asan_linux.cpp 2020-12-29 22:57:16.000000000 +0000 +--- gcc-10.3.0/libsanitizer/asan/asan_linux.cpp 2021-04-08 12:56:30.229766760 +0100 
-+++ asan_linux.cpp 2020-12-29 23:20:04.000000000 +0000++++ asan_linux.cpp.new 2021-04-22 13:26:26.000000000 +0100
 @@ -76,6 +76,10 @@ @@ -76,6 +76,10 @@
  asan_rt_version_t  __asan_rt_version;  asan_rt_version_t  __asan_rt_version;
  }  }
- +
 +#ifndef PATH_MAX +#ifndef PATH_MAX
 +#define PATH_MAX 4096 +#define PATH_MAX 4096
Line 337: Line 335:
 + +
  namespace __asan {  namespace __asan {
- +
  void InitializePlatformInterceptors() {}  void InitializePlatformInterceptors() {}
  
 EOF EOF
  
-# Patch gcc-10.2.x/libsanitizerasan/asan_linux.cpp [or the build will fail]+# Patch gcc-10.3.x/libsanitizerasan/asan_linux.cpp [or the build will fail]
 ASANLINUXCC=$CWD/$GCC_VERSION/libsanitizer/asan/asan_linux.cpp ASANLINUXCC=$CWD/$GCC_VERSION/libsanitizer/asan/asan_linux.cpp
 if [ ! -f "$ASANLINUXCC".orig ]; then if [ ! -f "$ASANLINUXCC".orig ]; then
Line 411: Line 409:
 #EOF<*> #EOF<*>
  
-</code>+</file> 
 + 
 +===== Configuring the system to use the Aarch64 cross-compiler ===== 
 + 
 +Once the cross-compiler has been built and you intend to use it to compile Aarch64 [64bit] binaries, the location of the tool-chains must be exported to your system's $PATH variable. It's also prudent to have this entry appear before all other PATHs. So, for example, to check what your existing $PATH includes, use the 'echo $PATH' command like this:  
 + 
 +<code>root@slackware:~# echo $PATH 
 +/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/qt/bin</code> 
 + 
 +This is the output of the $PATH on our Slackware ARM system before adding the '/path/to/cross-compiler/bin' tool-chain location. Your own $PATH might be very different.  
 + 
 +If you didn't change the 'INSTALL_PATH' variable in the build script then the command the script uses to export the PATH will be like this: 
 + 
 +<code>root@slackware:~# export PATH=/tmp/.gcc-cross/bin:$PATH</code> 
 + 
 +This is the command to use if it doesn't already appear in your system $PATH. Obviously, if you've modified the INSTALL_PATH variable then that location will be used instead of the default. You can check the $PATH variable to ensure that it has been added correctly: 
 + 
 +<code>root@slackware:~# echo $PATH 
 +/tmp/.gcc-cross/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/qt/bin</code> 
 + 
 +The example output above all looks good because the cross compile PATH appears first before everything else. 
 + 
 +===== Aarch64 cross-compiling 'HOWTO' example ===== 
 + 
 +So, when the Aarch64 tool-chains feature in the $PATH on the system, they can be utilised to build software for the ARMv8 architecture instead of your Slackware ARM system's [ARMv7] existing infrastructure. It's all done via the 'make' process. 
 + 
 +As an example to show how this can be achieved, the bespoke RPi kernel source 'master' branch will be used. This kernel source will be downloaded and located in '/tmp/linux-rpi' directory. [**NB: note that this is __NOT__ '/usr/src/linux' - it should never reside in that standard location for cross-compiling purposes!**]. After downloading the Linux source, use 'cd' to the directory where it's located: 
 + 
 +<code>root@slackware:~# git clone --depth=1 git://github.com/raspberrypi/linux /tmp/linux-rpi 
 +Cloning into '/tmp/linux-rpi'... 
 +~ Enumerating, Counting, Compressing, yadda yadda yadda ~ 
 +Updating files: 100% (66403/66403), done. 
 +root@slackware:~# cd /tmp/linux-rpi/ 
 +root@slackware:/tmp/linux-rpi# </code> 
 + 
 +We use '--depth=1' option to only download the latest commit and not the entire branch content, which may currently be +10GB in size. The actual disk space amount used for the source that's just been downloaded is: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# du -sh /tmp/linux-rpi/ 
 +1.2G    /tmp/linux-rpi/ </code> 
 + 
 +To verify which major/minor revision of the Linux kernel source you're working with, use the 'head' command on the 'Makefile', like this: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# head -5 Makefile 
 +# SPDX-License-Identifier: GPL-2.0 
 +VERSION = 5 
 +PATCHLEVEL = 4 
 +SUBLEVEL = 83 
 +EXTRAVERSION = 
 +root@slackware:/tmp/linux-rpi# </code> 
 + 
 +At the time of writing, this is kernel 5.4.83 source from the Raspberry Pi Github repository 'master' branch. You can download and work with other branches by simply maniplulating the 'git' command options. Right now the downloaded kernel source is in a "raw state" (i.e. it includes no settings or configurations) and it's not going to build anything until some form of instructions exist regarding specifically how/what/which to compile.  
 + 
 +What's missing now is a kernel '.config' - a file that includes instructions (i.e. settings) that's an essential prerequisite in order to compile the Linux source into a resulting kernel image file - and you won't be doing much without creating one first. This is __much__ easier said than done if you're starting from scratch, because it requires intimate knowledge about the the computer/device hardware that you're building the kernel to support. However, with the Raspberry Pis (and many other ARM devices) there is such a thing as a 'default config', or 'defconfig', that can be called to build the kernel '.config' file for you and save a lot of time and effort (and unfortunately a huge amount of education and experience is also wasted in this process). So in the interest of saving time, let's do it the easy and lazy way for this example... 
 + 
 +For the Raspberry Pi 3 to build a default kernel '.config' file for Aarch64 architecture: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- bcm2709_defconfig </code> 
 + 
 +For the Raspberry Pi 4 to build a default kernel '.config' file for Aarch64 architecture: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# make ARCH=arm64 CROSS_COMPILE=aarch64-linux- bcm2711_defconfig </code> 
 + 
 +OK! So, normally you would just use 'make <deviceID>_defconfig' to achieve this but here it's the 'ARCH=arm64 CROSS_COMPILE=aarch64-linux-' that makes ALL the difference. You should now have a '.config' file in your Linux source directory which reflects that. Check it out with the 'head' command: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# head -10 .config 
 +
 +# Automatically generated file; DO NOT EDIT. 
 +# Linux/arm64 5.4.83 Kernel Configuration 
 +
 + 
 +
 +# Compiler: aarch64-linux-gcc (GCC) 10.3.0 
 +
 +CONFIG_CC_IS_GCC=y 
 +CONFIG_GCC_VERSION=100300 
 +root@slackware:/tmp/linux-rpi# </code> 
 + 
 +If this is what you see then it's perfect and ready to compile your kernel. In exactly the same way, now 'make' the kernel image, BUT... invoke 'multijobs' as well. Multijobs is the '-j4' option. The '-j<number>' will use more than just a single core of the CPU to build and dramatically cut down on the compile time(s) involved. The RPi3 and RPi4 have quad-core CPUs so it's quite safe to use four cores here, like this: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux- Image </code> 
 + 
 +Incidentally, and very logically, it's the same structure and options to compile the DTBs, kernel-headers, modules, etc. and install them: 
 + 
 +<code>root@slackware:/tmp/linux-rpi# make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux- dtbs </code> 
 +<code>root@slackware:/tmp/linux-rpi# make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux- headers_install </code> 
 +<code>root@slackware:/tmp/linux-rpi# make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux- modules </code> 
 +<code>root@slackware:/tmp/linux-rpi# make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux- modules_install </code> 
 + 
 +**NB: Under normal circumstances you wouldn't compile and install the kernel-headers (as they are already included in the kernel) unless you're intending to build external modules or "outside of source-tree" software. If you don't understand what this means or what it entails, then skip the kernel-headers completely.** 
 + 
 +<note warning>**BEFORE CONTINUING - Make a back-up __FIRST__ of your '/boot/' directory before coping any new files to it, in case things don't go exactly as planned. Only reboot once everything is correctly in place and you have your backup(s) to fall-back on.**</note> 
 + 
 +So with everything compiled and built, you just need to copy the 'kernel' image, 'DTBs' and 'System.map' to your '/boot' directory. 
 + 
 +<note important>NB: By default, on Raspberry Pi ARMv7 [32-bit] systems, the kernel image is named 'kernel7.img' on the RPi3, and for the RPi4 the kernel image is named 'kernel7l.img' - where the "L" is actually an indicator for "Large Physical Address Extension (LPAE)". However, on Raspberry Pi ARMv8 [64-bit] systems the kernel is named 'kernel8.img'. This filename __MUST__ be correct in order for the boot-loader to find and run the ARMv8 [64-bit] kernel! If you have specified a custom kernel image filename in the '/boot/config.txt' file then you already know what you're doing here. ;-)</note> 
 + 
 +<code>root@slackware:/tmp/linux-rpi# cp -avr arch/arm64/boot/Image /boot/kernel8.img" 
 +root@slackware:/tmp/linux-rpi# cp -avr arch/arm64/boot/dts/broadcom/bcm27*.dtb /boot/ 
 +root@slackware:/tmp/linux-rpi# cp -avr System.map /boot/System.map</code> 
 + 
 +That's it! When you reboot your system it should now be using a 64bit kernel and modules. One should be mindful that [[http://arm.slackware.com/|Slackware Aarch64]] is in development and building kernels using a cross-compiler will soon become superfluous on that system architecture, but for 32bit systems and users a cross-compiler may still be relevant.  
 + 
 +I hope this Aarch64 cross-compiler build script and/or information will be useful for Slackware [ARM] users in whatever ways are possible. Any questions or assistance can be addressed via the [[https://www.linuxquestions.org/questions/slackware-arm-108/|Linux Questions forum(s)]]
  
-That's it. Enjoy and happy cross-compiling! 8-)+Thanks very much for your interest in this Aarch64 cross-compiler on the Raspberry Pi. 
  
 ====== Sources ====== ====== Sources ======
-# If you need to install any of the pre-requisite software here are the links [* check for updates!]:+# If you need to install any of the pre-requisite software here are the links [**NB: check for updates!**]:
  
-[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/a/gawk-5.1.0-arm-1.txz]]  # Slackware ARM current - gawk package. \\ +[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/a/]] # Slackware ARM current - gawk package. \\ 
-[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/git-2.29.2-arm-1.txz ]] # Slackware ARM current - git package. \\ +[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/]] # Slackware ARM current - git package. \\ 
-[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/bison-3.7.4-arm-1.txz]]  # Slackware ARM current - bison package. \\ +[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/]] # Slackware ARM current - bison package. \\ 
-[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/flex-2.6.4-arm-4.txz]] # Slackware ARM current - flex package. \\ +[[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/]] # Slackware ARM current - flex package. \\ 
 [[https://www.github.com/raspberrypi/]] # Raspberry Pi Foundation GitHub repository Linux kernel and boot-firmware source. \\ [[https://www.github.com/raspberrypi/]] # Raspberry Pi Foundation GitHub repository Linux kernel and boot-firmware source. \\
 [[https://ftp.gnu.org/gnu/]] # gcc, binutils, glibc, gmp, mpc, mpfr package source. \\  [[https://ftp.gnu.org/gnu/]] # gcc, binutils, glibc, gmp, mpc, mpfr package source. \\ 
 howtos:hardware:arm:gcc-10.x_aarch64_cross-compiler ()