KernelBuild » History » Version 31
Wolfgang Wiedmeyer, 05/08/2017 08:02 AM
link to release key page (key should be fetched from a keyserver if possible)
1 | 28 | Wolfgang Wiedmeyer | h1. Kernel Build |
---|---|---|---|
2 | 1 | Denis 'GNUtoo' Carikli | |
3 | 2 | Denis 'GNUtoo' Carikli | h2. Use case |
4 | |||
5 | 29 | Wolfgang Wiedmeyer | Building a kernel aside Replicant is faster to set up and faster to build since you do not need to fetch and use the huge Android build system. |
6 | 2 | Denis 'GNUtoo' Carikli | |
7 | 30 | Wolfgang Wiedmeyer | 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. If the changes are integrated back into Replicant, they will automatically be built by the Android build system when building images. |
8 | 2 | Denis 'GNUtoo' Carikli | |
9 | 4 | Denis 'GNUtoo' Carikli | h2. Dependencies |
10 | 1 | Denis 'GNUtoo' Carikli | |
11 | 30 | Wolfgang Wiedmeyer | Since you are not compiling any user space applications, you don't need the Android build system. The Linux kernel and bootloaders such as U-Boot can be built without the Android build system. |
12 | 4 | Denis 'GNUtoo' Carikli | |
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 | 30 | Wolfgang Wiedmeyer | If you use distributions such as Parabola, this will probably not work because the arm-none-eabi-gcc is too recent for many device kernels. But there are efforts to make the kernel sources compatible with more recent compiler versions. |
19 | 1 | Denis 'GNUtoo' Carikli | |
20 | 30 | Wolfgang Wiedmeyer | You can install Trisquel in a container to work around this. |
21 | This way, it will have very few CPU and memory overhead compared to a virtual machine. |
||
22 | 4 | Denis 'GNUtoo' Carikli | 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 | 31 | Wolfgang Wiedmeyer | First download the following example image and its signature: |
29 | 27 | Wolfgang Wiedmeyer | * https://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/images/crespo/replicant-4.2-crespo.zip.asc |
30 | 1 | Denis 'GNUtoo' Carikli | * https://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/images/crespo/replicant-4.2-crespo.zip |
31 | |||
32 | 31 | Wolfgang Wiedmeyer | As usual, verify the signature after [[ReplicantReleaseKey#Replicant-42-and-below|importing the release key]]: |
33 | 6 | Denis 'GNUtoo' Carikli | <pre> |
34 | 31 | Wolfgang Wiedmeyer | $ gpg --armor --verify path/to/replicant-4.2-crespo.zip.asc path/to/replicant-4.2-crespo.zip |
35 | 6 | Denis 'GNUtoo' Carikli | </pre> |
36 | 31 | Wolfgang Wiedmeyer | |
37 | Make sure the check succeeds! |
||
38 | 5 | Denis 'GNUtoo' Carikli | |
39 | 7 | Denis 'GNUtoo' Carikli | Then unpack the zip file: |
40 | <pre> |
||
41 | 8 | Denis 'GNUtoo' Carikli | $ mkdir replicant-4.2-crespo && cd replicant-4.2-crespo && unzip ../replicant-4.2-crespo.zip |
42 | 7 | Denis 'GNUtoo' Carikli | </pre> |
43 | |||
44 | 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: |
45 | <pre> |
||
46 | $ file boot.img |
||
47 | 1 | Denis 'GNUtoo' Carikli | boot.img: Android bootimg, kernel (0x30008000), ramdisk (0x31000000), page size: 4096, cmdline (console=ttyFIQ0 no_console_suspend) |
48 | </pre> |
||
49 | Here it says it's an "Android bootimg", so we need the following tools: |
||
50 | 10 | Denis 'GNUtoo' Carikli | * mkbootimg to pack an image |
51 | * unbootimg to unpack an image |
||
52 | |||
53 | Ways to get such tools: |
||
54 | 27 | Wolfgang Wiedmeyer | * Pre-built by Replicant at https://ftp-osl.osuosl.org/pub/replicant/images/replicant-4.2/0004/tools/ |
55 | 10 | Denis 'GNUtoo' Carikli | * Build Replicant and use its tools. That defeat the purpose here since we want to avoid building Replicant fully. |
56 | |||
57 | Some android tools were converted to build on GNU/Linux without requiring the Android build system. |
||
58 | * In git://git.freesmartphone.org/utilities.git you have adb in android/adb, mkbootimg and unbootimg in android/image-utils |
||
59 | |||
60 | Some GNU/Linux distributions also have packages for some of the tools. |
||
61 | 9 | Denis 'GNUtoo' Carikli | |
62 | 19 | Denis 'GNUtoo' Carikli | Extract the ramdisk and the kernel image and parameters from the original boot.img: |
63 | |||
64 | 1 | Denis 'GNUtoo' Carikli | <pre> |
65 | 19 | Denis 'GNUtoo' Carikli | $ unbootimg --kernel kernel.img --ramdisk ramdisk.img -i boot.img |
66 | 11 | Denis 'GNUtoo' Carikli | total image size: 3100672 |
67 | kernel size: 2903532 |
||
68 | kernel load addr: 0x30008000 |
||
69 | ramdisk size: 189142 |
||
70 | ramdisk load addr: 0x31000000 |
||
71 | 2nd boot size: 0 |
||
72 | 2nd boot load addr: 0x30f00000 |
||
73 | kernel tags addr: 0x30000100 |
||
74 | page size: 4096 |
||
75 | board: `' |
||
76 | cmdline: `console=ttyFIQ0 no_console_suspend' |
||
77 | 1 | Denis 'GNUtoo' Carikli | id: bd59d387bf083b0946e25a8f17f1aaef4bcc7412000 |
78 | 11 | Denis 'GNUtoo' Carikli | </pre> |
79 | 19 | Denis 'GNUtoo' Carikli | |
80 | 22 | Denis 'GNUtoo' Carikli | We also check the kernel image format, since we will build that: |
81 | <pre> |
||
82 | $ file kernel.img |
||
83 | kernel.img: Linux kernel ARM boot executable zImage (little-endian) |
||
84 | </pre> |
||
85 | 11 | Denis 'GNUtoo' Carikli | |
86 | h3. Building |
||
87 | |||
88 | 14 | Denis 'GNUtoo' Carikli | If you want to be able to run "make menuconfig", install libncurses5-dev: |
89 | <pre> |
||
90 | # apt-get install libncurses5-dev |
||
91 | </pre> |
||
92 | |||
93 | 13 | Denis 'GNUtoo' Carikli | Download the sources: |
94 | 11 | Denis 'GNUtoo' Carikli | <pre> |
95 | 4 | Denis 'GNUtoo' Carikli | $ git clone https://git.replicant.us/replicant/kernel_samsung_crespo.git |
96 | 1 | Denis 'GNUtoo' Carikli | </pre> |
97 | 13 | Denis 'GNUtoo' Carikli | |
98 | Then in each console you build from, do: |
||
99 | <pre> |
||
100 | export ARCH=arm |
||
101 | export CROSS_COMPILE=arm-none-eabi- |
||
102 | </pre> |
||
103 | |||
104 | Configure it for crespo: |
||
105 | <pre> |
||
106 | $ make crespo_defconfig |
||
107 | </pre> |
||
108 | |||
109 | 14 | Denis 'GNUtoo' Carikli | If you want to configure it furthurer: |
110 | <pre> |
||
111 | $ make menuconfig |
||
112 | </pre> |
||
113 | |||
114 | 13 | Denis 'GNUtoo' Carikli | Then build a zImage: |
115 | <pre> |
||
116 | $ make -j4 zImage |
||
117 | </pre> |
||
118 | 11 | Denis 'GNUtoo' Carikli | |
119 | 15 | Denis 'GNUtoo' Carikli | If the compilation succedded, the image is at: |
120 | <pre> |
||
121 | arch/arm/boot/zImage |
||
122 | </pre> |
||
123 | |||
124 | h3. Building Failures |
||
125 | |||
126 | 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. |
||
127 | |||
128 | As a result, variations in the default kernel configuration for your device can result in build errors. |
||
129 | |||
130 | Compilation failures can also happen when you use another gcc version, like we do in this guide. |
||
131 | This happens frequently if you use a gcc that is more recent than your kernel. |
||
132 | The "not very clean code" also increase the probability of it. |
||
133 | |||
134 | 20 | Denis 'GNUtoo' Carikli | h3. Repacking |
135 | 21 | Denis 'GNUtoo' Carikli | |
136 | 23 | Denis 'GNUtoo' Carikli | We now create a new boot.img from the parameters and ramdisk.img we extracted from the default boot.img |
137 | <pre> |
||
138 | $ mkbootimg --kernel /path/to/arch/arm/boot/zImage --ramdisk ramdisk.img --cmdline "console=ttyFIQ0 no_console_suspend" --base 0x30000000 --pagesize 4096 -o new-boot.img |
||
139 | </pre> |
||
140 | |||
141 | Then we verify that it matches the default boot.img parameters: |
||
142 | <pre> |
||
143 | $ unbootimg -i new-boot.img |
||
144 | total image size: 3096576 |
||
145 | kernel size: 2899584 |
||
146 | kernel load addr: 0x30008000 |
||
147 | ramdisk size: 189142 |
||
148 | ramdisk load addr: 0x31000000 |
||
149 | 2nd boot size: 0 |
||
150 | 2nd boot load addr: 0x30f00000 |
||
151 | kernel tags addr: 0x30000100 |
||
152 | page size: 4096 |
||
153 | board: `' |
||
154 | cmdline: `console=ttyFIQ0 no_console_suspend' |
||
155 | id: f33faefb7b1eca7d1d1d6dc7603aed2bd82d65c000 |
||
156 | </pre> |
||
157 | |||
158 | Here we check if the following parameters match: |
||
159 | * kernel load addr |
||
160 | * ramdisk load addr |
||
161 | * Kernel tag addr |
||
162 | * page size |
||
163 | * cmdline if you don't plan to change it. |
||
164 | |||
165 | 1 | Denis 'GNUtoo' Carikli | h3. Testing |
166 | 24 | Denis 'GNUtoo' Carikli | |
167 | Reboot the device to the bootloader, and run: |
||
168 | <pre> |
||
169 | $ fastboot boot new-boot.img |
||
170 | 25 | Denis 'GNUtoo' Carikli | < waiting for device > |
171 | downloading 'boot.img'... |
||
172 | OKAY [ 0.435s] |
||
173 | booting... |
||
174 | OKAY [ 0.288s] |
||
175 | finished. total time: 0.723s |
||
176 | 24 | Denis 'GNUtoo' Carikli | </pre> |