How To Cross Compile Linux Kernel For Beagle Bone Black From PC With Debian.
1. Clone The Kernel Source from GitHub
If you don”t have the toolchain installed see the Cross Compile Application For Beagle Bone Black
The official BBB kernel releases can be found on the BeagleBoard github repo .
Clone the repository from the Debian terminal:
$ git clone git://github.com/beagleboard/linux.git
Once complete change to the newly checked out directory.
$ cd linux/
In the example of cross compiling a kernel, we use the same kernel version which is running on Beagle Bone Black board.
To find the kernel version running on the BeagleBone type the following command at BeagleBone terminal:
debian@beaglebone:~$ uname -a
Linux beaglebone 4.19.94-ti-r42 #1buster SMP PREEMPT Tue Mar 31 19:38:29 UTC 2020 armv7l GNU/Linux
So the running BBB kernel version on the board is 4.19.94-ti-r42.
On the Debian terminal type the following command to check out the correct kernel version
$ git checkout 4.19.94-ti-r42
2. Build The Kernel
To use the default configuration from the sources type the following command at the Debian terminal.
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-bb.org_defconfig
This command copies the Beagle Bone kernel configuration to kernel sources configuration (the file .config )
If you want to change the default configuration use the command:
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
This command opens standard Kernel Configurator.
To compile the kernel execute the following command:
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LOADADDR=0x80000000 uImage dtbs
If the following error is displayed during compilation:
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:99: scripts/dtc/dtc] Error 1
make[1]: *** [scripts/Makefile.build:544: scripts/dtc] Error 2
make: *** [Makefile:1067: scripts] Error 2
edit the file ./linux-rtk/scripts/dtc/dtc-lexer-lex.c
Find the line ‘YYLTYPE yylloc’ and change it to ‘extern YYLTYPE yylloc’
If the following error is displayed during compilation:
"mkimage" command not found - U-Boot images will not be built
make[1]: *** [arch/arm/boot/Makefile:95: arch/arm/boot/uImage] Error 1
make: *** [arch/arm/Makefile:336: uImage] Error 2
install the U-BOOT tools:
$ sudo apt-get install u-boot-tools
When the kernel build is finished without errors build the modules
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules
3. Download New Kernel To The BBB SD Card
Mount the SD card with BBB Debian system to the Debian PC (for example to /mnt/bbb).
Copy the image:
$ sudo cp zImage /mnt/bbb/boot/vmlinuz-4.19.94-ti-r42
Install modules to the BBB SD card:
$ sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=/mnt/bbb modules_install
Insert the SD card to BBB board, start the system and type the command in BBB terminal.
debian@beaglebone:~$ uname -a
Linux beaglebone 4.19.94 #1 SMP PREEMPT Mon Dec 5 21:14:50 CET 2022 armv7l GNU/Linux
You should see the new kernel build date.