modifying system call in Linux kernel and recompiling in a virtual machine (not a module) - linux

I am trying to modify the sys_write system call in the Linux kernel. I have researched and found the source code online, but I don't know how to access the source code in my virtual machine so that I can start changing it. I have looked everywhere in the file system, but all I can find are header files and makefiles. I am thinking that they made the .c files invisible from within the OS for a reason. Does anyone know how I can get to them, or do I have to modify source I download from the internet and recompile from scratch?

First of all: download and build Linux Kernel. In internet there is so many tutorials about that. After that you can try to write own System Call but for every new system call you need to rebuild a kernel.

Related

Linux kernel getting rebuilt when moving the source folder

I'm trying to optimize the way our system is getting built and one of the problems I am faced with is the linux kernel getting rebuilt every time the build systems recompile.
There is a customized cache mechanism in place which allows our developers to patch the root fs at different point of the building process. Some applications are copied just before buildroot is rebuilt by updating the target root fs before buildroot can generate the target linux image (vmlinux, which includes the initramfs).
To avoid recompiling buildroot we have a system which copies all the object files from a previously compiled folder into a local folder and then make is invoked in the latest. It works fine for all packages in buildroot BUT for the linux kernel, which gets rebuilt every time.
After a long analysis of the makefile logs, I think this is happening because of absolute paths being present in some of the kernel dependencies (which forces some generated files to be re-generated again, thus recompiling almost everything).
I have multiple tracks to explore starting from there but I can't find any more info on neither of those:
Can I configure/compile the linux kernel so that it uses only relative paths ?
If not, can I patch those paths safely ?
If not, can I tell buildroot to use a previously compiled vmlinux image to build it's final package ?

Yocto and Linux

I am following the instructions here:
http://www.rocketboards.org/foswiki/Documentation/AlteraSoCDevelopmentBoardYoctoGettingStarted
I run this command
bitbake virtual/kernel
Everything works fine except it does not create a socfpga_cyclone5.dtb
I run this command, which should be the same
bitbake altera-image
And I get the error
ERROR: Multiple .bb files are due to be built which each provide virtual/kernel (/home/bobo/yocto/meta-altera/recipes-kernel/linux/linux-altera_3.11.bb /home/bobo/yocto/meta-altera/recipes-kernel/linux/linux-altera-dist.bb).
This usually means one provides something the other doesn't and should.
Does anyone know how to create that .dtb file or fix the second command? Up to that point I had no errors.
Ideally your .dtb file should be coming from the Altera software flow through Qsys and that is the one you should use, rather than the one that is created from the Yocto build system.
The Yocto build system will not be aware of the FPGA design and hence that .dtb won't be useful.
The error you're getting is mostly due to conflicting meta files. Sometimes a target might have multiple providers. A common example is "virtual/kernel", which is provided by each kernel recipe. Each machine often selects the best kernel provider by using a line similar to the following in the machine configuration file, which should be somewhere in
poky/meta-altera/conf/machine/your-machine.conf:
PREFERRED_PROVIDER_virtual/kernel = "linux-altera-3.11"

making a simple sytem call for linux 2.6.39 kernel

I am learning to make a simple system call from this website.
When i go to my "/usr/src" directory, I see 2 folders
1) Linux
2) Linux-Source-2.6.39.4
To which one should i make changes in order to make my system call ?
Neither. Download a fresh copy of the kernel source code, extract it into your home directory, and do your development work there using your normal user account. You only need root to install the kernel after you compile it.
The root-owned files in /usr/src are probably associated with the stock kernel that came with your system, and shouldn't be used for development. Especially since you'd have to do your development as root, just to have write permission.

how to get the linux kernel directory from http://source.android.com?

The default download seems not to contain the kernel directory while use the prebuilt linux kernel image. Does any one know how to get the linux kernel directory? I have googled and tried some methods but they did not work.
You know how to use git right?
Here :
https://android.googlesource.com/
Go to https://android.googlesource.com/ as the repositories moved away from kernel.org to Google's own servers (~2011).
There are a couple of repositories named "kernel/*". Each one is for a different device. For instance, the one used in the emulator is the "kernel/goldfish".
Once you click in any one of them, at the top of the repository page you'll get a "git clone" command to download them individually.

Distributing source files with an open source app

I have written an open source (GPL) application for Linux and OSX and now wish to distribute it. Is it normal to distribute the source code along with the binaries by default, or just provide a link to where it can be obtained?
If I include the source files, where is the normal location for writing them on the users system for Linux and OSX (I thought /usr/local/src but on my Ubuntu machine, supposedly chock-full of open source apps, this directory is empty).
It is usual to distribute the sources and binaries separately. Binaries would normally be distributed in distro-specific package formats whilst sources would be a simple .tar.gz containing a project folder. The user could unpack it to /usr/local/src if they wanted but it should build anywhere. It's not up to your program to drop its sources in any particular location.
I thought /usr/local/src but on my Ubuntu machine, supposedly chock-full of open source apps, this directory is empty
It will be empty if you are only using the Ubuntu repos. The OS is in charge of /usr and will drop any sources you install into /usr/src. But /usr/local is left for you to play with; that's where you install stuff that the distro doesn't provide.
About /usr/local/src
/usr/local and any subdirectories are always going to be empty on your machine unless YOU have specifically put something in there. It's a section of the filesystem that is reserved for user-installed software for that specific machine. Ubuntu (or any distribution) is not ever supposed to touch it.
Your distro will have separate places for its own source code, if any. Most Ubuntu installations won't need source code anyway (though you can download it if you want to), but if they do it'll go somewhere like /usr/src. But if you want to place your own source code somewhere and don't want your distro to mess with it, then just:
If it's just for developing/compiling in your own user account, you can just put it somewhere in your home directory.
If it's a piece of software you'll installing on the system, /usr/local/src is the suggested spot and your distro won't mess with it there.
FHS is the standard which says where in the filesystems things go, and includes distinctions such as the ones I've discussed above.
Your software should be able to be compiled no matter which directory it's in, because as you can see, it can depend.
It's worth looking at a few projects on Sourceforge (http://www.sf.net). As menioned by #bobince it's normal to distribute binaries and source separately. It's certainly kind to users not to require compilation so they can download and run.

Resources