{"id":551,"date":"2022-09-10T16:47:11","date_gmt":"2022-09-10T23:47:11","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=551"},"modified":"2022-09-12T09:37:48","modified_gmt":"2022-09-12T16:37:48","slug":"debugging-raspberry-pi-kernel-modules-using-prebuilt-kernels","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/raspberry\/prebuilt\/","title":{"rendered":"Debugging Raspberry Pi Kernel Modules using Prebuilt Kernels"},"content":{"rendered":"<p>This tutorial shows how to create, build and debug a basic kernel module for Raspberry Pi using VisualKernel 4.0 and pre-built Raspberry Pi kernel symbols.<\/p>\n<p>Using the pre-built kernel image avoids the need to build the kernel on a separate Linux machine and allows quickly navigating the kernel source code using the IntelliSense code database included with the image.<\/p>\n<ol>\n<li>Start Visual Studio and locate the VisualKernel Linux Kernel Project Wizard:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-564\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/01-newprj.png\" alt=\"\" width=\"1014\" height=\"675\" \/><\/a><\/li>\n<li>Choose a name for the project and enter the location where you would like to store it: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/02-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-563\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/02-prjname.png\" alt=\"\" width=\"1014\" height=\"675\" \/><\/a><\/li>\n<li>Proceed with the default &#8220;Hello, World&#8221; project template:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/03-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-562\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/03-hello.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Make sure your Raspberry Pi is running the latest SD card image and can be accessed via SSH. Then, select &#8220;Setup a new target -&gt; Target an Embedded Device&#8221;, open the drop-down list and click &#8220;Create a new SSH connection&#8221;:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/04-newssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-561\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/04-newssh.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Enter the host name, user name and the password to connect to the Raspberry Pi. Then, click <strong>Create<\/strong> to proceed: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/05-raspberry.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-560\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/05-raspberry.png\" alt=\"\" width=\"586\" height=\"510\" \/><\/a><\/li>\n<li>Proceed with the default settings on the &#8220;Build Settings&#8221; page of the wizard:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/06-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-559\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/06-target.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>VisualKernel will detect the Raspbian distribution running on the Raspberry Pi and will suggest automatically downloading a matching pre-built kernel image: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/kernels.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-568\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/kernels.png\" alt=\"\" width=\"786\" height=\"493\" \/><\/a>VisualKernel can automatically download and install both 32-bit kernels (<strong>v7l+<\/strong>) and 64-bit kernels (<strong>v8+<\/strong>).<\/li>\n<li>Select it from the list and click &#8220;OK&#8221;. VisualKernel will download the image and will install it, along with the build environment, on the Raspberry Pi:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/08-install.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-557\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/08-install.png\" alt=\"\" width=\"470\" height=\"268\" \/><\/a>After the installation, your Raspberry Pi will be rebooted and you will be able to build the modules directly on it, as if it was a regular desktop Linux distribution.<\/li>\n<li>Proceed with the default settings of storing the sources on the Windows side and uploading them during build:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/09-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-556\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/09-files.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Follow <a href=\"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/raspberry\/jtagsetup\/\">this tutorial<\/a> to setup JTAG debugging on your Raspberry Pi. Once it works, select the corresponding settings on the last page of the wizard:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/10-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-555\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/10-debug.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>VisualKernel will create a basic project. Build it via the <strong>Build-&gt;Build Solution<\/strong> command, set a breakpoint in the init() function and press F5 to begin debugging: <a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/11-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-554\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/11-bkpt.png\" alt=\"\" width=\"1278\" height=\"763\" \/><\/a><\/li>\n<li>Once the init() function finishes running and the kernel unloads the <strong>.init<\/strong> section, VisualKernel will automatically disable the breakpoint. You can load and the unload module using the button on the right side of the GDB Session window:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/12-loaded.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-553\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/12-loaded.png\" alt=\"\" width=\"1278\" height=\"763\" \/><\/a><\/li>\n<li>Use the <strong>Debug-&gt;Windows-&gt;Live Variables<\/strong> command to see the real-time values of various variables in your module, or the kernel itself. E.g. you can see (and plot) the <strong>jiffies<\/strong> variable counting the internal time:<a href=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/13-live.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-552\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2022\/09\/13-live.png\" alt=\"\" width=\"1278\" height=\"763\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create, build and debug a basic kernel module for Raspberry Pi using VisualKernel 4.0 and<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[37],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/551"}],"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=551"}],"version-history":[{"count":4,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/551\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}