RZ/G2L Linux系統的鏡像基于yocto構建,本篇介紹如何添加新的內核模塊。
方式1:內核源碼外添加
方式2:內核源碼中添加
需要提前已按照文檔構建好開發環境和安裝SDK,本篇依據G2L VLP3.0.3。
方式1示例
A. bitbake編譯模塊方式
目錄和內容參考:
左右滑動查看完整內容
rzg2l_vlp_v3.0.3$ tree meta-renesas/meta-rz-common/recipes-kernel/kernel-module-helloworld/ meta-renesas/meta-rz-common/recipes-kernel/kernel-module-helloworld/ ├── files │ ├── helloworld.c │ └── Makefile └── kernel-module-helloworld.bb
helloworld.c
左右滑動查看完整內容
#includestatic int hello_world_init(void) { printk("Hello world "); return 0; } static void hello_world_exit(void) { printk("Bye world "); } module_init(hello_world_init); module_exit(hello_world_exit); MODULE_LICENSE("GPL v2");
Makefile
左右滑動查看完整內容
obj-m := helloworld.o SRC := $(shell pwd) all: make -C $(KERNELSRC) M=$(SRC) modules install: make -C $(KERNELSRC) 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
kernel-module-helloworld.bb
左右滑動查看完整內容
SRC_URI = " file://helloworld.c file://Makefile " S = "${WORKDIR}" EXTRA_OEMAKE = "KERNELDIR=${STAGING_KERNEL_BUILDDIR}" EXTRA_OEMAKE += "CROSS_COMPILE=${CROSS_COMPILE}" KERNEL_MODULE_PACKAGE_SUFFIX = "" do_install() { # Create destination directory install -d ${D}/lib/modules/${KERNEL_VERSION}/extra/ # Install kernel module install -m 644 ${S}/helloworld.ko ${D}/lib/modules/${KERNEL_VERSION}/extra/ # Install module symbol file install -m 644 ${S}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/helloworld.symvers } PACKAGES = " ${PN} " FILES_${PN} = " /lib/modules/${KERNEL_VERSION}/extra/helloworld.ko
編譯模塊:
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3$ source poky/oe-init-build-env ### Shell environment set up for builds. ### You can now run 'bitbake' Targets are: core-image-minimal core-image-bsp core-image-weston core-image-qt hank@rz:~/rzg2l_vlp_v3.0.3/build$ MACHINE=smarc-rzg2l bitbake -s | grep hello go-helloworld :0.1-r0 kernel-module-helloworld :1.0-r0 lib32-go-helloworld :0.1-r0 hank@rz:~/rzg2l_vlp_v3.0.3/build$ MACHINE=smarc-rzg2l bitbake kernel-module-helloworld WARNING: Layer qt5-layer should set LAYERSERIES_COMPAT_qt5-layer in its conf/layer.conf file to list the core layer names it is compatible with. WARNING: Layer qt5-layer should set LAYERSERIES_COMPAT_qt5-layer in its conf/layer.conf file to list the core layer names it is compatible with. Loading cache: 100% … NOTE: Tasks Summary: Attempted 650 tasks of which 635 didn't need to be rerun and all succeeded.
查看結果:
左右滑動查看完整內容
build/tmp/work/smarc_rzg2l-poky-linux/kernel-module-helloworld/1.0-r0/helloworld.ko
如果想編譯到rootfs,請修改conf/local.conf追加內容并重新編譯rootfs
左右滑動查看完整內容
MACHINE_EXTRA_RRECOMMENDS = " kernel-module-helloworld"
庫文件包已含在rootfs內
左右滑動查看完整內容
build$ find ./tmp/work/smarc_rzg2l-poky-linux/ -name helloworld.ko ./tmp/work/smarc_rzg2l-poky-linux/core-image-qt/1.0-r0/rootfs/lib/modules/5.10.158-cip22-yocto-standard/extra/helloworld.ko ./tmp/work/smarc_rzg2l-poky-linux/kernel-module-helloworld/1.0-r0/helloworld.ko
B.在源碼目錄直接編譯方式
左右滑動查看完整內容
cd /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build source /opt/poky_vlp3.0.3/environment-setup-aarch64-poky-linux sudo chown -R $USER . make scripts make prepare mkdir hello //并拷貝上邊的源碼文件 /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello$ ls helloworld.c Makefile /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello$ make make -C /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/usr/src/kernel M=/opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello modules make[1]: Entering directory '/opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build' CC [M] /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello/helloworld.o MODPOST /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello/Module.symvers CC [M] /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello/helloworld.mod.o LD [M] /opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello/helloworld.ko make[1]: Leaving directory '/opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build' hank@rz:/opt/poky_vlp3.0.3/sysroots/aarch64-poky-linux/lib/modules/5.10.158-cip22-yocto-standard/build/hello$ ls helloworld.c helloworld.ko helloworld.mod helloworld.mod.c helloworld.mod.o helloworld.o Makefile modules.order Module.symvers
方式2示例
首先提取內核源碼:
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3$ source poky/oe-init-build-env ~/rzg2l_vlp_v3.0.3/build$ MACHINE=smarc-rzg2l devtool modify linux-renesas NOTE: Starting bitbake server... …… INFO: Adding local source files to srctree... INFO: Copying kernel config to srctree INFO: Source tree extracted to /home/xxx/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas WARNING: SRC_URI is conditionally overridden in this recipe, thus several devtool-override-* branches have been created, one for each override that makes changes to SRC_URI. It is recommended that you make changes to the devtool branch first, then checkout and rebase each devtool-override-* branch and update any unique patches there (duplicates on those branches will be ignored by devtool finish/update-recipe) INFO: Recipe linux-renesas now set up to build from /home/xxx/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas
上面最后一行就是Linux內核源碼提取后所在目錄,即/home/xxx/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas, 然后去這個目錄修改代碼即可。
進入Linux源碼目錄下找個目錄增加模塊代碼,這里使用build/workspace/sources/ linux-renesas /drivers/char目錄,在該目錄下執行mkdir hello創建目錄,然后在hello目錄下創建以下文件。
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas/drivers/char$ tree hello/ hello/ ├── hello.c ├── Kconfig └── Makefile
hello.c
左右滑動查看完整內容
#includestatic int hello_world_init(void) { printk("Hello world "); return 0; } static void hello_world_exit(void) { printk("Bye world "); } module_init(hello_world_init); module_exit(hello_world_exit); MODULE_LICENSE("GPL v2");
Kconfig
左右滑動查看完整內容
config HELLO tristate 'Create a hello module' default n help This is a module to print Hello World!
Makefile
obj-$(CONFIG_HELLO) += hello.o
修改build/workspace/sources/ linux-renesas /drivers/char目錄的Kconfig和Makefile:
左右滑動查看完整內容
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index b4e65d1ed..2b96630ab 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -508,4 +508,6 @@ config RANDOM_TRUST_BOOTLOADER believe its RNG facilities may be faulty. This may also be configured at boot time with "random.trust_bootloader=on/off". +source "drivers/char/hello/Kconfig" + endmenu diff --git a/drivers/char/Makefile b/drivers/char/Makefile index ffce287ef..3056303ff 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -47,3 +47,5 @@ obj-$(CONFIG_PS3_FLASH) += ps3flash.o obj-$(CONFIG_XILLYBUS) += xillybus/ obj-$(CONFIG_POWERNV_OP_PANEL) += powernv-op-panel.o obj-$(CONFIG_ADI) += adi.o + +obj-$(CONFIG_HELLO) += hello/
返回yocto頂層目錄,選擇內核配置
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3/build$ source poky/oe-init-build-env ~/rzg2l_vlp_v3.0.3/build$ MACHINE=smarc-rzg2l bitbake virtual/kernel -c menuconfig
編譯內核
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3/build$ MACHINE=smarc-rzg2l devtool build linux-renesas NOTE: Starting bitbake server... …… NOTE: Tasks Summary: Attempted 607 tasks of which 594 didn't need to be rerun and all succeeded.
生成結果
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3/build$ ls tmp/work/smarc_rzg2l-poky-linux/linux-renesas/5.10.158-cip22+git999-r1/linux-renesas-5.10.158-cip22+git999/drivers/char/hello/ built-in.a hello.o modules.order
最后制作補丁,創建自己的layer保存補丁。
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3$ source poky/oe-init-build-env ~/rzg2l_vlp_v3.0.3/build$ bitbake-layers create-layer ../meta-mylayer ~/rzg2l_vlp_v3.0.3/build$ bitbake-layers add-layer ../meta-mylayer hank@rz:~/rzg2l_vlp_v3.0.3/build$ tree ../meta-mylayer/ ../meta-mylayer/ ├── conf │ └── layer.conf ├── COPYING.MIT ├── README └── recipes-example └── example └── example_0.1.bb 3 directories, 4 files
再次進入源碼目錄,提交修改,生成補丁
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas$ git status . Refresh index: 100% (70807/70807), done. On branch devtool Changes not staged for commit: (use "git add..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: drivers/char/Kconfig modified: drivers/char/Makefile Untracked files: (use "git add ..." to include in what will be committed) drivers/char/hello/ no changes added to commit (use "git add" and/or "git commit -a") ~/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas$ git add ./* The following paths are ignored by one of your .gitignore files: oe-logs oe-workdir Use -f if you really want to add them. ~/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas$ git commit -m "add the hello module" [devtool 6dc52bd44] add the hello module 5 files changed, 25 insertions(+) create mode 100644 drivers/char/hello/Kconfig create mode 100644 drivers/char/hello/Makefile create mode 100644 drivers/char/hello/hello.c
切到build目錄執行
左右滑動查看完整內容
~/rzg2l_vlp_v3.0.3/build$ MACHINE=smarc-rzg2l devtool finish linux-renesas ../meta-mylayer/ NOTE: Starting bitbake server... …… Parsing of 2151 .bb files complete (0 cached, 2151 parsed). 5440 targets, 887 skipped, 3 masked, 0 errors. …… INFO: Leaving source tree /home/xxx/rzg2l_vlp_v3.0.3/build/workspace/sources/linux-renesas as-is; if you no longer need it then please delete it manually ~/rzg2l_vlp_v3.0.3/build$ tree ../meta-mylayer/ ../meta-mylayer/ ├── conf │ └── layer.conf ├── COPYING.MIT ├── README ├── recipes-example │ └── example │ └── example_0.1.bb └── recipes-kernel └── linux ├── linux-renesas │ ├── 0001-add-the-hello-module.patch │ └── devtool-fragment.cfg └── linux-renesas_%.bbappend 6 directories, 7 files
上邊patch文件就是修改的內容了。
審核編輯:湯梓紅
-
內核
+關注
關注
3文章
1362瀏覽量
40226 -
Linux
+關注
關注
87文章
11225瀏覽量
208911 -
Linux系統
+關注
關注
4文章
591瀏覽量
27352 -
源碼
+關注
關注
8文章
633瀏覽量
29138 -
SDK
+關注
關注
3文章
1026瀏覽量
45775
原文標題:RZ/G2L添加新的內核模塊
文章出處:【微信號:瑞薩MCU小百科,微信公眾號:瑞薩MCU小百科】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論