{"id":935,"date":"2013-11-16T10:54:59","date_gmt":"2013-11-16T10:54:59","guid":{"rendered":"http:\/\/rglinuxtech.com\/?p=935"},"modified":"2013-11-16T10:54:59","modified_gmt":"2013-11-16T10:54:59","slug":"howto-cross-compiling-for-arm-one-method","status":"publish","type":"post","link":"https:\/\/rglinuxtech.com\/?p=935","title":{"rendered":"Howto:  Cross-Compiling for ARM &#8211; One Method.."},"content":{"rendered":"<p>I originally wrote an article on cross-compiling for <strong>ARM<\/strong> systems, some time ago &#8211; before I got my first Raspberry Pi &#8211; and this is a more up-to-date version.<\/p>\n<p>This is how I cross-compile ARM kernels, on x86_64.\u00a0 There are &#8211; of course &#8211; other ways of doing this, but this works, for me..<br \/>\nThe following info assumes that you are already familiar with compiling your own Linux kernels..<\/p>\n<p>For the cross-compiler and associated system files, I found the set for <strong>Mandriva<\/strong> works fine, and installed OK on my Fedora x86_64 systems, and is suitable for producing kernels for armv5 (DreamPlug) and armv6 (Raspberry Pi) systems, as well as armv7..:<\/p>\n<p><a title=\"http:\/\/fr2.rpmfind.net\/\/linux\/RPM\/mandriva\/devel\/cooker\/x86_64\/media\/contrib\/release\/cross-armv7hl-2011.10-1.x86_64.html\" href=\"http:\/\/fr2.rpmfind.net\/\/linux\/RPM\/mandriva\/devel\/cooker\/x86_64\/media\/contrib\/release\/cross-armv7hl-2011.10-1.x86_64.html\" target=\"_blank\">http:\/\/fr2.rpmfind.net\/\/linux\/RPM\/mandriva\/devel\/cooker\/x86_64\/media\/contrib\/release\/cross-armv7hl-2011.10-1.x86_64.html<\/a><\/p>\n<p><strong>cross-armv7hl-c++-2011.10-1.x86_64<\/strong><br \/>\n<strong>cross-armv7hl-binutils-2011.10-1.x86_64<\/strong><br \/>\n<strong>cross-armv7hl-2011.10-1.x86_64<\/strong><br \/>\n<strong>cross-armv7hl-gdb-2011.10-1.x86_64<\/strong><br \/>\n<strong>cross-armv7hl-host-2011.10-1.x86_64<\/strong><br \/>\n<strong>cross-armv7hl-gcc-2011.10-1.x86_64<\/strong><\/p>\n<p>I run Fedora (and &#8211; now &#8211; Pidora) on all my Linux systems, but &#8211; of course &#8211; there are similar cross-compiler toolchains available for Debian, Arch Linux, Gentoo, and other distros..<\/p>\n<p>I \u2013 personally \u2013 don\u2019t use the # make&#8230;. ARCH=ARM&#8230; method, but instead I modify the top-level Makefile, as I wanted the kernel and modules etc. to all be resident in a local directory..\u00a0\u00a0 One point to mention is that &#8211; assuming this is all somewhere in your ~\/home directory &#8211; the compilation can be run as a normal user..<\/p>\n<p>This example is for the Raspberry Pi, but the compilation stage is the same for other arm systems, with UBoot etc.\u00a0\u00a0\u00a0 For arm systems which can use the standard mainstream kernel, such as the DreamPlug, boot image creation has recently changed to use the &#8216;device tree&#8217;, dtbs, mkimage etc. but that is outside the scope of this particular article!<\/p>\n<p>First, unpack the kernel source (from github..) in its own directory (raspberrypi-312 in the example below..).\u00a0\u00a0 Remember <span style=\"text-decoration: underline;\">not<\/span> to use the &#8216;download zip&#8217; option (see previous article)..<br \/>\nThen create a \u2018lib\u2019 (sub)directory there.<\/p>\n<p>Then edit the top-level Makefile, as follows (changing the armvxx\u2026\u2026. description to suite your particular cross-compiler installation, if different..)<\/p>\n<pre>around line 195:\r\n\u00a0change:\r\n\u00a0<strong>ARCH\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ?= $(SUBARCH)<\/strong>\r\n<strong>\u00a0CROSS_COMPILE\u00a0\u00a0 ?= $(CONFIG_CROSS_COMPILE:\"%\"=%)<\/strong>\r\n\u00a0to:\r\n\u00a0<strong>ARCH\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ?= arm<\/strong>\r\n<strong>\u00a0CROSS_COMPILE\u00a0\u00a0 ?= armv7l-mandriva-linux-gnueabi-<\/strong>\r\n-------------------------------------------------<strong>^<\/strong>\r\nDon't forget the <strong>dash<\/strong> at the end, so the compile process will find\r\nthe correct version of gcc..<\/pre>\n<p>To install modules etc. locally &#8211; under the ..\/lib directory,<br \/>\nedit\u00a0 Makefile:<\/p>\n<pre>around line 6<em>95<\/em>:\r\n\u00a0change:\r\n\u00a0<strong>export\u00a0\u00a0\u00a0 INSTALL_PATH ?= \/boot<\/strong>\r\n\u00a0to:\r\n\u00a0<strong>export\u00a0\u00a0\u00a0 INSTALL_PATH ?= ..\/boot<\/strong>\r\n\u00a0and add:\r\n\u00a0<strong>export\u00a0\u00a0\u00a0 INSTALL_MOD_PATH ?= ..\/<\/strong>\r\n- then run\u00a0\u00a0 <em><strong># make xconfig<\/strong><\/em>\u00a0\u00a0 (or whatever you prefer...)\r\n\u00a0<em><strong># make<\/strong><\/em>\r\n\u00a0and..\u00a0\u00a0 <em><strong># make modules_install<\/strong><\/em>\r\n\r\nDo not run # make install!<\/pre>\n<p>The Pi uses a kernel.img file, along with some binary \u2018firmware\u2019 files (for the GPU) and config files, residing in the fat partition.<\/p>\n<p>So, the whole kernel (compiled) source \/ lib \/ kernel.img package directory structure looks like:<\/p>\n<pre><strong>raspberrypi-312<\/strong>\u00a0 \r\n\u00a0|\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0 |\r\n\u00a0|\u00a0\u00a0 |\u00a0\u00a0\u00a0 <strong>tools<\/strong> (containing kernel.img file)\r\n\u00a0|\u00a0\u00a0 |\r\n\u00a0|\u00a0\u00a0 <strong>linux<\/strong> (containing compiled kernel source)\r\n\u00a0|\r\n\u00a0<strong>lib<\/strong> (containing modules and firmware directories created by the\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 kernel compilation)<\/pre>\n<p>Then copy the <strong><em>kernel.img<\/em><\/strong> file to the boot (FAT) partition, to be accessed by the bootloader, and copy the directories\/files from the ..\/lib\/modules and ..\/lib\/firmware directories to the corresponding directories on the root (EXT3 or 4) directory on the SD Card.<\/p>\n<p>Usual disclaimer \u2013 This works on my system (Currently Fedora 20, Kernel 3.12)\u00a0 It may not on yours.<\/p>\n<p><em>Robert Gadsdon..\u00a0 November 16, 2013.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I originally wrote an article on cross-compiling for ARM systems, some time ago &#8211; before I got my first Raspberry Pi &#8211; and this is a more up-to-date version. This is how I cross-compile ARM kernels, on x86_64.\u00a0 There are &#8211; of course &#8211; other ways of doing this, but this works, for me.. The following info <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/rglinuxtech.com\/?p=935\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[91,5,10,11,14,16,19,21],"tags":[1174,131,710,191,367],"class_list":["post-935","post","type-post","status-publish","format-standard","hentry","category-arm","category-compilation","category-fedora","category-hacks","category-kernel","category-linux-arm","category-opinion","category-raspberry-pi","tag-arm","tag-cross-compile","tag-example","tag-howto","tag-toolchain"],"_links":{"self":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=935"}],"version-history":[{"count":1,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/935\/revisions"}],"predecessor-version":[{"id":936,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/935\/revisions\/936"}],"wp:attachment":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}