DeprecatedPortingGuideS5PC110 » History » Version 16
Paul Kocialkowski, 12/29/2012 07:13 PM
1 | 1 | Paul Kocialkowski | h1. PortingGuideS5PC110 |
---|---|---|---|
2 | |||
3 | *This guide assumes your phone has a S5PC110/Exynos 3110 SoC* |
||
4 | |||
5 | 3 | Paul Kocialkowski | h2. Prerequisites |
6 | 1 | Paul Kocialkowski | |
7 | 3 | Paul Kocialkowski | Before porting your device to Replicant, you must make sure it complies with the following: |
8 | * Already supported by CyanogenMod (or, worst-case scenario, by a non-official CyanogenMod port) |
||
9 | * CyanogenMod support for this device is available for one of Replicant versions (pick the latest) |
||
10 | * The phone is GSM: Replicant doesn't support CDMA phones yet |
||
11 | * It is likely to be usable without blobs nor firmwares and with Replicant replacements |
||
12 | 1 | Paul Kocialkowski | |
13 | 3 | Paul Kocialkowski | h2. Investigating the phone hardware |
14 | 1 | Paul Kocialkowski | |
15 | 3 | Paul Kocialkowski | Before doing anything, you will need to know the codename of the device. You can find it out on "CyanogenMod Wiki":http://wiki.cyanogenmod.org/ or on "CyanogenMod download page":http://get.cm/. |
16 | For instance, the "Nexus S":http://wiki.cyanogenmod.org/wiki/Nexus_S codename is: @crespo@. |
||
17 | 1 | Paul Kocialkowski | |
18 | 11 | Paul Kocialkowski | One very important step is to find out if the device is Tivoized: that means that even though the manufacturer releases the kernel source code for the device, the bootloader checks the kernel signature and will refuse to start it if it's not properly signed by the manufacturer. In other words, if you build the kernel yourself, the device will refuse to run it since it's not signed by the manufacturer. Since the Linux kernel is released under the GPLv2, there are no specific dispositions to counter Tivoization, and so porting the device to Replicant is pointless as it will require a prebuilt and signed kernel from the manufacturer. |
19 | |||
20 | 3 | Paul Kocialkowski | First thing to consider before starting a port, when all of the above is assumed, is to see how many non-free components are required by CyanogenMod. |
21 | The easiest way to do this is to spot the device repository in "CyanogenMod repos":https://github.com/CyanogenMod/ and look for the @extract-files.sh@ or @proprietary-blobs.txt@ file. |
||
22 | For instance, the list of non-free components for the "Nexus S":https://github.com/CyanogenMod/android_device_samsung_crespo is "extract-files.sh":https://github.com/CyanogenMod/android_device_samsung_crespo/blob/ics/extract-files.sh |
||
23 | |||
24 | From that list, spot what is related to what hardware component (audio, camera, sensors, gps, modem, etc): that gives an idea of the amount of work required to add support for the phone. |
||
25 | |||
26 | During the port, you might need to find precise infos about the hardware that is in the phone. A good to do this is by looking at the kernel defconfig for the device, another way is to download the Service Manual for the device. |
||
27 | |||
28 | h2. Getting everything ready |
||
29 | |||
30 | In order to prepare everything for the Replicant port: |
||
31 | * Install CyanogenMod on the phone |
||
32 | * Install the [[BuildDependencies]] |
||
33 | * Get the sources: [[GettingReplicantSources]] |
||
34 | * Read Replicant developer guide: [[DeveloperGuide]] |
||
35 | * Learn how to do debug: [[GettingLogs]] [[GDBDebugging]] |
||
36 | |||
37 | 8 | Paul Kocialkowski | h2. Cloning the device files |
38 | |||
39 | Once your Replicant tree is ready, you can start by adding the necessary repos for your device. |
||
40 | That means cloning the necessary repos in the right place. These repos are: |
||
41 | 10 | Paul Kocialkowski | * A *device-specific repo*. On CyanogenMod, it is usually called: @android_device_vendor_device@. |
42 | * Sometimes one or more *common repo(s)*, usually called: @android_device_vendor_devices-common@. |
||
43 | 1 | Paul Kocialkowski | Some devices don't need any common repo, but some do. |
44 | 10 | Paul Kocialkowski | * A *kernel repo*. On CyanogenMod, it is usually called: @android_kernel_samsung_devices@. |
45 | 8 | Paul Kocialkowski | The kernel repo can be shared across a family of devices (for instance, on kernel repo for Samsung Exynos, one for Samsung OMAP, etc). |
46 | 10 | Paul Kocialkowski | If there are different branches in the kernel repo, be sure to use the one that will match userspace: if you are porting to ICS, take the branch called @ics@ or ask the people who know which branch to use. |
47 | Generally speaking, the following kernel versions match the given userspaces: |
||
48 | 1 | Paul Kocialkowski | |
49 | 10 | Paul Kocialkowski | | *Android version* | *CyanogenMod version* | *Kernel version* | |
50 | | Android 2.3 | CM 7.x | 2.6.35 | |
||
51 | | Android 4.0 | CM 9.x | 3.0.8 | |
||
52 | | Android 4.1 | CM 10 | 3.0.31 | |
||
53 | | Android 4.2 | CM 10.1 | 3.4 | |
||
54 | |||
55 | 11 | Paul Kocialkowski | Sometimes, these repos aren't held in CyanogenMod repos but instead in some other projects repos, such as: |
56 | * "Teamhacksung":https://github.com/teamhacksung (Samsung devices) |
||
57 | * "FreeXperia":https://github.com/freexperia (Sony Ericsson Xperia devices) |
||
58 | |||
59 | Generally speaking, it is a good idea to ask the members of the CyanogenMod community where to find what (especially for kernel sources and for which branch to use). |
||
60 | |||
61 | 9 | Paul Kocialkowski | Clone these repos in the correct locations and remove the prefix (e.g. @android_device_samsung_crespo@ must be cloned in @device/samsung/@ and renamed to @crespo@). |
62 | |||
63 | 8 | Paul Kocialkowski | h3. Creating the kernel repo |
64 | |||
65 | If the kernel repo is nowhere to be found, you'll need to get the kernel source directly from the vendor, especially if your device is supported by a 3rd party CyanogenMod fork. |
||
66 | Keep in mind that the Linux kernel is GPLv2, so vendors have the legal obligation to release the modified kernel sources as soon as they sell you the device. |
||
67 | That means the kernel sources will be available online. Here are some websites where such releases are done: |
||
68 | * "Samsung Open Source Release Center":http://opensource.samsung.com/ |
||
69 | For Samsung kernels. Search the device codename (e.g. I9000) and download the package called "Opensource Update" (e.g. GT-I9000_Opensource_GB_Update2.zip). |
||
70 | This will hold a kernel archive with all the sources and instructions on how to build it and which defconfig to use. |
||
71 | 12 | Paul Kocialkowski | * "CodeAurora":https://www.codeaurora.org/contribute/projects/qaep |
72 | For MSM/QSD devices, and particularly HTC ones. |
||
73 | * "HTCdev":http://www.htcdev.com/devcenter/downloads |
||
74 | * "Motorola Sourceforge":http://sourceforge.net/motorola/ |
||
75 | * "Sony Mobile Developer":http://developer.sonymobile.com/downloads/opensource/ |
||
76 | * "LG OpenSource":http://www.lg.com/global/support/opensource/opensource.jsp |
||
77 | 8 | Paul Kocialkowski | |
78 | Once you have the kernel sources, read the instructions to find out which defconfig to use. |
||
79 | |||
80 | Since manufacturers usually don't release the git history along with the files, you'll need to recreate a git repo: |
||
81 | * Clone the mainline kernel in the same version as the Makefile from the sources you just obtained |
||
82 | * Remove the cloned files *except the .git directory* |
||
83 | * Move the manufacturer kernel tree at the place of the files you just removed |
||
84 | * Add all the files in git (@git add -A@) and commit (@git commit@) with a message explaining what you just imported (e.g. "GT-I9000 GB Opensource Update 2") |
||
85 | |||
86 | Now that you have a git repo, you can move it to the Replicant code tree, under the name: @kernel/vendor/devices@ (e.g. @kernel/samsung/aries@). |
||
87 | Make sure to make the @devices@ name match the @devices@ in @android_device_vendor_devices-common@ if the kernel is shared across these devices or to match the @device@ in @android_device_vendor_device@. |
||
88 | |||
89 | 15 | Paul Kocialkowski | h3. In case of a prebuilt kernel |
90 | |||
91 | Some devices are still using a prebuilt kernel. Even though the CyanogenMod team is trying to avoid that, it remains in many repos. |
||
92 | For such devices, you will need to remove the prebuilt binaries and the instructions to copy the prebuilt kernel and its modules. |
||
93 | |||
94 | In the device repository (@device/vendor/device@) and common repository for your device (if any), remove the prebuilt kernel and modules (usually called @kernel@ and @module.ko@ (replace module with the name of a module) or a @modules@ directory). |
||
95 | Remove the instructions to copy these prebuilts on the makefiles. Remove instructions such as: |
||
96 | <pre> |
||
97 | PRODUCT_COPY_FILES += \ |
||
98 | $(LOCAL_KERNEL):kernel |
||
99 | |||
100 | LOCAL_KERNEL := $(LOCAL_PATH)/kernel |
||
101 | </pre> |
||
102 | and anything regarding @TARGET_PREBUILT_KERNEL@ as well as the instructions to copy the prebuilt modules. |
||
103 | |||
104 | The @BoardConfig.mk@ (or @BoardConfigCommon.mk@ in the common directory for your device) will most likely hold a line like: |
||
105 | <pre> |
||
106 | TARGET_PREBUILT_KERNEL := device/samsung/p5/kernel |
||
107 | </pre> |
||
108 | you must remove this line. |
||
109 | |||
110 | Now that the device repository has no prebuilt instructions, you can add the instructions to build the kernel. In the @BoardConfig.mk@ file, add the following lines: |
||
111 | <pre> |
||
112 | TARGET_KERNEL_SOURCE := kernel/samsung/p3 |
||
113 | TARGET_KERNEL_CONFIG := samsung_p5_defconfig |
||
114 | </pre> |
||
115 | and make sure to replace the location and defconfig by the correct values for your devices (being the location of the device kernel tree and the appropriate defconfig). |
||
116 | |||
117 | h3. Building the correct kernel image format |
||
118 | |||
119 | There are different types of kernel images: |
||
120 | * Android image: that is a zImage, without a separate initramfs |
||
121 | * zImage: that is a zImage, with a built-in initramfs |
||
122 | * uImage: that is an image for the u-boot bootloader, with a built-in initramfs |
||
123 | |||
124 | You need to find out which type of kernel image your device uses. Asking people who know about that is the best idea. |
||
125 | |||
126 | h4. Android image |
||
127 | |||
128 | This is the easiest case to handle: just make sure the @CONFIG_INITRAMFS_SOURCE@ option in the kernel defonfig is left blank or undefined: |
||
129 | <pre> |
||
130 | CONFIG_INITRAMFS_SOURCE="" |
||
131 | </pre> |
||
132 | |||
133 | h4. zImage with built-in initramfs |
||
134 | |||
135 | Building a zImage with a built-in initramfs requires the following steps: |
||
136 | In the kernel defconfig, define the @CONFIG_INITRAMFS_SOURCE@ option that way: |
||
137 | <pre> |
||
138 | CONFIG_INITRAMFS_SOURCE="../../root" |
||
139 | </pre> |
||
140 | |||
141 | Back to the device repository, create a @bootimg.mk@ file containing the following: |
||
142 | <pre> |
||
143 | LOCAL_PATH := $(call my-dir) |
||
144 | |||
145 | $(INSTALLED_BOOTIMAGE_TARGET): $(INSTALLED_KERNEL_TARGET) |
||
146 | $(ACP) $(INSTALLED_KERNEL_TARGET) $@ |
||
147 | $(call pretty,"Boot image: $@") |
||
148 | </pre> |
||
149 | |||
150 | Edit the @BoardConfig.mk@ file and add the following line: |
||
151 | <pre> |
||
152 | BOARD_CUSTOM_BOOTIMG_MK := device/vendor/device/bootimg.mk |
||
153 | </pre> |
||
154 | and make sure to replace @device/vendor/device/@ to the correct path to your device's repository. |
||
155 | |||
156 | h4. uImage with built-in initramfs |
||
157 | |||
158 | Follow the previous instructions (*zImage with built-in initramfs*) and set the @BOARD_USES_UBOOT@ variable in the @BoardConfig.mk@ file: |
||
159 | <pre> |
||
160 | BOARD_USES_UBOOT := true |
||
161 | </pre> |
||
162 | |||
163 | 9 | Paul Kocialkowski | h3. Adding the device to the build targets |
164 | 1 | Paul Kocialkowski | |
165 | Now that the repos are cloned, you need to modify some makefiles to cope with Replicant paths. |
||
166 | In the device repository (@device/vendor/device@), modify the file called @cm.mk@ and replace the @vendor/cm/@ occurrences by @vendor/replicant/@. Other makefiles may need that as well (in any case, build will fail very early if you missed one). In that same @cm.mk@ file, change the PRODUCT_NAME variable by repalcing the @cm@ prefix with @replicant@ (e.g. change PRODUCT_NAME := cm_crespo to PRODUCT_NAME := replicant_crespo). |
||
167 | |||
168 | Now that your device files are ready, you can declare a new build target: these are held in @vendor/replicant/jenkins-build-targets@. |
||
169 | 11 | Paul Kocialkowski | Modify that file and add a line (at the end) with the PRODUCT_NAME you set and the @-eng@ suffix (e.g. @replicant_crespo-eng@). |
170 | 1 | Paul Kocialkowski | |
171 | 11 | Paul Kocialkowski | From now on, everything should be ready to start a build. To check for errors or missed occurrences, start a terminal in the Replicant tree root and lunch: |
172 | <pre> |
||
173 | 1 | Paul Kocialkowski | source build/envsetup.sh |
174 | 14 | Paul Kocialkowski | lunch replicant_device-eng |
175 | </pre> |
||
176 | |||
177 | Adapt replicant_device-eng from what you added to the @jenkins-build-target@ (e.g. @replicant_crespo-eng@). |
||
178 | If an error occurs, it will explicitly report it and you'll need to fix it before doing anything. |
||
179 | If everything works correctly, you should see something like: |
||
180 | <pre> |
||
181 | ============================================ |
||
182 | PLATFORM_VERSION_CODENAME=REL |
||
183 | PLATFORM_VERSION=4.0.4 |
||
184 | TARGET_PRODUCT=replicant_crespo |
||
185 | TARGET_BUILD_VARIANT=eng |
||
186 | TARGET_BUILD_TYPE=release |
||
187 | TARGET_BUILD_APPS= |
||
188 | TARGET_ARCH=arm |
||
189 | TARGET_ARCH_VARIANT=armv7-a |
||
190 | HOST_ARCH=x86 |
||
191 | HOST_OS=linux |
||
192 | HOST_BUILD_TYPE=release |
||
193 | BUILD_ID=IMM76L |
||
194 | ============================================ |
||
195 | </pre> |
||
196 | |||
197 | 11 | Paul Kocialkowski | h2. Building the kernel |
198 | 2 | Paul Kocialkowski | |
199 | 11 | Paul Kocialkowski | Once the devices repos are in place and the build target is configured, you are now able to start building things and the first thing to build is obviously the kernel. |
200 | 4 | Paul Kocialkowski | |
201 | 16 | Paul Kocialkowski | Once your terminal is correctly setup (the @lunch@ command worked correctly), you can start building the kernel: |
202 | <pre> |
||
203 | make -j9 bootimage |
||
204 | </pre> |
||
205 | |||
206 | It will take a couple of minutes, depending on how fast your setup is. At the end, it should create a @boot.img@ file in @out/target/product/device@ (replace device with your device's product name). |
||
207 | If not, an error will be shown and you'll have to fix it. |
||
208 | |||
209 | h2. Building recovery |
||
210 | |||
211 | Building the kernel with success is a great step, but it is hard to make any use of it (unless your userspace matches the initramfs, but that's not always the case). |
||
212 | That's why you'll have to build recovery next. Furthermore, some devices only allow flashing via recovery, so this is fundamental. |
||
213 | |||
214 | 6 | Denis 'GNUtoo' Carikli | h2. Various hardware and software fixes to get things working. |
215 | 1 | Paul Kocialkowski | |
216 | 6 | Denis 'GNUtoo' Carikli | h3. To get software video decoding (OMX stuff): |
217 | 7 | Denis 'GNUtoo' Carikli | |
218 | 4 | Paul Kocialkowski | * remove OMX libs for hardware video decoding |
219 | 1 | Paul Kocialkowski | * remove libstagefrighthw.so |
220 | 5 | Denis 'GNUtoo' Carikli | like that: http://gitorious.org/replicant/device_samsung_crespo/commit/c8edb6539977c8820d665691d53c33892cfa4fdd |