KernelBuild » History » Version 33
Wolfgang Wiedmeyer, 05/08/2017 08:20 AM
difference between unpackbootimg and unbootimg;ADB is not important; also a little formatting
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 | 33 | Wolfgang Wiedmeyer | * @mkbootimg@ to pack an image |
51 | * @unpackbootimg@ to unpack an image (older versions are called @unbootimg@) |
||
52 | 10 | Denis 'GNUtoo' Carikli | |
53 | 1 | Denis 'GNUtoo' Carikli | Ways to get such tools: |
54 | 32 | Wolfgang Wiedmeyer | * [[ReplicantImages|Pre-built by Replicant]] |
55 | * Some GNU/Linux distributions also have packages for some of the tools. |
||
56 | * Build Replicant and use its tools. This would defeat the purpose of this tutorial since we want to avoid a full build of Replicant. |
||
57 | 10 | Denis 'GNUtoo' Carikli | |
58 | 32 | Wolfgang Wiedmeyer | Some android tools were converted to build on GNU/Linux without requiring the Android build system: |
59 | 33 | Wolfgang Wiedmeyer | * In https://github.com/freesmartphone/utilities, you have the source code for @mkbootimg@ and @unbootimg@ in @android/image-utils@. |
60 | 9 | Denis 'GNUtoo' Carikli | |
61 | 19 | Denis 'GNUtoo' Carikli | Extract the ramdisk and the kernel image and parameters from the original boot.img: |
62 | |||
63 | 1 | Denis 'GNUtoo' Carikli | <pre> |
64 | 19 | Denis 'GNUtoo' Carikli | $ unbootimg --kernel kernel.img --ramdisk ramdisk.img -i boot.img |
65 | 11 | Denis 'GNUtoo' Carikli | total image size: 3100672 |
66 | kernel size: 2903532 |
||
67 | kernel load addr: 0x30008000 |
||
68 | ramdisk size: 189142 |
||
69 | ramdisk load addr: 0x31000000 |
||
70 | 2nd boot size: 0 |
||
71 | 2nd boot load addr: 0x30f00000 |
||
72 | kernel tags addr: 0x30000100 |
||
73 | page size: 4096 |
||
74 | board: `' |
||
75 | cmdline: `console=ttyFIQ0 no_console_suspend' |
||
76 | 1 | Denis 'GNUtoo' Carikli | id: bd59d387bf083b0946e25a8f17f1aaef4bcc7412000 |
77 | 11 | Denis 'GNUtoo' Carikli | </pre> |
78 | 19 | Denis 'GNUtoo' Carikli | |
79 | 22 | Denis 'GNUtoo' Carikli | We also check the kernel image format, since we will build that: |
80 | <pre> |
||
81 | $ file kernel.img |
||
82 | kernel.img: Linux kernel ARM boot executable zImage (little-endian) |
||
83 | </pre> |
||
84 | 11 | Denis 'GNUtoo' Carikli | |
85 | h3. Building |
||
86 | |||
87 | 14 | Denis 'GNUtoo' Carikli | If you want to be able to run "make menuconfig", install libncurses5-dev: |
88 | <pre> |
||
89 | # apt-get install libncurses5-dev |
||
90 | </pre> |
||
91 | |||
92 | 13 | Denis 'GNUtoo' Carikli | Download the sources: |
93 | 11 | Denis 'GNUtoo' Carikli | <pre> |
94 | 4 | Denis 'GNUtoo' Carikli | $ git clone https://git.replicant.us/replicant/kernel_samsung_crespo.git |
95 | 1 | Denis 'GNUtoo' Carikli | </pre> |
96 | 13 | Denis 'GNUtoo' Carikli | |
97 | Then in each console you build from, do: |
||
98 | <pre> |
||
99 | export ARCH=arm |
||
100 | export CROSS_COMPILE=arm-none-eabi- |
||
101 | </pre> |
||
102 | |||
103 | Configure it for crespo: |
||
104 | <pre> |
||
105 | $ make crespo_defconfig |
||
106 | </pre> |
||
107 | |||
108 | 14 | Denis 'GNUtoo' Carikli | If you want to configure it furthurer: |
109 | <pre> |
||
110 | $ make menuconfig |
||
111 | </pre> |
||
112 | |||
113 | 13 | Denis 'GNUtoo' Carikli | Then build a zImage: |
114 | <pre> |
||
115 | $ make -j4 zImage |
||
116 | </pre> |
||
117 | 11 | Denis 'GNUtoo' Carikli | |
118 | 15 | Denis 'GNUtoo' Carikli | If the compilation succedded, the image is at: |
119 | <pre> |
||
120 | arch/arm/boot/zImage |
||
121 | </pre> |
||
122 | |||
123 | h3. Building Failures |
||
124 | |||
125 | 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. |
||
126 | |||
127 | As a result, variations in the default kernel configuration for your device can result in build errors. |
||
128 | |||
129 | Compilation failures can also happen when you use another gcc version, like we do in this guide. |
||
130 | This happens frequently if you use a gcc that is more recent than your kernel. |
||
131 | The "not very clean code" also increase the probability of it. |
||
132 | |||
133 | 20 | Denis 'GNUtoo' Carikli | h3. Repacking |
134 | 21 | Denis 'GNUtoo' Carikli | |
135 | 23 | Denis 'GNUtoo' Carikli | We now create a new boot.img from the parameters and ramdisk.img we extracted from the default boot.img |
136 | <pre> |
||
137 | $ 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 |
||
138 | </pre> |
||
139 | |||
140 | Then we verify that it matches the default boot.img parameters: |
||
141 | <pre> |
||
142 | $ unbootimg -i new-boot.img |
||
143 | total image size: 3096576 |
||
144 | kernel size: 2899584 |
||
145 | kernel load addr: 0x30008000 |
||
146 | ramdisk size: 189142 |
||
147 | ramdisk load addr: 0x31000000 |
||
148 | 2nd boot size: 0 |
||
149 | 2nd boot load addr: 0x30f00000 |
||
150 | kernel tags addr: 0x30000100 |
||
151 | page size: 4096 |
||
152 | board: `' |
||
153 | cmdline: `console=ttyFIQ0 no_console_suspend' |
||
154 | id: f33faefb7b1eca7d1d1d6dc7603aed2bd82d65c000 |
||
155 | </pre> |
||
156 | |||
157 | Here we check if the following parameters match: |
||
158 | * kernel load addr |
||
159 | * ramdisk load addr |
||
160 | * Kernel tag addr |
||
161 | * page size |
||
162 | * cmdline if you don't plan to change it. |
||
163 | |||
164 | 1 | Denis 'GNUtoo' Carikli | h3. Testing |
165 | 24 | Denis 'GNUtoo' Carikli | |
166 | Reboot the device to the bootloader, and run: |
||
167 | <pre> |
||
168 | $ fastboot boot new-boot.img |
||
169 | 25 | Denis 'GNUtoo' Carikli | < waiting for device > |
170 | downloading 'boot.img'... |
||
171 | OKAY [ 0.435s] |
||
172 | booting... |
||
173 | OKAY [ 0.288s] |
||
174 | finished. total time: 0.723s |
||
175 | 24 | Denis 'GNUtoo' Carikli | </pre> |