{"id":116,"date":"2014-03-25T00:59:47","date_gmt":"2014-03-25T00:59:47","guid":{"rendered":"http:\/\/int03.co.uk\/blog\/?p=116"},"modified":"2014-03-25T01:10:29","modified_gmt":"2014-03-25T01:10:29","slug":"building-kernel-modules-on-the-raspberry-pi-is-ridiculously-hard","status":"publish","type":"post","link":"https:\/\/int03.co.uk\/blog\/2014\/03\/25\/building-kernel-modules-on-the-raspberry-pi-is-ridiculously-hard\/","title":{"rendered":"Building Kernel Modules on the Raspberry Pi is Ridiculously Hard!"},"content":{"rendered":"<p>I don&#8217;t think I&#8217;m alone on <a href=\"http:\/\/raspberryalphaomega.org.uk\/2013\/01\/29\/why-is-it-so-hard-to-build-raspberry-pi-linux-drivers\/\">this issue&#8230; <\/a>it seems almost impossible to build a working kernel driver on the Pi. After much trial and error, and on the verge of giving up completely, I finally succeeded!<\/p>\n<p>I started with cross compilation on Ubuntu but couldn&#8217;t get it to work initially, it kept giving &#8220;Invalid module format&#8221;. Compiling directly on the Pi, again I was only able to obtain &#8220;Invalid module format&#8221; errors and, finally, a module that loaded but crashed the OS. The .config and Module.symvers seem correct, but it just would not build a working module. It makes me suspect some compiler toolchain difference between the kernel and the tools used to build the module.<\/p>\n<p>Finally, cross compilation worked. Here is the magical recipe which\u00a0 worked for me under Ubuntu, cross compiling for 3.10.33+ (mostly in case I need it again myself). First, set up the environment variables and download tools as described <a href=\"http:\/\/elinux.org\/RPi_Kernel_Compilation\">here<\/a>.<\/p>\n<pre>git clone --depth 1 git:\/\/github.com\/raspberrypi\/linux.git\r\ncd linux\r\ncp <strong>your\/raspi\/config<\/strong> .config\r\nwget https:\/\/github.com\/raspberrypi\/firmware\/raw\/master\/extra\/Module.symvers\r\nARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig\r\nARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig\r\n# Save.. Exit..\r\nARCH=arm CROSS_COMPILE=${CCPREFIX} make modules_prepare\r\n# Note: can specify -j9 for 8 core compile..<\/pre>\n<p>Well, now that it finally works, I&#8217;m not updating the Pi again until I&#8217;ve finished my driver \ud83d\ude09<\/p>\n<p>Incidentally, here&#8217;s an easy way to find Module.symvers: <a href=\"https:\/\/github.com\/raspberrypi\/firmware\/commits\/master\/extra\/Module.symvers\">https:\/\/github.com\/raspberrypi\/firmware\/commits\/master\/extra\/Module.symvers<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t think I&#8217;m alone on this issue&#8230; it seems almost impossible to build a working kernel driver on the Pi. After much trial and error, and on the verge of giving up completely, I finally succeeded! I started with cross compilation on Ubuntu but couldn&#8217;t get it to work initially, it kept giving &#8220;Invalid &hellip; <a href=\"https:\/\/int03.co.uk\/blog\/2014\/03\/25\/building-kernel-modules-on-the-raspberry-pi-is-ridiculously-hard\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Building Kernel Modules on the Raspberry Pi is Ridiculously Hard!<\/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":[],"_links":{"self":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/116"}],"collection":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":4,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}