KernelBuild » History » Version 15
Denis 'GNUtoo' Carikli, 02/04/2016 01:47 PM
1 | 1 | Denis 'GNUtoo' Carikli | h1. KernelBuild |
---|---|---|---|
2 | |||
3 | 2 | Denis 'GNUtoo' Carikli | h2. Use case |
4 | |||
5 | 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. |
||
6 | |||
7 | 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. |
||
8 | |||
9 | 4 | Denis 'GNUtoo' Carikli | h2. Dependencies |
10 | 1 | Denis 'GNUtoo' Carikli | |
11 | 4 | Denis 'GNUtoo' Carikli | 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. |
12 | |||
13 | 12 | Denis 'GNUtoo' Carikli | The Trisquel ARM version of gcc seem to work well. To install it run: |
14 | <pre> |
||
15 | $ apt-get install gcc-arm-none-eabi |
||
16 | </pre> |
||
17 | 4 | Denis 'GNUtoo' Carikli | |
18 | 1 | Denis 'GNUtoo' Carikli | 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. |
19 | |||
20 | 4 | Denis 'GNUtoo' Carikli | To workaround that you can install Trisquel in a container. |
21 | This way it will have very few CPU and memory overhead compared to a virtual machine. |
||
22 | It will also save disk space since you can just store the Trisquel rootfs in any directory. |
||
23 | |||
24 | 10 | Denis 'GNUtoo' Carikli | h2. Example with crespo under Trisquel |
25 | 1 | Denis 'GNUtoo' Carikli | |
26 | 10 | Denis 'GNUtoo' Carikli | h3. Getting the right parameters |
27 | |||
28 | 6 | Denis 'GNUtoo' Carikli | First download the following example image and its signatures: |
29 | * http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/security/4A80EB23.asc |
||
30 | 5 | Denis 'GNUtoo' Carikli | * http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/images/crespo/replicant-4.2-crespo.zip.asc |
31 | * http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/images/crespo/replicant-4.2-crespo.zip |
||
32 | 1 | Denis 'GNUtoo' Carikli | |
33 | As usual, verify the signature: |
||
34 | 6 | Denis 'GNUtoo' Carikli | <pre> |
35 | 8 | Denis 'GNUtoo' Carikli | $ gpg --import 4A80EB23.asc |
36 | $ gpg --verify replicant-4.2-crespo.zip.asc |
||
37 | 6 | Denis 'GNUtoo' Carikli | </pre> |
38 | It should then say something like: |
||
39 | <pre> |
||
40 | $ gpg --verify replicant-4.2-crespo.zip.asc |
||
41 | gpg: assuming signed data in 'replicant-4.2-crespo.zip' |
||
42 | gpg: Signature made Tue 01 Sep 2015 01:31:47 PM CEST using RSA key ID 4A80EB23 |
||
43 | gpg: Good signature from "Replicant project release key <contact@replicant.us>" [unknown] |
||
44 | gpg: WARNING: This key is not certified with a trusted signature! |
||
45 | gpg: There is no indication that the signature belongs to the owner. |
||
46 | Primary key fingerprint: E776 092B 052A DC91 FDD1 FD80 16D1 FEEE 4A80 EB23 |
||
47 | </pre> |
||
48 | 5 | Denis 'GNUtoo' Carikli | |
49 | 7 | Denis 'GNUtoo' Carikli | Then unpack the zip file: |
50 | <pre> |
||
51 | 8 | Denis 'GNUtoo' Carikli | $ mkdir replicant-4.2-crespo && cd replicant-4.2-crespo && unzip ../replicant-4.2-crespo.zip |
52 | 7 | Denis 'GNUtoo' Carikli | </pre> |
53 | |||
54 | 9 | Denis 'GNUtoo' Carikli | That should have extracted a boot.img. We then should not forget to look at what format the boot.img is in: |
55 | <pre> |
||
56 | $ file boot.img |
||
57 | 1 | Denis 'GNUtoo' Carikli | boot.img: Android bootimg, kernel (0x30008000), ramdisk (0x31000000), page size: 4096, cmdline (console=ttyFIQ0 no_console_suspend) |
58 | </pre> |
||
59 | Here it says it's an "Android bootimg", so we need the following tools: |
||
60 | 10 | Denis 'GNUtoo' Carikli | * mkbootimg to pack an image |
61 | * unbootimg to unpack an image |
||
62 | |||
63 | Ways to get such tools: |
||
64 | * Pre-built by Replicant at http://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/tools/ |
||
65 | * Build Replicant and use its tools. That defeat the purpose here since we want to avoid building Replicant fully. |
||
66 | |||
67 | Some android tools were converted to build on GNU/Linux without requiring the Android build system. |
||
68 | * In git://git.freesmartphone.org/utilities.git you have adb in android/adb, mkbootimg and unbootimg in android/image-utils |
||
69 | |||
70 | Some GNU/Linux distributions also have packages for some of the tools. |
||
71 | 9 | Denis 'GNUtoo' Carikli | |
72 | 11 | Denis 'GNUtoo' Carikli | Now we can finally get the right parameters that we will use later to rebuild a boot.img |
73 | 1 | Denis 'GNUtoo' Carikli | <pre> |
74 | 11 | Denis 'GNUtoo' Carikli | $ unbootimg -i boot.img |
75 | total image size: 3100672 |
||
76 | kernel size: 2903532 |
||
77 | kernel load addr: 0x30008000 |
||
78 | ramdisk size: 189142 |
||
79 | ramdisk load addr: 0x31000000 |
||
80 | 2nd boot size: 0 |
||
81 | 2nd boot load addr: 0x30f00000 |
||
82 | kernel tags addr: 0x30000100 |
||
83 | page size: 4096 |
||
84 | board: `' |
||
85 | cmdline: `console=ttyFIQ0 no_console_suspend' |
||
86 | id: bd59d387bf083b0946e25a8f17f1aaef4bcc7412000 |
||
87 | </pre> |
||
88 | |||
89 | h3. Building |
||
90 | |||
91 | 14 | Denis 'GNUtoo' Carikli | If you want to be able to run "make menuconfig", install libncurses5-dev: |
92 | <pre> |
||
93 | # apt-get install libncurses5-dev |
||
94 | </pre> |
||
95 | |||
96 | 13 | Denis 'GNUtoo' Carikli | Download the sources: |
97 | 11 | Denis 'GNUtoo' Carikli | <pre> |
98 | 4 | Denis 'GNUtoo' Carikli | $ git clone https://git.replicant.us/replicant/kernel_samsung_crespo.git |
99 | 1 | Denis 'GNUtoo' Carikli | </pre> |
100 | 13 | Denis 'GNUtoo' Carikli | |
101 | Then in each console you build from, do: |
||
102 | <pre> |
||
103 | export ARCH=arm |
||
104 | export CROSS_COMPILE=arm-none-eabi- |
||
105 | </pre> |
||
106 | |||
107 | Configure it for crespo: |
||
108 | <pre> |
||
109 | $ make crespo_defconfig |
||
110 | </pre> |
||
111 | |||
112 | 14 | Denis 'GNUtoo' Carikli | If you want to configure it furthurer: |
113 | <pre> |
||
114 | $ make menuconfig |
||
115 | </pre> |
||
116 | |||
117 | 13 | Denis 'GNUtoo' Carikli | Then build a zImage: |
118 | <pre> |
||
119 | $ make -j4 zImage |
||
120 | </pre> |
||
121 | 11 | Denis 'GNUtoo' Carikli | |
122 | 15 | Denis 'GNUtoo' Carikli | If the compilation succedded, the image is at: |
123 | <pre> |
||
124 | arch/arm/boot/zImage |
||
125 | </pre> |
||
126 | |||
127 | h3. Building Failures |
||
128 | |||
129 | 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. |
||
130 | |||
131 | As a result, variations in the default kernel configuration for your device can result in build errors. |
||
132 | |||
133 | Compilation failures can also happen when you use another gcc version, like we do in this guide. |
||
134 | This happens frequently if you use a gcc that is more recent than your kernel. |
||
135 | The "not very clean code" also increase the probability of it. |
||
136 | |||
137 | 11 | Denis 'GNUtoo' Carikli | h3. Repacking |
138 | |||
139 | h3. Testing |