| | 95 | |
| | 96 | [=#kernel] |
| | 97 | ==== Modifying the stand-alone Linux Kernel |
| | 98 | The Gateworks Catalina BSP instructions [#build above] create an environment for building the Linux kernel among other targets. |
| | 99 | |
| | 100 | You can modify the default Gateworks kernel config as well as build it manually: |
| | 101 | * Modify kernel menuconfig: |
| | 102 | {{{#!bash |
| | 103 | make linux-menuconfig |
| | 104 | }}} |
| | 105 | * Make kernel by hand |
| | 106 | {{{#!bash |
| | 107 | source ./setup-environment |
| | 108 | cd linux |
| | 109 | make menuconfig |
| | 110 | make savedefconfig |
| | 111 | diff defconfig ../configs/imx95_catalina_linux-6.18_defconfig # show changes |
| | 112 | cp defconfig ../configs/imx95_catalina_linux-6.18_defconfig # copy changes (if desired) |
| | 113 | }}} |
| | 114 | |
| | 115 | [=#toolchain] |
| | 116 | == ARM64 Toolchain |
| | 117 | The buildroot based ARM64 toolchain is used can be used by sourcing the [https://github.com/Gateworks/bsp-catalina/blob/master/setup-environment setup-environment] file which adds to your PATH and sets the CROSS_COMPILE variables: |
| | 118 | {{{#!bash |
| | 119 | source ./setup-environment |
| | 120 | }}} |
| | 121 | |
| | 122 | Note this is not necessary to do if you are using the Makefile as it specifies the necessary ARCH and CROSS_COMPILE vars where needed. |
| | 123 | |
| | 124 | === Buildroot based toolchain |
| | 125 | The Catalina BSP uses buildroot to build the ARM64 toolchain used to build everything that runs on the A55 cores: ATF, kernel and bootloader firmware. |
| | 126 | |
| | 127 | The buidlroot config is [https://github.com/Gateworks/bsp-catalina/blob/main/configs/buildroot_arm64_toolchain_defconfig configs/buildroot_arm64_toolchain_defconfig]. |
| | 128 | |
| | 129 | The bsp [https://github.com/Gateworks/bsp-catalina/blob/main/Makefile Makefile] has an 'arm64-toolchain' target which is built as a pre-requisite for building code running on the A55 cores. |
| | 130 | |
| | 131 | The toolchain is built using buildroot 2026.02 with the following details (which are all defaults for this version of buildroot): |
| | 132 | - Linux 6.18 kernel headers |
| | 133 | - glib libc |
| | 134 | - binutils 2.44 |
| | 135 | - gcc 13.4 |
| | 136 | - C++ support (default is to disable this; we enable it) |
| | 137 | |
| | 138 | 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: |
| | 139 | {{{#!bash |
| | 140 | make arm64-toolchain-menuconfig # select changes |
| | 141 | make clean-toolchain |
| | 142 | make |
| | 143 | }}} |
| | 144 | * make sure you clean and rebuild when changing toolchain options |
| | 145 | |
| | 146 | === External toolchain |
| | 147 | The Catalina BSP uses buildroot to build the toolchain used to build the kernel and bootloader firmware. |
| | 148 | |
| | 149 | While the BSP makefile will always build the buildroot ARM64 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 and adjusting the PATH and CROSS_COMPILE statements int he Makefile. |
| | 150 | |
| | 151 | |
| | 152 | === Cross compile examples |
| | 153 | |
| | 154 | Examples of cross-compiling on your development host using the ARM64 buildroot toolchain |
| | 155 | * ANSI-C hello world: |
| | 156 | {{{#!bash |
| | 157 | cat << EOF > helloworld.c |
| | 158 | #include <stdio.h> |
| | 159 | #include <stdlib.h> |
| | 160 | |
| | 161 | int main(int argc, char **argv) |
| | 162 | { |
| | 163 | printf("hello world!\n"); |
| | 164 | |
| | 165 | return 0; |
| | 166 | } |
| | 167 | EOF |
| | 168 | . ./setup-environment # setup environment for buildroot toolchain |
| | 169 | ${CROSS_COMPILE}gcc helloworld.c --static -o helloworld |
| | 170 | }}} |
| | 171 | - Note that if you want to use shared libraries you would either need to copy the toolchains libc (buildroot/output/target/lib/) to the target so that the interpreter and shared libs are present or you can use Ubuntu's cross-toolchain instead (see [wiki:/ubuntu#hello-world.c ubuntu/cross-compile]) |
| | 172 | * C++ hello world: |
| | 173 | {{{#!bash |
| | 174 | cat << EOF > helloworld.cpp |
| | 175 | #include <iostream> |
| | 176 | |
| | 177 | using namespace std; |
| | 178 | |
| | 179 | int main() { |
| | 180 | cout << "Hello World!"; |
| | 181 | return 0; |
| | 182 | } |
| | 183 | EOF |
| | 184 | . ./setup-environment # setup environment for buildroot toolchain |
| | 185 | ${CROSS_COMPILE}gcc helloworld.cpp --static -lstdc++ -o helloworld |
| | 186 | }}} |
| | 187 | - Note that if you want to use shared libraries you would either need to copy the toolchains libc (buildroot/output/target/lib/) to the target so that the interpreter and shared libs are present or you can use Ubuntu's cross-toolchain instead (see [wiki:/ubuntu#hello-world.c ubuntu/cross-compile]) |
| | 188 | * kernel module: |
| | 189 | {{{#!bash |
| | 190 | . ./setup-environment # setup environment for buildroot toolchain |
| | 191 | make kernel_image # first build the kernel |
| | 192 | make -C linux M=$PWD/my-module modules |
| | 193 | }}} |
| | 194 | - 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) |
| | 195 | |
| | 196 | |
| | 197 | [=#target-compile] |
| | 198 | == Building applications on the Catalina Target |
| | 199 | |
| | 200 | === Out-of-Tree Kernel Modules on Target |
| | 201 | Gateworks Catalina BSP now creates images that have built in support for building external or out-of-tree kernel modules on a target board, allowing users to extend the functionality of the kernel with custom or third-party modules. Below are some examples demonstrating how to build and install external modules on a one of our Catalina boards: |
| | 202 | |
| | 203 | Before building any external kernel modules, it's essential to ensure your system has necessary dependencies installed. We recommend starting with an update of package lists followed by the installation of essential tools. Run the following commands: |
| | 204 | {{{#!bash |
| | 205 | apt update |
| | 206 | apt install -y build-essential git bc file flex bison |
| | 207 | }}} |
| | 208 | |
| | 209 | Examples: |
| | 210 | 1. cryptodev-linux (a properly defined Makefile) |
| | 211 | {{{#!bash |
| | 212 | git clone http://github.com/cryptodev-linux/cryptodev-linux |
| | 213 | cd cryptodev-linux |
| | 214 | make && make modules_install |
| | 215 | modprobe cryptodev |
| | 216 | }}} |
| | 217 | 1. something with an improper or problematic Makefile but with a single C file for example uiodma.c |
| | 218 | {{{#!bash |
| | 219 | git clone https://github.com/nxp-imx-support/uiodma-driver.git |
| | 220 | cd uiodma-driver/uiodma |
| | 221 | # build module |
| | 222 | make -C /lib/modules/$(uname -r)/build M=$PWD obj-m=uiodma.o modules |
| | 223 | # install module |
| | 224 | make -C /lib/modules/$(uname -r)/build M=$PWD obj-m=uiodma.o modules_install |
| | 225 | }}} |
| | 226 | - The kernel build system will still look for a file named Makefile or Kbuild in your directory. If the existing files are so broken that it can't even parse them you will need to rename/remove them |
| | 227 | - If you need to pass flags to the compiler define them as 'KCFLAGS' - ie 'KCFLAGS="-Wno-missing-prototypes -Wno-missing-declarations" |
| | 228 | |
| | 229 | These examples illustrate the process of building and installing external kernel modules. Users can adapt these instructions for other modules as needed, ensuring that dependencies are met and the module is properly installed and loaded into the kernel. |
| | 230 | |
| | 231 | |