{"id":24,"date":"2015-12-20T19:57:33","date_gmt":"2015-12-20T18:57:33","guid":{"rendered":"http:\/\/blog.brunocsmartin.fr\/?p=24"},"modified":"2016-01-27T15:47:04","modified_gmt":"2016-01-27T14:47:04","slug":"about-linux-modules","status":"publish","type":"post","link":"https:\/\/blog.brunocsmartin.fr\/index.php\/2015\/12\/20\/about-linux-modules\/","title":{"rendered":"About Linux Modules"},"content":{"rendered":"<p>Create a SD card image :<br \/>\n&#8211; get the last Raspbian image ont the website :\u00a0<a href=\"https:\/\/www.raspberrypi.org\/downloads\/raspbian\/\">https:\/\/www.raspberrypi.org\/downloads\/raspbian\/<\/a><br \/>\n&#8211; get the last applePi-Baker :\u00a0<a href=\"http:\/\/www.tweaking4all.com\/hardware\/raspberry-pi\/macosx-apple-pi-baker\/\">http:\/\/www.tweaking4all.com\/hardware\/raspberry-pi\/macosx-apple-pi-baker\/<\/a><br \/>\n&#8211; unzip the image, connect the SD card and launch applePi-Baker<\/p>\n<p>Connect the rpi using usb serial connexion :<br \/>\n&#8211; install the PL2303 driver<br \/>\n&#8211; install minicom<br \/>\n&#8211; connect the usb serial adapter to the rpi and ti the mac, check in dev (\/dev\/tty.usbserial)<br \/>\n&#8211; launch \u00ab\u00a0minicom -s\u00a0\u00bb in a terminal and enter the device address<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">minicom -s<\/pre>\n<p>&#8211; login : pi, password : raspberry<br \/>\n&#8211; activate root account :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo passwd root<\/pre>\n<p>&#8211; exit and log with root<\/p>\n<p>Expand Filesystem:<br \/>\n&#8211; launch raspi-config<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">raspi-config<\/pre>\n<p>&#8211; choose \u00ab\u00a01 Expand Filesystem\u00a0\u00bb<br \/>\n&#8211; reboot<\/p>\n<p>Get the module development environment :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napt-get install rpi-update\r\nrpi-update\r\n<\/pre>\n<p>&#8211; get the kernel version :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">uname -r<\/pre>\n<p>&#8211; download corresponding package at https:\/\/www.niksula.hut.fi\/~mhiienka\/Rpi\/linux-headers-rpi\/<br \/>\n&#8211; install with dpkg :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">dpkg -i linux-headers...<\/pre>\n<p>Try module compilation :<br \/>\n&#8211; create hello.c file containing :<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\n\/*\r\n* hello.c - The simplest kernel module.\r\n*\/\r\n#include &quot;linux\/module.h&quot; \/\/ included for all kernel modules\r\n#include &quot;linux\/kernel.h&quot; \/\/ included for KERN_INFO\r\n#include &quot;linux\/init.&quot; \/\/ included for __init and __exit macros\r\n\r\nMODULE_LICENSE(&quot;GPL&quot;);\r\nMODULE_AUTHOR(&quot;Martin&quot;);\r\nMODULE_DESCRIPTION(&quot;A Simple Hello World module&quot;);\r\n\r\nstatic int __init hello_init(void)\r\n{\r\n    printk(KERN_INFO &quot;Hello world!\\n&quot;);\r\n    return 0; \/\/ Non-zero return means that the module couldn't be loaded.\r\n}\r\n\r\nstatic void __exit hello_cleanup(void)\r\n{\r\n    printk(KERN_INFO &quot;Cleaning up module.\\n&quot;);\r\n}\r\n\r\nmodule_init(hello_init);\r\nmodule_exit(hello_cleanup);\r\n<\/pre>\n<p>&#8211; create Makefile file containing :<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nobj-m += hello.o\r\nKDIR := \/lib\/modules\/$(shell uname -r)\/build\r\nPWD := $(shell pwd)\r\n\r\nall:\r\n    make -C $(KDIR) M=$(PWD) modules\r\n\r\nclean:\r\n\u00a0\u00a0 \u00a0make -C $(KDIR) M=$(PWD) clean\r\n<\/pre>\n<p>&#8211; try to load and unload the module :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ninsmod hello.ko\r\nrmmod hello.ko\r\n<\/pre>\n<p>&#8211; check the results through the kernel messages :<br \/>\n&gt;dmesg | tail -20<\/p>\n<p>&#8211; it should be written something like :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B; 2831.586831] Hello world.\r\n&#x5B; 2846.286438] Goodbye world.\r\n<\/pre>\n<p>&#8211; And it&rsquo;s good !<\/p>\n<p>Install the new driver so it will be loaded at start up :<br \/>\n&#8211; copy the .ko file to the appropropriate directory : \/lib\/modules\/`uname -r`\/kernel\/drivers\/gpio<br \/>\n&#8211; run depmod<br \/>\n&gt;depmod<br \/>\n&#8211; and reboot<br \/>\n&gt;shutdown -r now<\/p>\n<p>For the raspberry, the serial connexion is limited and graphical interface is not supplied. So create a ssh server is a good way to use geany for example. As I use a wifi connexion, the ssh server will hang up soon as you are connected so. To get rid of this, add the following lines at the end of \/etc\/ssh\/sshd_config :<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">KeepAlive yes\r\nClientAliveInterval 60<\/pre>\n<p>Ok ?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a SD card image : &#8211; get the last Raspbian image ont the website :\u00a0https:\/\/www.raspberrypi.org\/downloads\/raspbian\/ &#8211; get the last applePi-Baker :\u00a0http:\/\/www.tweaking4all.com\/hardware\/raspberry-pi\/macosx-apple-pi-baker\/ &#8211; unzip the image, connect the SD card and launch applePi-Baker Connect the rpi using usb serial connexion : &#8211; install the PL2303 driver &#8211; install minicom &#8211; connect the usb serial adapter &hellip; <a href=\"https:\/\/blog.brunocsmartin.fr\/index.php\/2015\/12\/20\/about-linux-modules\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">About Linux Modules<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/posts\/24"}],"collection":[{"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":8,"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/posts\/24\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.brunocsmartin.fr\/index.php\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}