100% found this document useful (1 vote)
211 views

Cross-Compiling Linux Kernels On x86 - 64: A Tutorial On How To Get Started

This document provides a tutorial on how to set up a cross-compilation environment to compile Linux kernels for different architectures like ARM, ARM64, Blackfin, and others. It discusses the benefits of cross-compilation, downloading necessary packages and compilers, configuring the system, and demonstrates how to cross-compile and test builds for ARM and ARM64. Instructions are also provided for automating cross-compile testing.

Uploaded by

Shivam Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
211 views

Cross-Compiling Linux Kernels On x86 - 64: A Tutorial On How To Get Started

This document provides a tutorial on how to set up a cross-compilation environment to compile Linux kernels for different architectures like ARM, ARM64, Blackfin, and others. It discusses the benefits of cross-compilation, downloading necessary packages and compilers, configuring the system, and demonstrates how to cross-compile and test builds for ARM and ARM64. Instructions are also provided for automating cross-compile testing.

Uploaded by

Shivam Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

"ross#compiling Linux Kernels on x$%&%'( A )u)orial on *o+ )o Ge) S)ar)e,

Shuah Khan Senior Linux Kernel Developer Open Source Group Samsung Research America (Silicon Valley)
shuah. h!samsung.com

Agenda

Cross-compile value proposition Preparing the system for cross-compiler installation Cross-compiler installation steps Demo install arm and arm64 Compiling on architectures Demo compile arm and arm64 Automating cross-compile testing Upstream cross-compile testing activity References and Package repositories !A

Cross-compile value proposition

"#$ architectures supported %several su&-archs' (ative compile testing re)uires *ide range of test systems not practical A&ility to cross-compile non-natively on an *idely availa&le architecture helps detect compile errors Coupled *ith emulation environments %e+g, )emu' testing on non-native architectures &ecomes easier -etting up cross-compile environment is the first and necessary step

arch.
alpha frv arc h8300 arm hexagon arm64 ia64 avr32 m32r blackfin m68k c6x metag cris powerpc parisc tile openrisc sparc mn10300 sh x86 mips score unicore32 xtensa microblaze s390 um x86_64

Cross-compiler packages

U&untu arm packages %/0+/# or later'


gcc-arm-linu1-gnuea&i gcc-arm-linu1-gnuea&ihf

U&untu arm64 packages %/"+#4 or later' use arm64 repo for older U&untu releases+

gcc-4+2-aarch64-linu1-gnu

U&untu keeps adding support for compilers+ -earch U&untu repository for packages+

Cross-compiler packages

3m&edded De&ian Pro4ect is a good resource for alpha5 mips5 mipsel5 po*erpc5 sh5 and sparc cross-compilers+

gcc-4+2-alpha-linu1-gnu gcc-4+2-mips-linu1-gnu gcc-4+2-mipsel-linu1-gnu gcc-4+2-po*erpc-linu1-gnu gcc-4+2-sh4-linu1-gnu gcc-4+2-sparc-linu1-gnu

Cross-compiler packages

6edora repo and 6edora 3pel Repo are a good sources for several cross-compilers and &inutils rpms

&lackfin &inutils-&fin-linu1-gnu-0+0"+7/+#+"-/+fc/2+186964+rpm gcc-&fin-linu1-gnu-4+2+/-#+/+0#/0#6#6+fc/2+186964+rpm c61


&inutils-c61-linu1-gnu-0+0"+7/+#+"-/+fc/2+186964+rpm gcc-c61-linu1-gnu-4+2+0-0+aa+0#/0///4svn+fc/2+186964+rpm &inutils-tile-linu1-gnu-0+0"+7/+#+"-/+fc/2+186964+rpm gcc-tile-linu1-gnu-4+2+0-0+aa+0#/0///4svn+fc/2+186964+rpm

tile

Preparing the system for cross-compiler installation

Choose an 186-64 system :nstall U&untu /0+/# or later+

U&untu /"+#4 :nstall

:nstall common packages


su o!apt"get!install!buil "essential

su o!apt"get!install!binutils"multiarch

su o!apt"get!install!ncurses" ev

su o!apt"get!install!alien

#ote$!ncurses" ev!is!re%uire !to!run!menuconfig!an !alien!to!generate!& eb!from!&rpm

Configure apt for arm64 repo %U&untu /0+/#'


