I have installed Fedora 18 on VirtualBox on Macbook Pro and wanted to see if the Kernel compile is working fine.
After installing Fedora I had updated the Kernel source etc using the below commands
yum install kernel-devel
yum install kernel-headers
yum insall kernel-doc
yum install man
My Kernel version is 3.8.6-203.fc18.x86_64
I had tried Kernel compile with a simple Hello World program which goes like below
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
WHen I try to compile using the below commands, I get the below error
[seemabhat#localhost ~]$ make
make -C /lib/modules/3.6.10-4.fc18.x86_64/build M=/home/seemabhat modules
make: *** /lib/modules/3.6.10-4.fc18.x86_64/build: No such file or directory. Stop.
make: *** [all] Error 2
[seemabhat#localhost ~]$
Please suggest what do I need to do
Hmmm...problem with your kernel not with your program.....check whether build directory is there or not in /usr/lib/modules/3.6.10-4.fc18.x86_64..or if it is there then by clicking it is accessible or not....I believe it won't be there, you updated your kernel parts not kernel itself. Try to use this command "yum install update kernel" without quote, it will update your kernel...you can check lateset version kernel folder after installing in /usr/lib/modules...so when u do uname -r it will still show your previous kernel...so reboot it...and then do uname -r to check latest kernel version running...now try to build your module...It will execute successfully...Good Luck.
Related
My goal is to cross-compile a code file with Yocto SDK on my host machine to make it executable on my target Board. I am using SUMO Yocto version and GCC 7.3 cross compiler.
First of all, to get with YOCTO cross compiling I created a file Hello.c :
#include <stdio.h>
int main(void)
{
printf ("Hello World!\n");
return 0;
}
I compiled the file executing :
make hello
Now I have a compiled file which is ready to be executed on my target board.
But now I have multiple .h files and multiple .cpp files and a main file.
When I execute main file like this :
make main
an error occurs:
main.cpp:10:10: fatal error: boost/asio.hpp: No such file or directory
include ^~~~~~~~~~~~~~~~ compilation terminated.
: recipe for target 'main' failed make: *** [main] Error 1
I think that I have a problem with Boost and asio.hpp.
Is the boost library included in my Yocto Linux image ?
What is the problem with asio.hpp ?
How can I fix this please ?
Thanks
I just noticed that, actually, you're not using the SDK but the toolchain which only includes glibc along with some basic tools and gdb; usually used to build test apps and debug. So that, you need to build the real SDK which contains, in addition to the toolchain, the dev version (libs/headers/other files) of the packages installed in the rootfs of your image. This can be accomplished by:
bitbake -c populate_sdk <your_image>
Once the SDK is built you need to install it through the generated installer script. Also, don't forget to source the environment setup script before you start to work!
For further information refer to https://www.yoctoproject.org/docs/latest/sdk-manual/sdk-manual.html#sdk-building-an-sdk-installer
I'm working with a very peculiar environment: SH4 architecture, RedHat Linux, kernel 2.4.5.
I'm trying to write a graphic application using Xlib that can run in this environment.
I experimented long time ago with cross-compiling for SH4 architecture and it worked OK. However I never had to compile for a specific outdated kernel.
Set up a VM with linux mint, installed g++, cmake,
#include <iostream>
using namespace std;
int main()
{
//print output
cout << "hello" << endl;
return 0;
}
I run the compiler
g++ hello.cpp
And get a binary file "a.out".
I can execute the binary by typing "./a.out". It prints "hello".
However when I transfer "a.out" to the SH4 machine via FTP and try to run it I get:
bash: a.out: cannot execute binary file
This leads me to believe that the target computer doesn't understand the compiled binary.
In a fresh Alpine Linux I installed GCC by
apk add --update-cache gcc
but still a simple program
#include <stdio.h>
int main(int argc, char *argv[]) {
return 0;
}
compiled with message
fatal error: stdio.h: No such file or directory
Install musl-dev (in addition to the gcc compiler)
apk add musl-dev
You need to install it separately because in Alpine Linux, the package GCC doesn't depend on libc-dev for good reason:
You can use gcc to compile things without libc, for example hypervisors firmware etc.
And August Klein also noted that in Debian, GCC only recommends libc-dev for the same reason (but most people don't do --no-install-recommends anyway).
I am trying to write kernel module for ubuntu 12.04 LTS OS.
kernel version is 3.4.0-030400-generic-pae
I am able to compile it & load it to kernel.
For loading I use
sudo insmod nmod_main.ko
Now, If I try to remove it using
sudo rmmod nmod_main.ko
it gives me bellow error.
ERROR: Removing 'nmod_main': Device or resource busy
lsmod gives bellow information:
Module Size Used by
nmod_main 12394 0 [permanent]
Why this module shows permanent?
Bellow is the C-code for this module.
/********** Start of code ************/
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "init_module() called\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "cleanup_module() called\n");
}
/********** End of code ************/
I am getting some compilation warnings as bellow:
Building with KERNELRELEASE = 3.4.0-030400-generic-pae
CC [M] ../src/nmod_main.o
../src/nmod_main.c:1:0: warning: "KERNEL" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
../src/nmod_main.c:2:0: warning: "MODULE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
Building modules, stage 2.
Building with KERNELRELEASE = 3.4.0-030400-generic-pae
Please can anybody help me in this regard.
I am using bellow makefile for building this module:
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
.PHONY: build clean
build:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf ../src/*.o ../src/*~ core ../src/.depend ../src/.*.cmd ../src/*.ko ../src/*.mod.c
else
$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m := ../src/nmod_main.o
endi
This problem is solved. Yes, it is problem related to toolchain. I downloaded .deb files to install Linux Kernel from url.
But I was not sure about the toolchain used to generate these .deb files. So I finally downloaded Linux kernel source from url, compiled & installed on my laptop. Then compiled my module. Problem disappeared.
Thanks #avd for providing me valuable clue.
You need to add module entry points which will allow kernel to load or unload module.Without module_init and module_exit kernel does'nt know how to unload the module and module became permanent. BUt dont know to fix i need solution How to remove this permanent module.
I've just started learning linux kernel modules and trying to write simple Hello world program.
So mymod.c:
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Author");
MODULE_DESCRIPTION("\"Hello, world!\" minimal module");
MODULE_VERSION("printk");
int init_module(void)
{
printk("<1>Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
Makefile:
obj-m += mymod.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
make outout:
make -C /lib/modules/3.2.0-23-generic-pae/build M=/root modules
make[1]: Entering directory `/usr/src/linux-3.2.42'
WARNING: Symbol version dump /usr/src/linux-3.2.42/Module.symvers
is missing; modules will have no dependencies and modversions.
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-3.2.42'
So it creates files I needed, but when I try to install this by
insmod mymod.ko
I get next output:
insmod: error inserting 'mymod.ko': -1 Invalid module format
So I'd like to know what's the problem?
PS. OS - Ubuntu Server 12.04. Kernel - linux 3.2.0-23 pae
UPDATE:
I've downloaded from kernel.org kernel 3.2.42 and put it in /usr/src and did 'make defconfig && make prepare', 'make modules_prepare'. Also I've created link in /lib/modules/3.2.0-23-generic-pae/build.
Is this the source tree for the running kernel? If not, it should fail.
Install the kernel-devel (or similarly named) package for your distribution, it adds enough machinery to build modules against it.
You missed the module_init and module_cleanup declaration,
module_init (module_init);
module_exit (cleanup_module);
Otherwise it would have no entry point defined, and it wouldn't load.
Because this task requires so many details, and small files to be coordinated it is best to use UML (user mode linux) so that the kprintf (kernel printf) always outputs to the terminal even in a graphical environment.