First of all, we need a cross compiler.
Please see http://www.welzels.de/blog/en/arm-cross-compiling-with-mac-os-x/ for the cross compilation toolchain installation. ( Thanks to KNut Welzels )
A fews things will also be usefull, so we install:
brew install wget brew install ncurses brew tap homebrew/dupes brew install grep sudo port install findutils
Elf.h is somewhat missing on OSX, so we need it.
sudo curl http://www.opensource.apple.com/source/dtrace/dtrace-78/sys/elftypes.h?txt -o /usr/include/elftypes.h sudo curl http://www.opensource.apple.com/source/dtrace/dtrace-78/sys/elf.h?txt -o /usr/include/elf.h
Edit elf.h and add those lines:
Please see at the end of the post for a patch file.
#define R_386_NONE 0 #define R_386_32 1 #define R_386_PC32 2 #define R_ARM_NONE 0 #define R_ARM_PC24 1 #define R_ARM_ABS32 2 #define R_MIPS_NONE 0 #define R_MIPS_16 1 #define R_MIPS_32 2 #define R_MIPS_REL32 3 #define R_MIPS_26 4 #define R_MIPS_HI16 5 #define R_MIPS_LO16 6
We now have all the tools to compile a Kernel.
In order to avoid some git trouble, we need a case sensitive file system. If your system is not on that type of file system, you need to build and mount a drive image.
Open the disk utility -> new image.
Choose where you want the image to be placed, name it, select 4.6Gigs size, format MUST be case sensitive.
Click on create.
Disk image is mounted on /Volumes/ with the name you choose earlier.
In the terminal, navigate to your mounted image.
cd /Volumes/bb-kernel-3.14
Next, it’s time to clone the kernel repo.
git clone https://github.com/RobertCNelson/bb-kernel.git cd bb-kernel/ git checkout origin/am33x-v3.14 -b tmp
We need to tweak and change a few things.
First is the cross compiler.
cp system.sh.sample system.sh nano system.sh
You must insert the path to your compiler, ie for me it’s:
###REQUIRED: #ARM GCC CROSS Compiler: #if CC is not set, a known working linaro based gcc compiler will be downloaded and utilized. #CC=/bin/arm-none-eabi- #CC=/bin/arm-linux-gnueabi- #CC=/bin/arm-linux-gnueabihf- CC=/usr/local/linaro/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
Second thing is to modify the Robert’s scripts to include the OSx recognition.
To do so, edit nano build_kernel.sh and nano tools/rebuild.sh to replace menu_config function or apply the patch at the end of the post.
make_menuconfig () { cd ${DIR}/KERNEL/ if [ `uname -s` == "Darwin" ]; then make ARCH=arm CROSS_COMPILE="${CC}" nconfig else make ARCH=arm CROSS_COMPILE="${CC}" menuconfig fi cp -v .config ${DIR}/patches/defconfig cd ${DIR}/ }
Time to build !
./build_kernel.sh
You will need to disable raid6 drivers, no way to build under OSX and who needs raid6 drivers on a BBB anyway 😉
In the config menu, go to drivers, and disable raid drivers.
Everything should compile fine and you’ll see after a few minutes
Script Complete eewiki.net: [user@localhost:~$ export kernel_version=3.14.17-bone8]
Time to build sgx libraries !
First we need the Ti SDK, and the only way to have it on OSX is to copy it from linux, because the .bin won’t execute.
So copy SDK_BIN dir to ignore/.
We have some trouble with xargs on osx that won’t let you do a xargs -r.
No trouble, you already installed findutils, so you have gxargs
edit KERNEL/scripts/Makefile.modpost and change
Please see at the end of the post for a patch file.
MODLISTCMD := find $(MODVERDIR) -name '*.mod' | xargs -r grep -h '\.ko$$' | sort -u
to
MODLISTCMD := find $(MODVERDIR) -name '*.mod' | /opt/local/bin/gxargs -r grep -h '\.ko$$' | sort -u
Then launch ./sgx_build_modules.sh.
Modules should build fine.
Next, kernel needs to be compiled again using tools/rebuild.sh
Everything went well, you should have
----------------------------- Script Complete eewiki.net: [user@localhost:~$ export kernel_version=3.14.17-bone8] -----------------------------
There’s still a little glitch, depmod is not on OSX. The modules’ tar will not contains anything but the modules themselves. Looks like you’ll have to run a depmod -a on the beaglebone before being able to load any module.
I need to add a few things to this recipe to be complete because some parts where failing when I followed it.
I’ll add them soon.
For now you can download this kernel patch to be launched against KERNEL directory and this elf.h for osx file to be copied into KERNEL/scripts/ directory.
This patch enables UIO_pruss driver in Kernel menuconfig and make raid6 compilation available.
But you still have to disable apparmor in the kernl config.
Thanks to Robert C Nelson for the repo and advices.
This article was written by Cédric
2 comments:
Hi Cédric,
nice tutorial, but I run into an error:
In file included from scripts/kconfig/nconf.gui.c:8:
scripts/kconfig/nconf.h:18:10: fatal error: ‘curses.h’ file not found
#include
Did you have installed the ncurses libraries and header files from brew?
And why did you have installed findutils from port and not from brew? Are they differ?
Thanks Knut
Hi Knut,
Yes I installed ncurses from brew because I wanted to see if I could get menuconfig working, but I abandoned and went the nconfig route.
You can get findutils from brew or from port, I do not think they differ, they’re both gnu ports.
Thanks for the report, I’ll modify the post to include ncurses libs.