The toolchain as it is distributed today is unable to build kernel modules. It is necessary to run make scripts in the kernel headers directory. I’m not sure why this issue hasn’t been fixed yet since it was discovered a long time ago. The workaround to fix the toolchain is described in the legato documentation for out of tree kernel modules. I will save you some reading and reproduce the instructions here:
# Put the arm toolchain in your PATH environment variable
export PATH=$PATH:/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi
# Change directory into the kernel headers directory distributed with the toolchain
cd /opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/src/kernel
# Change the ownership of everything in the folder so that we can update the contents
sudo chown -R $USER .
# Run make scripts with appropriate cross compilation flags
ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- make scripts
# Change the ownership of the kernel headers back to root
sudo chown -R root .