[Edit – 12/20/15] – This guide is now out of date. A new walkthrough showing how to build a custom Linux image with the Yocto Project and Edison source code (release 2.1) can be found here.
If you want to add custom options to the Edison Linux kernel, you will need to compile it from source and enable the options you want. This tutorial is based on Intel’s Edison BSP User Guide, VijayNooki‘s post in the Intel Forum, and hammock‘s post in the Intel Forum.
You will need to perform these steps on a Linux host machine with apt-get installed (e.g. Ubuntu).
[Edit – 05/07/15] Note that this will take a lot of hard drive space. Yocto recommends having at least 50 GB free. Thanks for pointing this out, wojak!
Download Image and Install Tools
First, download the latest Edison Yocto source code from here. Navigate to “Intel Edison OS Image and source files” and the file will be labeled something like “edison-src-rel1-maint-rel1-ww42-14.tgz.”
Install some tools:
sudo apt-get install build-essential git diffstat gawk chrpath texinfo libtool gcc-multilib
[Edit – 02/05/15] If this is the first time you have installed git, you will want to configure it (where “you@example.com” and “Your Name” are your email and name. Ideally, these would be the email and name you used for something like GitHub):
git config –-global user.email “you@example.com” git config –-global user.name “Your Name”
[Edit – 02/05/15] You will also need libtool, if your version of Linux does not have it already installed (thanks, Scott Emery for these 2 tips!):
sudo apt-get install libtool
Perform Initial Build
Naviage to your Downloads directory (or wherever you downloaded the Edison source zip file):
cd Downloads
Unzip and navigate to the Edison source directory:
tar xvf edison-src.tgz cd edison-src/
Run the setup script:
./device-software/setup.sh
Load the shell script in the poky/ directory to configure our build environment:
source poky/oe-init-build-env
You will automatically be placed in the edison/source directory. From there, run bitbake to create an initial Edison image:
bitbake edison-image
This will take some time (potentially hours), as it needs to compile the whole kernel. Subsequent builds will go much faster.
Configure and Create New Kernel
Once the initial build is complete, open up menuconfig:
bitbake linux-yocto –c menuconfig
From here, you can select the options that you want your new kernel to have. Save and exit menuconfig. Copy the config file to the Edison build directory:
cp edison-src/build/tmp/work/edison-poky-linux/linux-yocto/3.10.17+gitAUTO*/linux-edison-standard-build/.config edison-src/device-software/meta-edison/recipes-kernel/linux/files/defconfig
You can open up the new defconfig file if you want to verify your kernel features. After that, run bitbake again to create the new image:
bitbake edison-image
Finally, run the post-build script to generate the toFlash/ directory:
cd ../device-software/utils/flash ./postBuild.sh
Navigate to the toFlash/directory:
cd ../../../build/toFlash
Flash Your Edison
If you want to flash your Edison with a new image, you can plug it into the USB port(s) and run:
./flashall.sh
This will flash your Edison with your new image! If you want to keep your user data, run the command with the keep-data option:
./flashall.sh --keep-data
Or Modify Your Edison’s Kernel
However, if you want to try and loading in new kernel modules in your existing Edison image, you will need to mount the newly created Edison image on your host machine, extract the modules, and send them to your Edison. This might be risky. I make no promises.
The cool thing about this method is that you can add modules to other versions of Linux for the Edison, like Debian and its unofficial Edison image, Ubilinux.
Plug in your Edison, configure it on your network, and find it’s IP address. You will need it to copy files using scp.
Mount the image file:
sudo mount edison-image-edison.hddimg /mnt
Copy the 4 files found within to your Edison’s /boot directory (where XXX.XXX.XXX.XXX is your Edison’s IP address, e.g. 192.168.1.5):
scp /mnt/* root@XXX.XXX.XXX.XXX:/boot/
Unmount the Edison image:
sudo umount /mnt
SSH into your Edison:
ssh root@XXX.XXX.XXX.XXX
Remove the old Edison kernel modules and exit SSH:
rm -rf /lib/modules/3.10.17-poky-edison-ww42+ exit
Copy the new modules over to the Edison:
sudo mount edison-image-edison.ext4 /mnt scp -r /mnt/lib/modules/* root@XXX.XXX.XXX.XXX:/lib/modules/
SSH into your Edison to reboot it:
ssh root@XXX.XXX.XXX.XXX reboot
This will kick you out of SSH. Wait a few minutes and then SSH back in:
ssh root@XXX.XXX.XXX.XXX
Once logged in to your Edison, you can use modprobe to enable your new module:
modprobe <MODULE_NAME>
And that’s it! You can check that the module got loaded with:
ls /sys/module/ | grep <MODULE_NAME>
You might notice that you need to run modprobe every time you boot. To perform this step automatically, we can create a configure script that gets run at boot. Make sure you are still logged into your Edison and make a file in /etc/modprobe.d/
sudo nano /etc/modprobe.d/<MODULE_NAME>.conf
In that file, on a single line at the top, enter the command:
modprobe <MODULE_NAME>
Save and exit (‘Ctrl-x’ and ‘y’ in nano). Reboot, and your module should be automatically loaded!
Excellent step-by-step instructions on how to build your own Edison image. I started with a fresh Xubuntu install and ran into two errors which you might consider adding to your list of steps. Firstly, while performing the do_patch step of the linux-yocto/3.10.17+gitAUTOINC+6ad20f049a_c03195ed6e-r0 target it requires that your email and name be configured in git. So, after intalling git, users should run:
And secondly, the zeromq target requires the libtool package, so you might want to add libtool to the list of packages to install.
Thanks! I’ll add those to the tutorial.
I forgot to ask – were you able to get any sort of GUI running on the Edison from Xubuntu? I’ve been looking at ways to do this (e.g. using an LCD over SPI).
Your CSS or whatnot breaks code examples, all ‘minus’ symbols are converted to dashes, and therefore if you are using an UTF-8 terminal, you get errors from copy & paste.
e.g.
$ bitbake linux-yocto –c menuconfig
WARNING: Host distribution "Debian-7.8" has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.
Loading cache: 100% |##############################################################################################################################################################################| ETA: 00:00:00
Loaded 1288 entries from dependency cache.
ERROR: Nothing PROVIDES '–c'
or:
$ git config –global user.email “you@example.com”
error: key does not contain a section: –global
Thanks for catching these. I didn’t have any issues copying-and-pasting from the code snippets, so there might be something wrong with my code plugin. I’ll take a look at it. The -global option needs to be –global, so I fixed that one.
There is a missing ‘-‘ sign in one of the paths, the correct command is
cp edison-src/build/tmp/work/edison-poky-linux/linux-yocto/3.10.17+gitAUTO*/linux-edison-standard-build/.config edison-src/device-software/meta-edison/recipes-kernel/linux/files/defconfig
Fixed. Thanks!
Would be good to mention that it will eat a lot of HDD space, 20GB was not enough for me.
Thanks for catching this! I made a note at the beginning of the tutorial.
Thanks for this! It is very helpful. I was wondering, has anybody been successful at compiling and loading a 64bit kernel?
Glad it helped! I haven’t seen a 64-bit kernel yet, but this might be helpful: https://communities.intel.com/thread/57334?tstart=0
Hi,
I want to try and patch the edison kernel with realtime preemtion, but I’m not to sure at what point I should apply the patch. My assumption would be to apply the patch right after unpacking the edison source. Or is there a special way patches are handled with the edison kernel?
Thanks in advance.
Sorry I didn’t see this until now! Gmail started marking my WordPress notifications as spam for some reason.
It has been a very long time since I’ve played with a real time kernel, so I honestly don’t know how a real time kernel would be made for the Edison. My guess would that you would need to create a special kernel from Yocto, but I could be way off. I recommend checking here and here for a start.
[…] https://shawnhymel.com/585/creating-a-custom-linux-kernel-for-the-edison/ […]
I am stuck at this step “source poky/oe-init-build-env”. There is no poky directory in the source. There is only “meta-edison-intel” folder. How shall I solve this?
It very well could be. It has been many months since I have played with Yocto, and they could have changed the build process. Does running the command
source poky/oe-init-build-env
fail?I took the older kernel src and it went fine till I reached the config file. I do not know where the config file is saved and from do I copy it. Also it would be great if you can do a tutorial for the newer yocto 2.1
YOur tutorial does not work for YOcto 2.1 software release.First of all I would like to thank you for writing this tutorial but could you please guide us for the same with YOcto 2.1 software release.
I am swamped with other projects for the time being, so I do not think I will be able to load a new Yocto build (at least in the near future). If you are running into issues with the latest Yocto, I recommend posting your questions to Intel’s Edison forums. You will get a much faster response there.
If you are still looking for help compiling the Edison kernel with release 2.1, an updated guide can be found here: https://shawnhymel.com/724/creating-a-custom-linux-kernel-for-the-edison-yocto-2-1/
From which directory should I run this “bitbake edison-image” the seconds time in the step “configure and create new kernel”
I don’t believe you change directories once you are automatically placed in a new directory from running
source poky/oe-init-build-env
(I don’t remember which directory that is).I changed the spidev.c file and gave wrong syntax purposefully but still bitbake runs without any error. MY question is how do we compile the kernel sources? Does bitbake does that? If bitbake happened once then how do we recompile the kernel sources again?
Correct. The command
bitbake
compiles the kernel source and creates a new image.I am trying to get an SPI device work with the edison.It uses an ioctl call like this
ioctl(int fd,command,arg). I want to modify this ioctl function to toggle a gpio pin (which I want to use as a custom defined chip/slave select pin).SO could you tell me where will I find this ioctl call in yocto?
I am getting this error when I do postbuild.sh
cp: cannot stat ‘/home/ranjan/Downloads/edisonsrc2/build/tmp/deploy/images/edison/vmlinux’: No such file or directory
I am trying to change the printk and pr_info statements so that I can see a corresponding change in the dmesg output but I cant change any of the items that are getting printed from the kernel.
Hi Sriranjan/Shawn
Sriranjan, I think I am having the same issues as you when I am trying to recompile Yocto.
I had to modify the steps above as follows
tar xvf edison-src.tgz
cd edison-src/meta-intel-edison
sh ./setup.sh
I am confused after this.
Shawn says to Load the shell script in the poky/ directory to configure the build environment.
My poky directory is located at /home/root/edison-src/out/linux32/poky
When I try to run the source (source poky/oe-init-build-env)
I get the following error
Error: The build directory (BUILDDIR) must be set!
Have you the same issues, Did you have any success?
Rosemarie
By the way have you seen this wiki: https://edison.internet-share.com/wiki/Main_Page?
I have not seen that. Thanks for sharing!