Patching and compiling kernel, in which directory - linux

I'm trying to apply a patch to my kernel source with limited success. The target machine is really some ARM device, but I haven't compiled a kernel before so I thought I'd start with an x86_64 kernel. This has been only marginally easier :)
Now, according to some tutorials, it seemed like we should use the source in /usr/src/linux-something. But when I tried to patch there I got
File Documentation/sysrq.txt is read-only; trying to patch anyway
patch: **** Can't create temporary file Documentation/sysrq.txt.oG1oiZW : Permission denied
even under sudo. So I tried just copying the patch and the linux source folder to my home directory and patched it from there. This worked. Why is this and will this have any weird side effects when compiling?

It seems you have no permission to /usr/src/linux-something. Download kernel source, put it anywere you could, then patch & compile it.
Build a x86_64 arch kernel from source which downloaded from kernel.org is well, if you wanna build an arm arch kernel for a special board, use buildroot or openwrt is better.

The package manager for some distributions installs the kernel source in /usr/src and distribution-specific build scripts may assume that the source is in that directory.
However, if you download vanilla kernel source from kernel.org, you should be able to build it anywhere.

Related

Integrate buildroot with BeagleBone github repository

I am using Buildroot to produce root filesystem and kernel for my BeagleBone Black. Currently I provide my custom kernel to buildroot. But I noticed there is several ready-made kernels for BeagleBone Black on GitHub.
Since Buildroot allows to download kernel source directly from a git repository, I should be able just to point Buildroot to the BeagleBone's kernel repository on GitHub and Buildroot should download and compile the kernel for me.
Unfortunately the things are not so easy. When I specify BeagleBone's kernel repository in Buildroot, the kernel source is successfully cloned, but there is no default configuration and maybe some patch work is also necessary.
Did anybody try to integrate Buildroot with BeagleBone's GitHub's kernel sources?
Why don't you use the beaglebone_defconfig configuration provided by Buildroot. It uses a 4.4 kernel for the BeagleBone, fetched from git://git.ti.com/processor-sdk/processor-sdk-linux.git.

Creating custom Linux image with Yocto using TI sitara am335x devkit compiler

I want to use Yocto to build a linux dist from my own sources (not Arago sources).
I have installed Yocto eclipse plugin, but I can't configure the compiler toolchain.
I have the ti-sdk-am335x-evm-07.00.00.00 SDK installed, and would like to use it
to compile my own dist.
In the Yocto Project ADT preferences in eclipse, what do I specify for:
Toolchain Root Location
And
Sysroot Location?
It won't show up a target architecture, when I try to configure it. What folders should I set?
First, make sure that you built the toolchain, or otherwise made it available. Try this:
bitbake meta-ide-support
That will build a script that you can source in another directory to have access to the toolchain.
Did you check out the Yocto Manual? Specifically, look at section:
4.2.2.1.4.1. Configuring the Cross-Compiler Options
What I've gotten to work is this:
Toolchain Root Location: the manual says the top of the build directory, but for me it won't work unless I have it at build/tmp. In other words, the Toolchain Root Directory is the directory right above where the environment setup script got built.
Sysroot Directory: build/tmp/sysroots/
Also, try with "Standalone pre-built toolchain" selected instead of "Build system derived toolchain," as discussed here.

Advice regarding installing ARM toolchain on Ubuntu VM (64bit)

