| | 118 | |
| | 119 | |
| | 120 | [=#toolchain] |
| | 121 | == Toolchain |
| | 122 | |
| | 123 | === Buildroot based toolchain |
| | 124 | The Venice BSP uses buildroot to build the toolchain used to build the kernel and bootloader firmware. |
| | 125 | |
| | 126 | The buidlroot config is [https://github.com/Gateworks/bsp-venice/blob/master/buildroot-imx8mm_venice_defconfig venice/buildroot-imx8mm_venice_defconfig] which is copied to buildroot/configs/imx8mm_venice_defconfig. |
| | 127 | |
| | 128 | The bsp [https://github.com/Gateworks/bsp-venice/blob/master/Makefile Makefile] has a 'toolchain' target which is built as a pre-requisite for building the bootloader and kernel. |
| | 129 | |
| | 130 | The buildroot version is 2020.05.3 and builds a toolchain with the following details (which are all defaults for buildroot): |
| | 131 | - Linux 5.6.x kernel headers |
| | 132 | - uClibc libc |
| | 133 | - binutils 2.32 |
| | 134 | - gcc 8.x |
| | 135 | - C++ support (default is to disable this; we enable it) |
| | 136 | |
| | 137 | The specific details can be shown by running 'gcc -v' for example: |
| | 138 | {{{#!bash |
| | 139 | user@host:/usr/src/venice/bsp$ . ./setup-environment # configure PATH and CROSS_COMPILER env vars |
| | 140 | user@host:/usr/src/venice/bsp$ ${CROSS_COMPILE}gcc -v |
| | 141 | Using built-in specs. |
| | 142 | COLLECT_GCC=/usr/src/venice/bsp/buildroot/output/host/bin/aarch64-linux-gcc.br_real |
| | 143 | COLLECT_LTO_WRAPPER=/usr/src/venice/bsp/buildroot/output/host/libexec/gcc/aarch64-buildroot-linux-uclibc/8.4.0/lto-wrapper |
| | 144 | Target: aarch64-buildroot-linux-uclibc |
| | 145 | Configured with: ./configure --prefix=/usr/src/venice/bsp/buildroot/output/host --sysconfdir=/usr/src/venice/bsp/buildroot/output/host/etc --enable-static --target=aarch64-buildroot-linux-uclibc --with-sysroot=/usr/src/venice/bsp/buildroot/output/host/aarch64-buildroot-linux-uclibc/sysroot --enable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --disable-decimal-float --with-gmp=/usr/src/venice/bsp/buildroot/output/host --with-mpc=/usr/src/venice/bsp/buildroot/output/host --with-mpfr=/usr/src/venice/bsp/buildroot/output/host --with-pkgversion='Buildroot 2020.05.3' --with-bugurl=http://bugs.buildroot.net/ --disable-libquadmath --disable-libsanitizer --enable-tls --enable-threads --without-isl --without-cloog --with-abi=lp64 --with-cpu=cortex-a53 --enable-languages=c,c++ --with-build-time-tools=/usr/src/venice/bsp/buildroot/output/host/aarch64-buildroot-linux-uclibc/bin --enable-shared --disable-libgomp |
| | 146 | Thread model: posix |
| | 147 | gcc version 8.4.0 (Buildroot 2020.05.3) |
| | 148 | }}} |
| | 149 | |
| | 150 | |
| | 151 | Note there are other options you may want to change for your needs such as using a different libc, different compiler version, or enable WCHAR support or additional threading support. To do so you can: |
| | 152 | {{{#!bash |
| | 153 | cd buildroot |
| | 154 | make menuconfig # select options desired under Toolchain |
| | 155 | make clean |
| | 156 | make |
| | 157 | }}} |
| | 158 | * make sure you clean and rebuild when changing toolchain options |
| | 159 | |
| | 160 | The buildroot based toolchain is used by virtue of sourcing the [https://github.com/Gateworks/bsp-venice/blob/master/setup-environment setup-environment] file which adds to your PATH and sets the CROSS_COMPILE variable. |
| | 161 | |
| | 162 | === External toolchain |
| | 163 | The Venice BSP uses buildroot to build the toolchain used to build the kernel and bootloader firmware. |
| | 164 | |
| | 165 | While the BSP makefile will always build the buildroot toolchain (unless you comment that out in the Makefile) you can easily use a toolchain of your liking by modifying the environment like 'setup-environment' does. Simply make sure to set CROSS_COMPILE to the prefix of your toolchains 'gcc' compiler and other tools, and make sure your external toolchain shows up first in your PATH. |
| | 166 | |
| | 167 | |
| | 168 | === Cross compile examples |
| | 169 | |
| | 170 | Examples of cross-compiling: |
| | 171 | * ANSI-C hello world: |
| | 172 | {{{#!bash |
| | 173 | cat << EOF > helloworld.c |
| | 174 | #include <stdio.h> |
| | 175 | #include <stdlib.h> |
| | 176 | |
| | 177 | int main(int argc, char **argv) |
| | 178 | { |
| | 179 | printf("hello world!\n"); |
| | 180 | |
| | 181 | return 0; |
| | 182 | } |
| | 183 | EOF |
| | 184 | . ./setup-environment # setup environment for buildroot toolchain |
| | 185 | ${CROSS_COMPILE}gcc helloworld.c -o helloworld |
| | 186 | }}} |
| | 187 | * C++ hello world: |
| | 188 | {{{#!bash |
| | 189 | cat << EOF > helloworld.cpp |
| | 190 | #include <iostream> |
| | 191 | |
| | 192 | using namespace std; |
| | 193 | |
| | 194 | int main() { |
| | 195 | cout << "Hello World!"; |
| | 196 | return 0; |
| | 197 | } |
| | 198 | EOF |
| | 199 | . ./setup-environment # setup environment for buildroot toolchain |
| | 200 | ${CROSS_COMPILE}gcc helloworld.cpp -lstdc++ -o helloworld |
| | 201 | }}} |
| | 202 | * kernel module: |
| | 203 | {{{#!bash |
| | 204 | . ./setup-environment # setup environment for buildroot toolchain |
| | 205 | make kernel_image # first build the kernel |
| | 206 | make -C linux M=$PWD/my-module modules |
| | 207 | }}} |
| | 208 | - Note that some out-of-tree kernel modules do not follow the suggested Makefile standards and may need to be modified to use the CROSS_COMPILE prefix and/or specify the kernel directory (as opposed to the above example where you do a make in the linux dir and set M to the path of your module) |
| | 209 | |
| | 210 | |