Debian Toolchain installation: Difference between revisions

From Variscite Wiki
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
--> {{INIT_RELEASE_PARAM|mx8m-debian-bullseye-5.4-2.1.x-v1.4}}<!--
--> {{INIT_RELEASE_PARAM|mx8m-debian-bullseye-5.4-2.1.x-v1.4}}<!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{PageHeader|Debian toolchain installation for out of Debian builds}} {{DocImage|category1=Debian|category2={{#var:HARDWARE_NAME}}}} __toc__
--> {{PageHeader|Debian toolchain for cross-compilation}} {{DocImage|category1=Debian|category2={{#var:HARDWARE_NAME}}}} __toc__


= Installing the toolchain =
= Prerequisites =
Please follow steps 2 & 4 of the {{Varlink|Debian_Build_Release_Stage|{{#var:RELEASE_LINK}}|Build Debian from source code}} guide, to setup a Debian build environment.


To install the toolchain, please go through the following steps of the {{varlink|Debian Build Release Stage|{{#var:RELEASE_LINK}}|Debian Build Release}} guide:
= Obtain the toolchain =
# {{varlink|Debian Build Release Stage#Setup Development Environment|{{#var:RELEASE_LINK}}|Setup Development Environment}}
The toolchain can be downloaded by running the following:
# {{varlink|Debian Build Release Stage#Installing required packages|{{#var:RELEASE_LINK}}|Installing required packages}}
$ cd {{#var:BUILD_FOLDER}}
# {{varlink|Debian Build Release Stage#Download Debian archive|{{#var:RELEASE_LINK}}|Download Debian archive}}
$ {{#var:BUILD_SCRIPT}} -c deploy
# {{varlink|Debian Build Release Stage#Deploy sources|{{#var:RELEASE_LINK}}|Deploy/Fetch the sources and components}}


You will have a development environment from this point, including the toolchain and the packages ready to be used.
This will download the toolchain '''{{#var:TOOLCHAIN}}''' (or a newer version), which can be found at ''{{#var:BUILD_FOLDER}}/toolchain''.


The GNU Linux toolchain '''{{#var:TOOLCHAIN}}''' can be found at {{#var:BUILD_FOLDER}}/toolchain. <!--
= Create a sysroot for user space cross-compilation =
A sysroot is basically a scaled-downed version of the target file system to be used on the host for cross-compilation of user space applications.
 
In the following we will show how to create the sysroot using a script, pre-shipped with the Debian archive, or manually. In any case, we would need a full Debian rootfs first, please refer to {{varlink|Debian Build Release Stage#Setup and build Debian|{{#var:RELEASE_LINK}}|Setup and build Debian}} to learn how to build it. Once the rootfs have been built, it should be present at ''{{#var:BUILD_FOLDER}}/rootfs''. From this point, follow one of the upcoming sections.
{{Note|'''Notes''':
* The Debian build script uses debootstrap to create a minimal Debian {{#var:DEBIAN_NAME}} system and adds the BSP support. Please consider installing extra (dev-)packages to your Debian file system as per your needs.<br>To do this, follow the {{varlink2|Adding Debian packages|{{#var:RELEASE_LINK}}}} guide to learn how to add packages to the rootfs.
* Keeping the sysroot in sync with the rootfs of the target is recommended to avoid misalignments. Whenever a change has been made to the rootfs, please consider creating a new sysroot as described.
}}


-->{{Note|'''Note:''' Alternatively, you can download the toolchain directly from the [https://releases.linaro.org/components/toolchain/binaries/ Linaro toolchain binaries archive]. Anyway, If you're considering downloading the toolchain directly, please still follow the steps 1 and 2.
== Use the script to create the sysroot ==
|info}}


= Create a sysroot =
The script to create the sysroot is located at ''{{#var:BUILD_FOLDER}}/variscite/scripts'':
A sysroot is basically a scaled-downed version of the target file system to be used on the host for cross-compilation of user space applications. Accordingly, to create the sysroot, we would first need the full Debian rootfs. Please refer to {{varlink|Debian Build Release Stage#Setup and build Debian|{{#var:RELEASE_LINK}}|Setup and build Debian}} to learn how to build it.
$ cd {{#var:BUILD_FOLDER}}
$ sudo MACHINE={{#var:MACHINE_NAME}} ./variscite/scripts/make-sysroot.sh


After the rootfs has been built, it should be present at ''{{#var:BUILD_FOLDER}}/rootfs''. From this point, we can start creating the sysroot:
== Manual step-by-step to create the sysroot ==


First, create a temporary copy of the origin rootfs:
First, create a temporary copy of the origin rootfs:
Line 32: Line 39:
Next, we need to convert all absolute links to relative ones. The following approach will use the tools '''chroot''' and '''symlinks'''.<br>
Next, we need to convert all absolute links to relative ones. The following approach will use the tools '''chroot''' and '''symlinks'''.<br>
{{Note|'''Notes:'''
{{Note|'''Notes:'''
* '''chroot''' along with QEMU emulates a target access on the host, please see [https://linux.die.net/man/1/chroot here] for more information
* '''chroot''' along with QEMU emulates a target access on the rootfs, please see [https://linux.die.net/man/1/chroot chroot docs] for more information
* '''symlinks''' can convert absolute paths to relative ones within a file system, please see [https://linux.die.net/man/8/symlinks here] for more information
* '''symlinks''' can convert absolute paths to relative ones within a file system, please see [https://linux.die.net/man/8/symlinks symlinks docs] for more information
}}
}}
Chroot to the rootfs with the following commands:
Chroot to the rootfs with the following commands:
Line 71: Line 78:
  $ cp -ar tmp/rootfs/usr/lib toolchain/sysroot/usr
  $ cp -ar tmp/rootfs/usr/lib toolchain/sysroot/usr
  $ cp -ar tmp/rootfs/usr/include toolchain/sysroot/usr
  $ cp -ar tmp/rootfs/usr/include toolchain/sysroot/usr
{{Note|'''Note:''' This guide covers adding the minimal required folders to the rootfs, you can add more per your needs. Doing it, be aware of keeping the original file tree layout.|info}}
{{Note|'''Note:''' This guide covers adding the minimal required folders to the sysroot, you can add more per your needs. Doing it, be aware of keeping the original file tree layout.|info}}


To clean up, delete the temporary rootfs:
To clean up, delete the temporary rootfs:
Line 77: Line 84:
  $ sudo rm -rf tmp/rootfs  
  $ sudo rm -rf tmp/rootfs  


The Debian sysroot is now located at ''{{#var:BUILD_FOLDER}}/toolchain/sysroot'' and can be used to cross-compile your user space applications on the host. <!--
The Debian sysroot is now located at ''{{#var:BUILD_FOLDER}}/toolchain/sysroot'' and can be used to cross-compile your user space applications on the host.
 
-->{{Note|'''Notes''':
* The Debian build script uses debootstrap to create a minimal Debian {{#var:DEBIAN_NAME}} system and adds the BSP support. Please consider installing extra (dev-)packages to your Debian file system as per your needs.<br>To do this, follow the {{varlink2|Adding Debian packages|{{#var:RELEASE_LINK}}}} guide to learn how to add packages to the rootfs.
* Keeping the sysroot in sync with the rootfs of the target is recommended to avoid misalignments. Whenever a change has been made to the rootfs, please consider creating a new sysroot as described.
}}

Latest revision as of 17:12, 8 June 2023

Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release mx8m-debian-bullseye-5.4-2.1.x-v1.4.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release


Debian toolchain for cross-compilation

Prerequisites

Please follow steps 2 & 4 of the Build Debian from source code guide, to setup a Debian build environment.

Obtain the toolchain

The toolchain can be downloaded by running the following:

$ cd ~/debian_imx8mq-var-dart_debian_bullseye
$ MACHINE=imx8mq-var-dart ./var_make_debian.sh -c deploy

This will download the toolchain gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu (or a newer version), which can be found at ~/debian_imx8mq-var-dart_debian_bullseye/toolchain.

Create a sysroot for user space cross-compilation

A sysroot is basically a scaled-downed version of the target file system to be used on the host for cross-compilation of user space applications.

In the following we will show how to create the sysroot using a script, pre-shipped with the Debian archive, or manually. In any case, we would need a full Debian rootfs first, please refer to Setup and build Debian to learn how to build it. Once the rootfs have been built, it should be present at ~/debian_imx8mq-var-dart_debian_bullseye/rootfs. From this point, follow one of the upcoming sections.

Notes:
  • The Debian build script uses debootstrap to create a minimal Debian Bullseye system and adds the BSP support. Please consider installing extra (dev-)packages to your Debian file system as per your needs.
    To do this, follow the Adding Debian packages guide to learn how to add packages to the rootfs.
  • Keeping the sysroot in sync with the rootfs of the target is recommended to avoid misalignments. Whenever a change has been made to the rootfs, please consider creating a new sysroot as described.

Use the script to create the sysroot

The script to create the sysroot is located at ~/debian_imx8mq-var-dart_debian_bullseye/variscite/scripts:

$ cd ~/debian_imx8mq-var-dart_debian_bullseye
$ sudo MACHINE=imx8m-var-dart ./variscite/scripts/make-sysroot.sh

Manual step-by-step to create the sysroot

First, create a temporary copy of the origin rootfs:

$ cd ~/debian_imx8mq-var-dart_debian_bullseye
$ mkdir -p tmp/rootfs
$ sudo cp -ar rootfs/. tmp/rootfs

Next, we need to convert all absolute links to relative ones. The following approach will use the tools chroot and symlinks.

Notes:
  • chroot along with QEMU emulates a target access on the rootfs, please see chroot docs for more information
  • symlinks can convert absolute paths to relative ones within a file system, please see symlinks docs for more information

Chroot to the rootfs with the following commands:

$ export ROOTFS_BASE=tmp/rootfs
$ sudo cp variscite/qemu_64bit/qemu-aarch64-static ${ROOTFS_BASE}/usr/bin/qemu-aarch64-static
$ sudo mount -o bind /proc ${ROOTFS_BASE}/proc
$ sudo mount -o bind /dev ${ROOTFS_BASE}/dev
$ sudo mount -o bind /sys ${ROOTFS_BASE}/sys
$ sudo mount -o bind /dev/pts ${ROOTFS_BASE}/dev/pts
$ sudo chroot $ROOTFS_BASE

Once entered, we can now install symlinks and convert the links:

# apt-get install -y symlinks
# symlinks -cr /

and exit:

# exit

Then we need to clean up the mounts (previously needed to chroot):

$ sudo umount ${ROOTFS_BASE}/dev/pts
$ sudo umount ${ROOTFS_BASE}/sys
$ sudo umount ${ROOTFS_BASE}/dev
$ sudo umount ${ROOTFS_BASE}/proc

Finally, create the sysroot target folder:

$ mkdir -p toolchain/sysroot
$ mkdir -p toolchain/sysroot/usr

And copy a minimal required set of the modified origin rootfs to it.
The minimal required set includes:

  • /lib: Libraries for programming and packages
  • /usr/lib: Libraries for programming and packages
  • /usr/include: Directory for standard include files
$ cp -ar tmp/rootfs/lib toolchain/sysroot/
$ cp -ar tmp/rootfs/usr/lib toolchain/sysroot/usr
$ cp -ar tmp/rootfs/usr/include toolchain/sysroot/usr
Note: This guide covers adding the minimal required folders to the sysroot, you can add more per your needs. Doing it, be aware of keeping the original file tree layout.

To clean up, delete the temporary rootfs:

$ sudo rm -rf tmp/rootfs 

The Debian sysroot is now located at ~/debian_imx8mq-var-dart_debian_bullseye/toolchain/sysroot and can be used to cross-compile your user space applications on the host.