Trying to compile Linux kernel for arm platform on a Ubuntu virtual machine
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
It fails as follows
arm-none-linux-gnueabi-gcc: not found
Tried to install
$sudo apt-get install arm-none-linux-gnueabi-gcc
E: unable to locate package arm-none-linux-gnueabi-gcc
Where to find the correct package? how to include it in the system? (I found a couple of links on line that didn't work for me). It would be great if you could provide a correct solution or reference.
The Ubuntu package names are gcc-arm-linux-gnueabi/gcc-arm-linux-gnueabihf.
For building the kernel, which one you use does not make much difference. For building anything else, "gnueabihf" is the hard-float version. For any modern ARM processor (this statement excludes the Raspberry PI), this is the one you would want.
Download arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 from https://sourcery.mentor.com/GNUToolchain/
or https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription?#template=lite
Get correct version of the arm-none-linux-gnueabi toolchain (i.e. targetting GNU/Linux rather than EABI).
untar it
tar xvf arm-2013.05-24-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
open bashrc
vi .bashrc
at the end add below comand
export PATH=$PATH:{path to toolchain}arm-2013.05/bin
e.g export PATH=$PATH:/home/vinay/under_linux/arm-2013.05/bin
save it and quit the terminal.
then you can cross-compile without everytime export.
Also take of correct toolchain there are two toolchain available choose according to your requirement.
Cross compile error "arm-none-eabi-g++ cannot find entry symbol"

libmodbus cross compilation and install in Beaglebone

Can any one tell me how I can install and cross-compile libmodbus library(libmodbus.org) for beaglebone??
I tried to compile for my local machine having ubuntu installed in it and the library got installed properly and works fine. But I want to install for beaglebone. I have beaglebone's file system on my local machine(target Network file system)
I want to write a modbus master(client) rtu code and run on the board which i mentioned above. Please guide me for this work.
Manual cross-compilation
You should configure the build system with the prefix of your toolchain (for example arm-none-linux-gnueabi for Sourcery CodeBench ARM 2013.05):
./configure --host=arm-none-linux-gnueabi
(if you can't find confgure script, execute autogen.sh first to create it), build the library:
make
Then copy library files to your rootfs:
cp src/.libs/libmodbus.* path-to-your-rootfs-usr-lib
Buildroot flavor
git clone git://git.busybox.net/buildroot
make beaglebone_defconfig
make menuconfig
And search for libmodbus "Target packages->Libraries->Networking", select it and build the entire rootfs:
make

Combining existing rootfs with custom toolchain

I've got a Raspberry PI with Emdebian installed on it, and want to cross-compile projects.
There is plenty of documentation on how to obtain a toolchain and build a simple project with it. I myself managed to build a toolchain with crosstool-ng and wrote a hello world program which works fine.
What I don't get is how to handle cross-compiling more complex projects like Qt, which have dependencies on other libraries. Let's use libdbus as an example, as that is one of Qt's dependencies.
The installed Emdebian already contains libdbus.so, so naturally I'd prefer to use that, instead of cross-compiling my own libdbus.so, as compiling all of Qt's dependencies would take a lot of time.
For cross-compiling, there are two important directories, as far as I understand:
The "staging" directory, where all the installed libraries and applications live. This initially is a copy of the toolchain's sysroot directory, and gets populated with more libraries as they are cross-compiled.
The "rootfs" directory, which is equivalent to what is on the device - essentially a copy of the staging directory without unneeded stuff like documentation and header files. As far as I understand it, the best approach is to copy required files from the staging directory into the rootfs.
Getting the rootfs directory is easy, as that can be a NFS mount from the device. But how do I get a staging directory for the existing Emdebian installation on the PI? The staging directory needs to include things like dbus headers, which are not installed on the rootfs.
Some people simply install the dbus headers on the device, with apt-get install libdbus-dev, and then use the rootfs as the staging directory. With this setup, there is no distinction between rootfs and staging anymore, with the disadvantage that the rootfs is polluted with headers, documentation and so on. The advantage of course is that it is easy.
What is the best way to get the dbus headers into my staging directory on my host machine? What is the usual approach people use in this situation?
As a side question, why does the approach of obtaining a toolchain, compiling a program and then copying that on a target work at all? The toolchain ships its own versions of libc, libstdc++ etc, are they not incompatible with the versions that are installed on the target? Especially when creating using a custom toolchain compiled with crosstool-ng?
(Note that I am not asking how to compile Qt, I can figure that out myself. My question is more general, about the approach to take when combining a custom toolchain with an existing installation/rootfs)
In my experience, you don't need to compile your dbus. You can do it as
Create Debian cross rootfs by debootstrap by https://wiki.debian.org/EmDebian/CrossDebootstrap
Create your cros-compile toolchain by crosstool-ng, and make sure the kernel version and eglibc version are the same as rootfs created by 1st step
Build QT by
CPPFLAGS=-I<rootfs>/usr/include \
LDFLAGS=-L<rootfs>/lib -L<rootfs>/usr/lib -Wl,-rpath-link,<rootfs>/lib,<rootfs>/usr/lib \
./configure <your options>
make
Install QT into the stage directory by
make install DESTDIR=<stage directory>
Copy QT dependent libraries from rootfs the your stage directory
So you can see that, the stage directory is kept minimum without pollution.

Resources