cd ~/poky
: Replace with your poky path- create a new layer. let say
meta-hello-yocto
:bitbake-layers create-layer ./meta-hello-yocto
- initialize the build environment variables :
source oe-init-build-env
cd build/
if not already there.- add the newly created layer to the build-system:
bitbake-layers add-layer "../meta-hello-yocto"
. This should automatically update thebblayers.conf
file underbuild/conf
cd ~/poky/meta-hello-yocto
- remove the receipes-exaple directory :
rm -rf recipes-example/
- create a dir . let say
recepies-kernel
:mkdir recipes-kernel
cd recipes-kernel/
- make a directory. let say hello-mod:
mkdir hello-mod
cd hello-mod
- create a file name, say
kernel-module-hello_0.1.bb
with the following content:
SUMMARY = "Example of how to build an external Linux kernel module"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
inherit module
SRC_URI = "file://Makefile \
file://hello.c \
file://COPYING \
"
S = "${WORKDIR}"
# The inherit of module.bbclass will automatically name module packages with
# "kernel-module-" prefix as required by the oe-core build environment.
RPROVIDES_${PN} += "kernel-module-hello"
mkdir files
cd files
- create a file named
hello.c
with the following content:
/******************************************************************************
*
* Copyright (C) 2011 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*****************************************************************************/
#include <linux/module.h>
int init_module(void)
{
printk("Hello World!\n");
return 0;
}
void cleanup_module(void)
{
printk("Goodbye Cruel World!\n");
}
MODULE_LICENSE("GPL");
-
create a file named
COPYING
(optional) -
create a
Makefile
obj-m := hello.o
SRC := $(shell pwd)
all:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC)
modules_install:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
clean:
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
rm -f Module.markers Module.symvers modules.order
rm -rf .tmp_versions Modules.symvers
- tree should be like this
.
├── conf
│ └── layer.conf
├── COPYING.MIT
├── README
└── recipes-kernel
└── hello-mod
├── files
│ ├── COPYING
│ ├── hello.c
│ └── Makefile
└── kernel-module-hello_0.1.bb
4 directories, 7 files
-
recheck the layers
bitbake-layers show-layers
-
update the
poky/build/conf/local.conf
file by appendingMACHINE_ESSENTIAL_EXTRA_DEPENDS +="kernel-module-hello"
-
compile the the code:
cd ~/poky/build && bitbake kernel-module-hello
-
bitbake package-index
-
re-build the image ( in this example
core-image-sato
) :bitbake core-image-sato
-
run the image in QEMU:
runqemu qemux86-64
: (in this example I'm usingqemux86-64
, addnographic
to the command if you are remotely logged into a machine ) -
modprobe hello
-
⚡