[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
Last revisionBoth sides next revision
howtos:hardware:arm:gcc-9.x_aarch64_cross-compiler [2019/07/25 19:02 (UTC)] – [Downloading required source and configuration] erour koreekshuns exagahowtos:hardware:arm:gcc-9.x_aarch64_cross-compiler [2019/08/03 12:46 (UTC)] – [Building the gcc aarch64 cross-compiler] missing CFLAG exaga
Line 3: Line 3:
 === Preface === === Preface ===
  
-With the recent congruous updates to [[http://arm.slackware.com|Slackware ARM]] [~24 June 2019 - "A MILLION THANKS to MoZes!"] and the surprise arrival of the Raspberry Pi 4, this just had to be done. Creating a gcc-9.1.0 armv8 arm64 aarch64 cross-compiler with the intention of building aarch64-linux binaries from source code and turning them into Slackware packages. +With the recent congruous updates to [[http://arm.slackware.com|Slackware ARM]] [~24 June 2019 - "A MILLION THANKS to MoZes!"] and the surprise arrival of the Raspberry Pi 4, this just had to be done. Creating a 64-bit gcc-9.1.0 arm64 aarch64 cross-compiler with the intention of building aarch64-linux binaries from source code and turning them into Slackware packages. 
  
-Previous [[howtos:hardware:arm:gcc_aarch64_cross-compiler|work in this area]] had already been done in 2016/2017. However, this time we'll be compiling with gcc-9.1.0 and not gcc-5.4.0 and we'll be using a Raspberry Pi 4 Model B and not a Mk3 version. The old build scripts weren't totally useless and some of the code was reused for this project, to save time.+Previous [[howtos:hardware:arm:gcc_aarch64_cross-compiler|work in this area]] had already been done since 2016/2017. However, this time we'll be compiling with gcc-9.1.0 and not gcc-5.4.0 and we'll be using a Raspberry Pi 4 Model B and not a Mk3 version. The old build scripts weren't totally useless and some of the code was reused for this project, to save time.
  
 === Notes === === Notes ===
Line 60: Line 60:
  
 When that's done you should see a message that 'origin/rpi-5.2.y' is the current branch. When that's done you should see a message that 'origin/rpi-5.2.y' is the current branch.
 +
 +<note tip>You can select which kernel source you would like to build instead of rpi-5.2.y branch. Just substitute it in the 'git checkout -f rpi-5.2.y' command for your chosen branch. To see a list of available branches use this command while in your Linux source directory:
 +
 +<code>
 +git branch -a
 +</code></note>
 +
 +
  
 === Downloading required package source === === Downloading required package source ===
  
-Before downloading the package source needed to build the GCC cross-compiler, be aware that more recent package versions may exist than the ones shown here. You may wish to install newer versions. It's always a good idea to check. To keep things simple, you might consider downloading a version of GCC which matches the one you currently have installed. I've read lots of articles about this and most advise to install the //latest and greatest// version of GCC available. However, if you're running Slackware ARM current you'll have gcc-9.1.0 installed and this is adequate for what you need.+Before downloading the package source needed to build the gcc cross-compiler, be aware that more recent package versions may exist than the ones shown here. You may wish to install newer versions. It's always a good idea to check. To keep things simple, you might consider downloading a version of gcc which matches the one you currently have installed. I've read lots of articles about this and most advise to install the //latest and greatest// version of gcc available. However, if you're running Slackware ARM current you'll have gcc-9.1.0 installed and this is adequate for what you need.
  
-So, first move back into the 'build-dir' directory and then download the packages below.+So, first move back into the 'BUILD' directory and then download the packages below.
  
 <code> <code>
Line 89: Line 97:
 Once this has completed you can us the '**ls**' command to verify that the directories are present. Once this has completed you can us the '**ls**' command to verify that the directories are present.
  
-=== Creating GCC dependency symlinks ===+=== Creating gcc dependency symlinks ===
  
-Now you are going to create some symbolic links in the gcc-9.1.0 directory. These will point to some of the source directories you have just unpacked, which are dependencies of GCC, and when these symbolic links are present GCC will build them automatically.+Now you are going to create some symbolic links in the gcc-9.1.0 directory. These will point to some of the source directories you have just unpacked, which are dependencies of gcc, and when these symbolic links are present gcc will build them automatically.
  
 <code> <code>
Line 123: Line 131:
 === Exporting install directory PATH === === Exporting install directory PATH ===
  
-You need to export the installation directory's /bin folder to your user's $PATH. the PATH of your gcc-9.1.0 cross-compiler bin needs to be the FIRST item in the $PATH in order to be successful.+You need to export the installation directory''/binfolder to your user's $PATH. The PATH of your gcc-9.1.0 cross-compiler bin needs to be the __FIRST__ item in the $PATH in order to be successful.
  
 <code> <code>
Line 141: Line 149:
 </code> </code>
  
-==== Building the GCC aarch64 cross-compiler ====+NB: your $PATH may be very different from the one shown above, but that doesn't matter. As long as the PATH to your gcc cross-compiler's '/bin' directory is the first item in the $PATH it's all good. 
 + 
 +==== Building the gcc aarch64 cross-compiler ====
  
 Now with all that in place, concentration focuses on building the cross-assembler, cross-disassembler, cross-linker, and other useful tools. Now with all that in place, concentration focuses on building the cross-assembler, cross-disassembler, cross-linker, and other useful tools.
Line 147: Line 157:
 === Building binutils === === Building binutils ===
  
-First move back into the 'build-dir' directory and then create a build directory for binutils. You'll notice the various build options but as a quick explanation; '--with-sysroot' basically tells binutils to enable 'sysroot' support in the cross-compiler by pointing it to a default empty directory, '--target=aarch64-linux' is the target system type (arm64), and '--disable-multilib' means that we only want binutils to work with the aarch64 instruction set and nothing else. +First move back into the 'BUILD' directory and then create a build directory for binutils. You'll notice the various CFLAGS but as a quick explanation; '--with-sysroot' basically tells binutils to enable 'sysroot' support in the cross-compiler by pointing it to a default empty directory, '--target=aarch64-linux' is the target system type (arm64), and '--disable-multilib' means that we only want binutils to work with the aarch64 instruction set and nothing else. 
  
 <code> <code>
Line 153: Line 163:
 mkdir build-binutils mkdir build-binutils
 cd build-binutils cd build-binutils
-../binutils-2.32/configure --prefix=/tmp/.gcc-cross --target=aarch64-linux --disable-multilib+../binutils-2.32/configure --prefix=/tmp/.gcc-cross --target=aarch64-linux --with-sysroot --disable-multilib
 make -j4  make -j4 
 make install make install
Line 160: Line 170:
 === Installing Linux kernel headers === === Installing Linux kernel headers ===
  
-Here you need to install the Linux kernel headers. Note the 'ARCH=arm64' option for the make process. GCC uses 'aarch64' where the Linux kernel uses 'arm64'. The two separate open source projects identify the same CPU architecture differently. +Here you need to install the Linux kernel headers. Note the 'ARCH=arm64' option for the make process. gcc uses 'aarch64' where the Linux kernel uses 'arm64'. The two separate open source projects identify the same CPU architecture differently. 
  
 <code> <code>
Line 169: Line 179:
 === Build gcc C and C++ cross-compilers === === Build gcc C and C++ cross-compilers ===
  
-First move into the 'build-dir' directory and create a build directory for GCC before building it. Notice that only C and C++ have been specified as build languages. That's all you will need here. Incidentally, the available build language options allow just one, or a selection, or all, of the following '--enable-languages=all,ada,c,c++,fortran,go,jit,lto,objc,obj-c++'.+First move into the 'BUILD' directory and create a build directory for gcc before building it. Notice that only C and C++ have been specified as build languages. That's all you will need here. Incidentally, the available build language options allow just one, or a selection, or all, of the following '--enable-languages=all,ada,c,c++,fortran,go,jit,lto,objc,obj-c++'.
  
 <code> <code>
Line 223: Line 233:
 === Build and install glibc === === Build and install glibc ===
  
-First move into the 'build-dir' directory and create a 'build-glibc' directory. Then move into the 'build-glibc' directory before building it. '--build=$MACHTYPE' is a predefined environment variable which describes the Raspberry Pi 4 (in this case) and it's required to compile some additional tools which are utilised during the build process. Notice that you're installing the C library startup files to the installation directory (csu/crt1.o, csu/crti.o, and csu/crtn.o) separately because there doesn’t seem to a 'make' rule that does this without creating other problems.+First move into the 'BUILD' directory and create a 'build-glibc' directory. Then move into the 'build-glibc' directory before building it. '--build=$MACHTYPE' is a predefined environment variable which describes the Raspberry Pi 4 (in this case) and it's required to compile some additional tools which are utilised during the build process. Notice that you're installing the C library startup files to the installation directory (csu/crt1.o, csu/crti.o, and csu/crtn.o) separately because there doesn’t seem to a 'make' rule that does this without creating other problems.
  
 <code> <code>
Line 239: Line 249:
 === Building glibc support library === === Building glibc support library ===
  
-Now move into the 'build-gcc' directory once again and build the GCC cross-compiler support library.+Now move into the 'build-gcc' directory once again and build the gcc cross-compiler support library.
  
 <code> <code>
Line 257: Line 267:
 </code> </code>
  
-=== Finish building GCC C++ library ==+=== Finish building gcc C++ library ==
  
-Move into the 'build-gcc' directory to finish building GCC C++ library and then install it.+Move into the 'build-gcc' directory to finish building gcc C++ library and then install it.
  
 <code> <code>
Line 271: Line 281:
 === Testing the cross-compiler === === Testing the cross-compiler ===
  
-To test/check that your GCC aarch64-linux cross-compiler is working properly run the following command.+To test/check that your gcc aarch64-linux cross-compiler is working properly run the following command.
  
 <code> <code>
Line 292: Line 302:
 </code> </code>
  
-Once this process has been completed, export the GCC cross-compiler PATH on your normal user. If/when you're wanting to cross-compile do this each time after you've (re)booted your system so that the GCC cross-compiler can be located via your user's $PATH. You also have the option to add this command to your **~/.profile** as a permanent setting. Whether or not you decide to permanently add the GCC cross-compiler PATH to your ~/.profile is entirely up to you. If you are using your Slackware ARM current system for exclusively building aarch64 (arm64) packages then it would make sense to do so.+Once this process has been completed, export the gcc cross-compiler PATH on your normal user. If/when you're wanting to cross-compile do this each time after you've (re)booted your system so that the gcc cross-compiler can be located via your user's $PATH. You also have the option to add this command to your **~/.profile** as a permanent setting. Whether or not you decide to permanently add the gcc cross-compiler PATH to your ~/.profile is entirely up to you. If you are using your Slackware ARM current system for exclusively building aarch64 (arm64) packages then it would make sense to do so.
  
 Example export command:  Example export command: 
Line 300: Line 310:
 </code> </code>
  
-The GCC aarch64-linux cross-compiler on your Slackware ARM system is now ready to //rock-n-roll!// +The gcc aarch64-linux cross-compiler on your Slackware ARM system is now ready to //rock-n-roll!// 
  
 ==== Building the arm64 kernel, modules, and device tree blob (DTB) ==== ==== Building the arm64 kernel, modules, and device tree blob (DTB) ====
  
-To build the aarch64 kernel, modules and device tree blob(s) is exactly the same method as you would carry it out under normal circumstances. Commands such as 'make bzImage && make modules && make modules_install' may be all too familiar to you. The major difference when cross-compiling is that you'll use certain Makefile options/variables/arguments/switches, commonly known as CFLAGS. In our case, CFLAGS will be used to instruct the GCC cross-compiler to build for the aarch64 (arm64) architecture specifically.+To build the aarch64 kernel, modules and device tree blob(s) is exactly the same method as you would carry it out under normal circumstances. Commands such as 'make bzImage && make modules && make modules_install' may be all too familiar to you. The major difference when cross-compiling is that you'll use certain Makefile variables/arguments/switches, commonly known as //build options//<. In our case, //build options// will be used to instruct the gcc cross-compiler to build for the aarch64 (arm64) architecture specifically.
  
 === Creating the arm64 kernel .config === === Creating the arm64 kernel .config ===
  
-First of all, as always, you need to be in the Raspberry Pi Linux kernel source directory which is in the 'build-dirfolder. Then you need to create a kernel .config file, based on Raspberry Pi 4 parameters. To keep it simple you can generate a default .config (**defconfig**) file. This file holds the Linux kernel configuration for the arm64 kernel you are going to build. To achieve this run the following commands:+First of all, as always, you need to be in the Raspberry Pi Linux kernel source directory which is within your 'BUILDdirectory. Then you need to create a kernel .config file, based on Raspberry Pi 4 parameters. To keep it simple you can generate a default .config (**defconfig**) file. This file holds the Linux kernel configuration for the arm64 kernel you are going to build. To achieve this run the following commands:
  
 <code> <code>
Line 315: Line 325:
 </code> </code>
  
-<note important>Make a note here of the CFLAGS which have been specified. They should be self-explanatory by now. Pay special attention to the trailing '-' of 'CROSS_COMPILE=aarch64-linux-' because that's **NOT** a typo. __It needs to be like that!__</note>+<note important>Make a note here of the //build options// [ARCH=arm64 CROSS_COMPILE=aarch64-linux-] which have been specified. They should be self-explanatory by now. Pay special attention to the trailing '-' of 'CROSS_COMPILE=aarch64-linux-' because that's **NOT** a typo. __It needs to be like that!__</note>
  
 Now that you've created a kernel .config which contains the default settings for your hardware, some settings within need to be checked and possibly modified. The Raspberry Pi 4's "VideoCore VI" GPU is not //64-bit compatible// and the build process will crash each time you attempt to compile the module's source code for ARMv8 architecture. Now that you've created a kernel .config which contains the default settings for your hardware, some settings within need to be checked and possibly modified. The Raspberry Pi 4's "VideoCore VI" GPU is not //64-bit compatible// and the build process will crash each time you attempt to compile the module's source code for ARMv8 architecture.
Line 363: Line 373:
 === Building the arm64 kernel === === Building the arm64 kernel ===
  
-Next up is building the kernel, based on the .config file you have just created. Again, you'll use the same CFLAGS as before. You can even set a 'LOCALVERSION' here which appends whatever you set to the end of the kernel version (e.g. LOCALVERSION="-aarch64" would eventually give you 5.2.1-v8-aarch64) once the kernel and modules have been built. Just as an example we'll use it here. Run the following command to start building the arm64 Linux kernel:+Next up is building the kernel, based on the .config file you have just created. Again, you'll use the same //build options// as before. You can even set a 'LOCALVERSION' here which appends whatever you set to the end of the kernel version (e.g. LOCALVERSION="-aarch64" would eventually give you 5.2.1-v8-aarch64) once the kernel and modules have been built. Just as an example we'll use it here. Run the following command to start building the arm64 Linux kernel:
  
 <code> <code>
Line 396: Line 406:
 === Installing the arm64 modules === === Installing the arm64 modules ===
  
-Once the modules have been built, you have to 'make modules_install' The process will install your kernel modules to '/tmp/lib/modules/5.2.1-v8-aarch64'+Once the modules have been built, you have to 'make modules_install' The process will install your kernel modules to '/lib/modules/5.2.1-v8-aarch64'
  
-You could build  //out-of-tree// kernel modules but, to keep things simple, you're going to install them to the usual location. Again, you will use the same CFLAGS as before but without any 'LOCALVERSION' set.+You could build  //out-of-tree// kernel modules but, to keep things simple, you're going to install them to the usual location. Again, you will use the same //build options// as before but without any 'LOCALVERSION' set.
  
 First you need become '**root**' user and enter a passwd when prompted. To install the aarch64 modules run the following commands: First you need become '**root**' user and enter a passwd when prompted. To install the aarch64 modules run the following commands:
Line 409: Line 419:
 <note important>You need to be '**root**' user to install the arm64 modules. A normal user does not have the rights to do so!</note> <note important>You need to be '**root**' user to install the arm64 modules. A normal user does not have the rights to do so!</note>
  
-So, as I'm a great believer in being thorough, I always verify things at every opportunity. Just to be sure, if nothing else, because it's always a good policy. Make sure the files and directories you have just spent quite a bit of time compiling actually do exist on your system and that they're in the right place. If this is the first time you have installed the GCC cross-compiler on your system and/or built the kernel, modules, and device tree blob(s), then it goes without saying. You could actually do this after each build process, which I often do as well.+So, as I'm a great believer in being thorough, I always verify things at every opportunity. Just to be sure, if nothing else, because it's always a good policy. Make sure the files and directories you have just spent quite a bit of time compiling actually do exist on your system and that they're in the right place. If this is the first time you have installed the gcc cross-compiler on your system and/or built the kernel, modules, and device tree blob(s), then it goes without saying. You could actually do this after each build process, which I often do as well.
  
 <code> <code>
Line 482: Line 492:
 <code> <code>
 ls -lah rpi-boot/boot/kernel* ls -lah rpi-boot/boot/kernel*
-ls -lah rpi-boot/boot/bcm*-rpi-3-b.dtb +ls -lah rpi-boot/boot/bcm*-rpi-4-b.dtb 
 ls -lah rpi-root/lib/modules/5.2.1-v8* ls -lah rpi-root/lib/modules/5.2.1-v8*
 </code> </code>
Line 542: Line 552:
  
 ====== Sources ====== ====== Sources ======
-# If you need to install any of the packages above [* check for updates!]:+# If you need to install any of the software above [* check for updates!]:
  
 [[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/a/gawk-5.0.1-arm-1.txz]]  # Slackware ARM current - gawk package. \\ [[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/a/gawk-5.0.1-arm-1.txz]]  # Slackware ARM current - gawk package. \\
Line 548: Line 558:
 [[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/bison-3.4.1-arm-1.txz]]  # Slackware ARM current - bison package. \\ [[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/bison-3.4.1-arm-1.txz]]  # Slackware ARM current - bison package. \\
 [[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/flex-2.6.4-arm-3.txz]] # Slackware ARM current - flex package. \\  [[ftp://ftp.arm.slackware.com/slackwarearm/slackwarearm-current/slackware/d/flex-2.6.4-arm-3.txz]] # Slackware ARM current - flex package. \\ 
-[[http://arm.slackware.com/FAQs]] # Slackware ARM Linux Project Frequently Asked Questions. \\  +[[https://www.github.com/raspberrypi/]] # Raspberry Pi Foundation GitHub repository Linux kernel and boot-firmware source. \\ 
-[[http://wiki.osdev.org/GCC_Cross-Compiler]] # GCC cross-compiler documentation. \\ +[[https://ftp.gnu.org/gnu/]] # gcc, binutils, glibc, gmp, mpc, mpfr package source. \\  
 +[[ftp://gcc.gnu.org/pub/gcc/infrastructure]] # cloog, isl package source. 
 + 
 +# Documentation which assisted in this guide: 
 + 
 +[[slackwarearm:faq|http://arm.slackware.com/FAQs]] # Slackware ARM Linux Project Frequently Asked Questions. \\  
 +[[http://wiki.osdev.org/GCC_Cross-Compiler]] # gcc cross-compiler documentation. \\  
 +[[howtos:hardware:arm:gcc_aarch64_cross-compiler|Slackware ARM GCC aarch64-linux cross-compiler]] for the Raspberry Pi. \\
 [[https://www.raspberrypi.org/documentation/linux/kernel]] # Raspberry Pi Linux kernel documentation. \\  [[https://www.raspberrypi.org/documentation/linux/kernel]] # Raspberry Pi Linux kernel documentation. \\ 
-[[https://www.github.com/raspberrypi/]] # Raspberry Pi Foundation GitHub repository Linux kernel, bootloader/GPU firmware. \\ 
-[[https://ftp.gnu.org/gnu/]] # GCC, binutils, glibc, gmp, mpc, mpfr package source \\  
-[[ftp://gcc.gnu.org/pub/gcc/infrastructure]] # cloog, isl package source 
  
 <!-- If you are copying information from another source, then specify that source --> <!-- If you are copying information from another source, then specify that source -->
 <!-- * Original source: [[http://some.website.org/some/page.html]] --> <!-- * Original source: [[http://some.website.org/some/page.html]] -->
 <!-- Authors are allowed to give credit to themselves! --> <!-- Authors are allowed to give credit to themselves! -->
-  * Originally written by [[wiki:user:exaga | Exaga]] - 2019-07-24 19:28:09 [GMT] 
 <!-- * Contributions by [[wiki:user:yyy | User Y]] --> <!-- * Contributions by [[wiki:user:yyy | User Y]] -->
 +
 +* Originally written by [[wiki:user:exaga | Exaga]] - 2019-07-24 19:28:09 [GMT]
  
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
 <!-- You must remove the tag-word "template" below before saving your new page --> <!-- You must remove the tag-word "template" below before saving your new page -->
-{{tag>howtos raspberry pi aarch64 arm64 armv8 cross-compile author_exaga}}+{{tag>howtos slackware raspberry pi arm aarch64 arm64 armv8 cross-compile author_exaga}}
  
 howtos:hardware:arm:gcc-9.x_aarch64_cross-compiler ()