Project

General

Profile

KernelBuild » History » Revision 15

Revision 14 (Denis 'GNUtoo' Carikli, 02/04/2016 10:53 AM) → Revision 15/41 (Denis 'GNUtoo' Carikli, 02/04/2016 01:47 PM)

h1. KernelBuild 

 h2. Use case 

 Building a kernel aside Replicant, is faster to setup and faster to build since you need to fetch and use the huge Android build system. 

 Users wanting to add a driver to their kernel, or developers that want to work on kernel related areas can do that to speed up the development process, however if the changes are integrated back into Replicant, they will automatically be built by the Android build system, when building images. 

 h2. Dependencies  

 Since you are not compiling any userspace applications, you don't need the Android build system. The Linux Kenrel, and Bootloaders such as uboot can be built without the Android build system. 

 The Trisquel ARM version of gcc seem to work well. To install it run: 
 <pre> 
 $ apt-get install gcc-arm-none-eabi 
 </pre> 

 If you use distributions such as Parabola, this will probably not work because the arm-none-eabi-gcc is too recent for many devices kernels. 

 To workaround that you can install Trisquel in a container. 
 This way it will have very few CPU and memory overhead compared to a virtual machine. 
 It will also save disk space since you can just store the Trisquel rootfs in any directory. 

 h2. Example with crespo under Trisquel 

 h3. Getting the right parameters 

 First download the following example image and its signatures: 
 * http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/security/4A80EB23.asc 
 * http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/images/crespo/replicant-4.2-crespo.zip.asc 
 * http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/images/crespo/replicant-4.2-crespo.zip 

 As usual, verify the signature: 
 <pre> 
 $ gpg --import 4A80EB23.asc 
 $ gpg --verify replicant-4.2-crespo.zip.asc 
 </pre> 
 It should then say something like: 
 <pre> 
 $ gpg --verify replicant-4.2-crespo.zip.asc  
 gpg: assuming signed data in 'replicant-4.2-crespo.zip' 
 gpg: Signature made Tue 01 Sep 2015 01:31:47 PM CEST using RSA key ID 4A80EB23 
 gpg: Good signature from "Replicant project release key <contact@replicant.us>" [unknown] 
 gpg: WARNING: This key is not certified with a trusted signature! 
 gpg:            There is no indication that the signature belongs to the owner. 
 Primary key fingerprint: E776 092B 052A DC91 FDD1    FD80 16D1 FEEE 4A80 EB23 
 </pre> 

 Then unpack the zip file: 
 <pre> 
 $ mkdir replicant-4.2-crespo && cd replicant-4.2-crespo && unzip ../replicant-4.2-crespo.zip 
 </pre> 

 That should have extracted a boot.img. We then should not forget to look at what format the boot.img is in: 
 <pre> 
 $ file boot.img 
 boot.img: Android bootimg, kernel (0x30008000), ramdisk (0x31000000), page size: 4096, cmdline (console=ttyFIQ0 no_console_suspend) 
 </pre> 
 Here it says it's an "Android bootimg", so we need the following tools: 
 * mkbootimg to pack an image  
 * unbootimg to unpack an image 

 Ways to get such tools: 
 * Pre-built by Replicant at http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/tools/ 
 * Build Replicant and use its tools. That defeat the purpose here since we want to avoid building Replicant fully. 

 Some android tools were converted to build on GNU/Linux without requiring the Android build system. 
 * In git://git.freesmartphone.org/utilities.git you have adb in android/adb, mkbootimg and unbootimg in android/image-utils 

 Some GNU/Linux distributions also have packages for some of the tools. 

 Now we can finally get the right parameters that we will use later to rebuild a boot.img 
 <pre> 
 $ unbootimg -i boot.img  
 total image size:     3100672 
 kernel size:          2903532 
 kernel load addr:     0x30008000 
 ramdisk size:         189142 
 ramdisk load addr:    0x31000000 
 2nd boot size:        0 
 2nd boot load addr: 0x30f00000 
 kernel tags addr:     0x30000100 
 page size:            4096 
 board:                `' 
 cmdline:              `console=ttyFIQ0 no_console_suspend' 
 id:                   bd59d387bf083b0946e25a8f17f1aaef4bcc7412000 
 </pre> 

 h3. Building 

 If you want to be able to run "make menuconfig", install libncurses5-dev: 
 <pre> 
 # apt-get install libncurses5-dev 
 </pre> 

 Download the sources: 
 <pre> 
 $ git clone https://git.replicant.us/replicant/kernel_samsung_crespo.git 
 </pre> 

 Then in each console you build from, do: 
 <pre> 
 export ARCH=arm 
 export CROSS_COMPILE=arm-none-eabi- 
 </pre> 

 Configure it for crespo: 
 <pre> 
 $ make crespo_defconfig 
 </pre> 

 If you want to configure it furthurer: 
 <pre> 
 $ make menuconfig 
 </pre> 

 Then build a zImage: 
 <pre> 
 $ make -j4 zImage 
 </pre> 

 If the compilation succedded, the image is at: 
 <pre> 
 arch/arm/boot/zImage 
 </pre> 

 h3. Building Failures 

 Many devices specific kernels often contains not very clean code. This is very common with high volume devices due to time to market constraints. Upstream Linux has way higher code quality standards, but having your patches merged there requires more time. 

 As a result, variations in the default kernel configuration for your device can result in build errors. 

 Compilation failures can also happen when you use another gcc version, like we do in this guide. 
 This happens frequently if you use a gcc that is more recent than your kernel. 
 The "not very clean code" also increase the probability of it. 

 h3. Repacking 

 h3. Testing