wget!"'!"!http$((people& ebian&org()wooke*(bootstrap(bootstrap"archive&ke*!+!su o!apt"ke*!a

su o!apt"a

"repositor*!, eb!http$((people& ebian&org()wooke*(bootstrap(ubunturepo(!%uantal"bootstrap!main,

su o!apt"get!up ate

Configure apt for emde&ian repo

su o!apt"get!install!em ebian"archive"ke*ring

-reate!(etc(apt(sources&list& (em ebian&list!file!with!the!following!line$ !!! eb!http$((www&em ebian&org( ebian(!si !main

Do*nload rpms from fedora repo

&lackfin rpms,

&inutils-&fin-linu1-gnu-0+0"+7/+#+"-/+fc/2+186964+rpm gcc-&fin-linu1-gnu-4+2+/-#+/+0#/0#6#6+fc/2+186964+rpm &inutils-c61-linu1-gnu-0+0"+7/+#+"-/+fc/2+186964+rpm gcc-c61-linu1-gnu-4+2+0-0+aa+0#/0///4svn+fc/2+186964+rpm &inutils-tile-linu1-gnu-0+0"+7/+#+"-/+fc/2+186964+rpm gcc-tile-linu1-gnu-4+2+0-0+aa+0#/0///4svn+fc/2+186964+rpm (ote, gcc-tile-linu1-gnu-4+2+0-0+aa+0#/0///4svn+fc/2+186964+rpm is *hat you *ant+ ;he older version is missing feed&ack+h5 tileg1 needs+

c61 rpms,

tile rpms

Convert rpms to +de&


su o!alien!" !binutils"bfin"linux"gnu"2&23&.1&0&3"1&fc1/&x86_64&rpm su o!alien!" !gcc"bfin"linux"gnu"4&/&1"0&1&20120606&fc1/&x86_64&rpm

su o!alien!" !binutils"c6x"linux"gnu"2&23&.1&0&3"1&fc1/&x86_64&rpm su o!alien!" !gcc"c6x"linux"gnu"4&/&2"2&aa&20121114svn&fc1/&x86_64&rpm su o!alien!" !binutils"tile"linux"gnu"2&23&.1&0&3"1&fc1/&x86_64&rpm su o!alien!" !gcc"tile"linux"gnu"4&/&2"2&aa&20121114svn&fc1/&x86_64&rpm

You will see warnings about missing keys e.g: below which you can safely ignore. warning: gcc-tile-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x !"!4.r#m: $ea%er &' ()*+)$*2,! )ignature- key ./ 1aca'4!,: 0123Y

Resulting +de&s

&inutils-&fin-linu1-gnu90+0"+7/+#+"-09amd64+de& &inutils-c61-linu1-gnu90+0"+7/+#+"-09amd64+de& &inutils-tile-linu1-gnu90+0"+7/+#+"-09amd64+de& gcc-&fin-linu1-gnu94+2+/-/+/9amd64+de& gcc-c61-linu1-gnu94+2+0-"9amd64+de& gcc-tile-linu1-gnu94+2+0-"9amd64+de&

:nstall cross-compilers
alpha su o!apt"get!install!""install"recommen s!gcc"4&/"alpha"linux"gnu !!!su o!ln!"s!(usr(bin(alpha"linux"gnu"gcc"4&/!(usr(bin(alpha"linux"gnu"gcc arm su o!apt"get!install!gcc"arm"linux"gnueabi arm64 su o!apt"get!install!""install"recommen s!gcc"4&/"aarch64"linux"gnu !!!su o!ln!"s!(usr(bin(aarch64"linux"gnu"gcc"4&/!(usr(bin(aarch64"linux"gnu"gcc mips su o!apt"get!install!""install"recommen s!gcc"4&/"mips"linux"gnu !!!su o!ln!"s!(usr(bin(mips"linux"gnu"gcc"4&/!(usr(bin(mips"linux"gnu"gcc mipsel su o!apt"get!install!""install"recommen s!gcc"4&/"mipsel"linux"gnu !!!su o!ln!"s!(usr(bin(mipsel"linux"gnu"gcc"4&/!(usr(bin(mipsel"linux"gnu"gcc

:nstall cross-compilers
powerpc su o!apt"get!install!""install"recommen s!gcc"4&/"powerpc"linux"gnu !!!su o!ln!"s!(usr(bin(powerpc"linux"gnu"gcc"4&/!(usr(bin(powerpc"linux"gnu"gcc sh su o!apt"get!install!""install"recommen s!gcc"4&/"sh4"linux"gnu !!!su o!ln!"s!(usr(bin(sh4"linux"gnu"gcc"4&/!(usr(bin(sh4"linux"gnu"gcc arm64 su o!apt"get!install!""install"recommen s!gcc"4&/"aarch64"linux"gnu !!!su o!ln!"s!(usr(bin(aarch64"linux"gnu"gcc"4&/!(usr(bin(aarch64"linux"gnu"gcc sparc su o!apt"get!install!""install"recommen s!gcc"4&/"sparc"linux"gnu !!!su o!ln!"s!(usr(bin(sparc"linux"gnu"gcc"4&/!(usr(bin(sparc"linux"gnu"gcc Note: Creating link to *arch*-linux-gnu-gcc is necessary as the CROSS_COMPILE irecti!e to "in the co#$ilers%

:nstall cross-compilers from +de&s


blackfin su o! pkg!"i!binutils"bfin"linux"gnu_2&23&.1&0&3"2_am 64& eb su o! pkg!"i!gcc"bfin"linux"gnu_4&/&1"1&1_am 64& eb !!

c6x su o! pkg!"i!binutils"c6x"linux"gnu_2&23&.1&0&3"2_am 64& eb !!!su o! pkg!"i!gcc"c6x"linux"gnu_4&/&2"3_am 64& eb

tile su o! pkg!"i!binutils"tile"linux"gnu_2&23&.1&0&3"2_am 64& eb !!!su o! pkg!"i!gcc"tile"linux"gnu_4&/&2"3_am 64& eb

arch.compile
alpha frv arc h8300 arm hexagon arm64 ia64 avr32 m32r blackfin m68k c6x metag cris powerpc parisc tile openrisc sparc mn10300 sh x86 mips score unicore32 xtensa microblaze s390 um x86_64

<uilding from sources

=auro Cheha&>s &uild9cross script

do*nloads compiler sources for a specified arch from gnu repo5 &uilds and installs+ Usage, &uild9cross arm Runs on fedora

Demo arm and arm64 install

Compilation ;ips

:f make ARC?@arch defconfig fails on an arch5 pick a config to test from arch.A.configs -ome architectures don>t support defconfig in cross-compile mode+ e+g, po*erpc+ :n some cases5 you might see errors in BD phase5 and please keep in mind these are 4ust compile tests+

Cross-compiling
alpha make! istclean !!!make!01-23alpha! efconfig !!!01-23alpha!-1'44_-'567893alpha"linux"gnu"!make!all arm make! istclean !!!make!01-23arm! efconfig !!!01-23arm!-1'44_-'567893arm"linux"gnueabi"!make!all arm64!:3&/!an !later; make! istclean make!01-23arm64! efconfig !!!01-23arm64!-1'44_-'567893aarch64"linux"gnu"!make!all blackfin make! istclean make!01-23blackfin! efconfig 01-23blackfin!-1'44_-'567893bfin"linux"gnu"!make!all

Cross-compiling
c6x!:3&4!an !later; make! istclean make!01-23c6x! efconfig !!!01-23arm64!-1'44_-'567893aarch64"linux"gnu"!make!all mips make! istclean !!!make!01-23mips! efconfig !!!01-23mips!-1'44_-'567893mips"linux"gnu"!make!all mipsel make! istclean !!!make!01-23mips! efconfig !!!01-23mips!-1'44_-'567893mipsel"linux"gnu"!make!all powerpc make! istclean !!!cp!arch(powerpc(configs(wii_ efconfig!&config !!!01-23powerpc!-1'44_-'567893powerpc"linux"gnu"!make!all

Cross-compiling
sh make! istclean !!!make!01-23sh! efconfig !!!01-23sh!-1'44_-'567893sh4"linux"gnu"!make!all

sparc make! istclean !!!make!01-23sparc! efconfig !!!01-23sparc!-1'44_-'567893sparc"linux"gnu"!make!all

tile make! istclean !!!make!01-23tile! efconfig !!!01-23tile!-1'44_-'567893tile"linux"gnu"!make!all

Demo arm and arm64 compilation

Automating cross-compile testing

-cript cross9compile+sh automates &uilds for the compilers mentioned in this talk ktest crosstests+conf <uild&ot tool for automating soft*are &uilds+ :t can &e configured to checkout Binu1 kernel sources from git repos and &uild+

Upstream Cross-compile testing activity

Binu1 Cernel sta&le )ueue &uilds pro4ect

Duenter Rock keeps adding ne* compilers each *eek+ Configs, allmodconfig5 defconfig5 configs *ith mmu and *ithout %nommu' *here applica&le+ )emu test results on selected architectures+

References and Package repositories

AR=v8 De&ian and U&untu &ootstrap repositories 3m&edded De&ian Pro4ect 6edora Repo 6edora 3pel Repo Cernel+org - crosstool U&untu /"+#4 :nstall <uild&ot Binu1 Cernel sta&le )ueue &uilds pro4ect Ctest

Q&A

-han you.

Shuah Khan Senior Open Source Developer Open Source Group Samsung Research America (Silicon Valley)
shuah. h!samsung.com

-ummary

Cross-compiling Binu1 Cernels on 186964, A tutorial on ?o* to Det -tarted Agenda Cross-compile value proposition arch. Cross-compiler packages Cross-compiler packages Cross-compiler packages Preparing the system for cross-compiler installation :nstall common packages Configure apt for arm64 repo %U&untu /0+/#' Configure apt for emde&ian repo Do*nload rpms from fedora repo Convert rpms to +de& Resulting +de&s :nstall cross-compilers :nstall cross-compilers :nstall cross-compilers from +de&s arch.compile <uilding from sources Compilation ;ips Cross-compiling Cross-compiling Cross-compiling Automating cross-compile testing Upstream Cross-compile testing activity References and Package repositories ;hank you+

You might also like