Debian Toolchain installation: Difference between revisions

From Variscite Wiki
(Build the sysroot: rephrase)
(Create sysroot: further work)
Line 19: Line 19:
|info}}
|info}}


= Build the sysroot =
= Create the sysroot =
We will need the Debian rootfs to create the sysroot (for cross-compilation), please follow the steps of the section {{varlink|Debian Build Release Stage#Setup and build Debian|{{#var:RELEASE_LINK}}|Setup and build Debian}}.
To create the Debian sysroot, we need the 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.


Assuming, the Debian rootfs is present at '''{{#var:BUILD_FOLDER}}/rootfs''', we can proceed with creating the sysroot.
After the rootfs has been built, it should be present at ''{{#var:BUILD_FOLDER}}/rootfs''. From this point, we can start creating the sysroot:


First, create a copy of the origin rootfs:
First, create a temporary copy of the origin rootfs:


  $ cd {{#var:BUILD_FOLDER}}
  $ cd {{#var:BUILD_FOLDER}}
  $ mkdir -p tmp/sysroot
  $ mkdir -p tmp/rootfs
  $ cp -avr rootfs/. tmp/rootfs
  $ sudo cp -ar rootfs/. tmp/rootfs


Next, we need to convert absolute links to relative ones by using chroot and the tool sysmlinks:
Next, we need to convert all absolute links to relative ones. The following approach will use the tools '''chroot''' and '''symlinks'''.


Chroot to the rootfs with the following commands:
  $ export ROOTFS_BASE=tmp/rootfs
  $ export ROOTFS_BASE=tmp/rootfs
  $ sudo cp variscite/qemu_64bit/qemu-aarch64-static ${ROOTFS_BASE}/usr/bin/qemu-aarch64-static
  $ sudo cp variscite/qemu_64bit/qemu-aarch64-static ${ROOTFS_BASE}/usr/bin/qemu-aarch64-static
Line 39: Line 40:
  $ sudo mount -o bind /dev/pts ${ROOTFS_BASE}/dev/pts
  $ sudo mount -o bind /dev/pts ${ROOTFS_BASE}/dev/pts
  $ sudo chroot $ROOTFS_BASE
  $ sudo chroot $ROOTFS_BASE
  # apt-get install -y sysmlinks
 
  # symlinks -cr .
Once entered, we can now install '''symlinks''' and convert the links:
  # apt-get install -y symlinks
  # symlinks -cr /
 
and exit:
  # exit
  # exit
Then we need to clean up the mounts:
  $ sudo umount ${ROOTFS_BASE}/dev/pts
  $ sudo umount ${ROOTFS_BASE}/dev/pts
  $ sudo umount ${ROOTFS_BASE}/sys
  $ sudo umount ${ROOTFS_BASE}/sys
Line 47: Line 54:
  $ sudo umount ${ROOTFS_BASE}/proc
  $ sudo umount ${ROOTFS_BASE}/proc


This will make it possible, to use the file system on the host for cross-compilation.<br>
Finally, we can create the syroot, copying a minimal set of the modified rootfs:
Finally, we will create the syroot with a minimal set of the modified (relative links) rootfs:


  $ mkdir -p toolchain/sysroot/
  $ mkdir -p toolchain/sysroot
  $ cp tmp/rootfs/lib toolchain/sysroot/
$ mkdir -p toolchain/sysroot/usr
  $ cp tmp/rootfs/usr/lib toolchain/sysroot/
  $ cp -ar tmp/rootfs/lib toolchain/sysroot/
  $ cp tmp/rootfs/usr/include toolchain/sysroot/
  $ cp -ar tmp/rootfs/usr/lib toolchain/sysroot/usr
  $ cp -ar tmp/rootfs/usr/include toolchain/sysroot/usr


And delete the temporary rootfs:
And delete the temporary rootfs:


  $ rm -rf tmp/sysroot <!--
  $ sudo rm -rf tmp/rootfs
 
The Debian sysroot is now located at ''{{#var:BUILD_FOLDER}}/toolchain/sysroot'' and can be used to cross-compile user space programs on the host. <!--


-->{{Note|'''Notes''':
-->{{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 so, follow the {{varlink2|Adding Debian packages|{{#var:RELEASE_LINK}}}} guide to learn how to add packages to the rootfs.
* 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 host-side's located Debian rootfs in sync with the target one is recommended to avoid issues. Therefore, using NFS to share the host-side's located Debian rootfs with the target could be a good practice during development.<br>Please refer to the {{Varlink2|Debian Setup TFTP/NFS|{{#var:RELASE_LINK}}}} guide for more information on how to setup a TFTP/NFS configuration.
* Keeping the sysroot in sync with the rootfs of the target is recommended to avoid issues. Whenever a change has been made to the rootfs, please consider creating a new sysroot as described.
}}
}}

Revision as of 16:27, 28 April 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 installation for out of Debian builds

Installing the toolchain

To install the toolchain, please go through the following steps of the Debian Build Release guide:

  1. Setup Development Environment
  2. Installing required packages
  3. Download Debian archive
  4. 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.

The GNU Linux toolchain gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu can be found at ~/debian_imx8mq-var-dart_debian_bullseye/toolchain.

Note: Alternatively, you can download the toolchain directly from the Linaro toolchain binaries archive. Anyway, If you're considering downloading the toolchain directly, please still follow steps 1 and 2.

Create the sysroot

To create the Debian sysroot, we need the Debian rootfs, please refer to Setup and build Debian to learn how to build it.

After the rootfs has been built, it should be present at ~/debian_imx8mq-var-dart_debian_bullseye/rootfs. From this point, we can start creating 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.

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:

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

Finally, we can create the syroot, copying a minimal set of the modified rootfs:

$ mkdir -p toolchain/sysroot
$ mkdir -p toolchain/sysroot/usr
$ 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

And 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 user space programs on the host.

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 issues. Whenever a change has been made to the rootfs, please consider creating a new sysroot as described.