{"id":6,"date":"2013-01-31T12:00:27","date_gmt":"2013-01-31T12:00:27","guid":{"rendered":"http:\/\/nofl.biz\/blog\/?p=1"},"modified":"2013-01-31T12:00:27","modified_gmt":"2013-01-31T12:00:27","slug":"hello-world-2","status":"publish","type":"post","link":"https:\/\/beneford.com\/Blog\/index.php\/2013\/01\/31\/hello-world-2\/","title":{"rendered":"Raspberry Pi &#8211; Setting up driver\/module development environment"},"content":{"rendered":"<div>Abstract: This post gives the steps required to set up a cross-compiling development environment for <a title=\"Raspberry Pi\" href=\"http:\/\/raspberrypi.org\" target=\"_blank\" rel=\"noopener\">Raspberry Pi<\/a>.<\/div>\n<div>The base platform is a Linux computer (examples are given for a SuSE 12.2 installation running as a virtual computer on\u00a0SuSE 12.2 using KVM as the hypervisor).<\/div>\n<ol>\n<li>Installing some prerequisites:\n<ol>\n<li>git (use to access the source code repositories)<br \/>\nOn SuSE, use <code>YaST<\/code> to install if it&#8217;s not already there<br \/>\nOn Debian, use <code>apt-get git<\/code> to install<\/li>\n<li>Create your base directory: we will use ~\/Projects<\/li>\n<\/ol>\n<\/li>\n<li>Installing a cross-compiler:\n<ol>\n<li>Download and compile the latest crosstool-ng from crosstool-ng.org (you will need to be root for the final <code>make install<\/code>)<br \/>\n<code>wget crosstool-ng.org\/download\/crosstool-ng\/crosstool-ng-1.17.0.tar.bz2<br \/>\ntar -xvz crosstool-ng-1.17.0.tar.bz2<br \/>\ncd crosstool-ng-1.17.0<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install<\/code><\/li>\n<li>Configure a cross compiler<br \/>\n<code>mkdir ~\/Projects\/souce\/ccc;cd ~\/Projects\/souce\/ccc<br \/>\nct-ng menuconfig<\/code><br \/>\nThe cross compiler configuration requires the following settings:<\/p>\n<table>\n<tbody>\n<tr>\n<td>Section<\/td>\n<td>Setting<\/td>\n<\/tr>\n<tr>\n<td>Paths and misc<\/td>\n<td>[x] Try features marked as EXPERIMENTAL)<br \/>\n(\/tools\/x-tools\/${CT_TARGET}) Prefix directory<\/td>\n<\/tr>\n<tr>\n<td>Target options<\/td>\n<td>Target Architecture (arm)<br \/>\nEndianness: (Little endian)<br \/>\nBitness: (32-bit)<\/td>\n<\/tr>\n<tr>\n<td>Operating System<\/td>\n<td>Target OS (linux)<br \/>\nLinux kernel version (3.?.?) &#8211; use the correct value!<\/td>\n<\/tr>\n<tr>\n<td>Binary utilities<\/td>\n<td>binutils version: choose the latest not marked EXPERIMENTAL<\/td>\n<\/tr>\n<tr>\n<td>C Compiler<\/td>\n<td>[x] Show Linaro vesions (EXPERIMENTAL)<br \/>\ngcc version &#8211; choose one of the Lenaro versions: 4.6-2-12.04 does work<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>Exit from ct-ng menu configuration.<\/div>\n<\/li>\n<li>Build a cross-compiler.\n<div>As root (or with sudo prefix):<br \/>\n<code>ct-ng buid<\/code><\/div>\n<div>Note: if build fails with a message about Static linking impossible, edit the .config file and change CT_WANTS_STATIC_LINKING=n and try again.<br \/>\nThe compiler will be in \/tools\/x-tools\/arm-unknown-linux-gnueabi<br \/>\nThe build takes quite a while&#8230; (42 minutes on a single core of i5-2500 at 3.3GHz)<\/div>\n<\/li>\n<\/ol>\n<\/li>\n<li>Installing the Linux Kernel Sources (which are required for compiling modules and drivers):\n<ol>\n<li>Create a source directory ~\/Projects\/source an running the following commands from that directory:<\/li>\n<li><code>git clone git:\/\/github.com\/raspberrypi\/linux.git<\/code><\/li>\n<li><code>git clone git:\/\/github.com\/raspberrypi\/firmware.git<\/code><\/li>\n<li><code>git clone git:\/\/github.com\/raspberrypi\/tools.git<\/code><\/li>\n<\/ol>\n<div>You will now have three directories under ~\/Projects\/source: linux, firmware and tools.<\/div>\n<\/li>\n<li>Set\u00a0the right version of the Linux Kernel &#8211; which needs to be the same version you are using on the RaspberryPi.<br \/>\nYou can find the version RaspberryPi is running using the command:<\/p>\n<pre>raspberrypi:~&gt; uname -sr\nLinux 3.2.27+<\/pre>\n<div>You can see the available\u00a0versions of the Linux kernel by:<\/div>\n<pre>rpidev:~&gt; cd ~\/Projects\/source\/linux\nrpidev:linux&gt; git branch -r\n  origin\/HEAD -&gt; origin\/rpi-3.6.y\n  origin\/master\n  origin\/rpi-3.2.27\n  origin\/rpi-3.6.y\n  origin\/rpi-patches<\/pre>\n<div>You can set the version to rpi-3.2.27\u00a0using:<br \/>\n<code>git checkout rpi-3.2.27<\/code><\/div>\n<ul>\n<li>ARM System Type=Broadcom BCM2708 family<\/li>\n<\/ul>\n<ul><\/ul>\n<\/li>\n<div>When changing the kernel version, you need to initialize it. This process will remove the .config file, so it&#8217;s a good idea to keep a copy in (eg) ..\/linux.config<br \/>\n<code>make mrproper<\/code><\/div>\n<div>\n<div>To set the configuration, use one or more of the following<\/div>\n<ul>\n<li>Copy from your backup: <code>cp ..\/linux.config .config<\/code><\/li>\n<li>Get it from the Raspberry Pi <code>ssh root@rpi zcat \/proc\/config &gt; .config<\/code><\/li>\n<li>Check the configuration:  <code>make ARCH=arm CROSS_COMPILE=\/tools\/x-tools\/arm-unknown-linux-gnueabi\/bin\/arm-unknown-linux-gnueabi- oldconfig<\/code><br \/>\nThis will prompt you to confirm any new options &#8211; use the default except for:<\/li>\n<\/ul>\n<\/div>\n<li>Edit the configuration:  <code>make ARCH=arm CROSS_COMPILE=\/tools\/x-tools\/arm-unknown-linux-gnueabi\/bin\/arm-unknown-linux-gnueabi- menuconfig<\/code><br \/>\nSome areas you might want to configure (especially if you&#8217;re planning to use this kernel on the device):<\/p>\n<ul>\n<li>Floating Point emulation: you need one emulation set<\/li>\n<li>Networking support (enable for more, disable for smaller)<\/li>\n<li>Device drivers (enable for more, disable for smaller)<\/li>\n<\/ul>\n<\/li>\n<div>You can check the version your source code tree is at using:<br \/>\n<code>make kernelversion<\/code><\/div>\n<li>Build the kernel using: (-j2 means use 2 core in parallel)<br \/>\n<code>make ARCH=arm CROSS_COMPILE=\/tools\/x-tools\/arm-unknown-linux-gnueabi\/bin\/arm-unknown-linux-gnueabi- -j2<\/code><\/li>\n<li>To compile my_module, use the following makefile:<br \/>\n<code>obj-m:=mymodule.o<\/code><br \/>\nAnd compile with:<br \/>\nmake ARCH=arm CROSS_COMPILE=\/tools\/x-tools\/arm-unknown-linux-gnueabi\/bin\/arm-unknown-linux-gnueabi- -C ~\/Projects\/source\/linux SUBDIRS=`pwd` modules\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Abstract: This post gives the steps required to set up a cross-compiling development environment for Raspberry Pi. The base platform is a Linux computer (examples are given for a SuSE 12.2 installation running as a virtual computer on\u00a0SuSE 12.2 using KVM as the hypervisor). Installing some prerequisites: git (use to access the source code repositories) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":0,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"wp:attachment":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}