{"id":90,"date":"2018-02-05T15:09:36","date_gmt":"2018-02-05T23:09:36","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=90"},"modified":"2018-02-06T09:57:18","modified_gmt":"2018-02-06T17:57:18","slug":"importing-a-linux-kernel-module-project-into-visualkernel","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/import\/","title":{"rendered":"Importing a Linux Kernel module project into VisualKernel"},"content":{"rendered":"<p>This tutorial shows how to create a VisualKernel project for an existing Linux kernel module. We will demonstrate it by creating a copy of the\u00a0<strong>coretemp<\/strong>\u00a0module responsible for measuring the temperature for the CPU core.<\/p>\n<p>Before you begin copy the\u00a0<strong>&lt;linux source&gt;\/drivers\/hwmon\/coretemp.c<\/strong>\u00a0file into a separate directory on your Linux machine, rename it to\u00a0<strong>coretemp2.c<\/strong>\u00a0and create a Makefile there containing the following lines:<\/p>\n<pre class=\"code \">KERNEL_MODULE_NAME := coretemp2\r\nobj-m += coretemp2.o\r\nccflags-y += -ggdb -O0<\/pre>\n<p>Then follow the steps below to import the module project into VisualKernel:<\/p>\n<ol>\n<li>Start the VisualKernel kernel module wizard:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/01-wizard.png\" width=\"700\" height=\"394\" \/><\/li>\n<li>On the first wizard page select &#8220;Import existing kernel module&#8221;:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/02-import.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the second page select the computer you are targeting:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/03-target.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the next page select the directory where you have placed the\u00a0<strong>coretemp2.c\u00a0<\/strong>file and the Makefile:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/04-source.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>On the &#8220;source code access&#8221; page proceed with the default settings:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/05-sourcecopy.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>Finally select the debugging method that will allow VisualKernel debug your target:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/06-kgdb.png\" width=\"696\" height=\"628\" \/><\/li>\n<li>Press &#8220;Finish&#8221; to create your project. Change\u00a0<strong>DRVNAME<\/strong>\u00a0from\u00a0<strong>&#8220;coretemp&#8221;<\/strong>\u00a0to\u00a0<strong>&#8220;coretemp2&#8221;<\/strong>\u00a0and press Ctrl-Shift-B to build the module. Changing the driver name will avoid collisions with the original coretemp driver:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/07-build.png\" width=\"698\" height=\"600\" \/><\/li>\n<li>Set a breakpoint on the\u00a0<strong>coretemp_init()<\/strong>\u00a0function and hit F5 to begin debugging:<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sysprogs.com\/VisualKernel\/legacy_tutorials\/import\/img\/08-breakpoint.png\" width=\"698\" height=\"600\" \/>Once the breakpoint is hit you can use normal debugging techniques to debug your module.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a VisualKernel project for an existing Linux kernel module. We will demonstrate it by<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[24,20],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/90"}],"collection":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":1,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":91,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/90\/revisions\/91"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}