Project

General

Profile

DeprecatedReplicant40DevicePortingGuide » History » Version 25

Paul Kocialkowski, 07/04/2013 08:19 PM

1 1 Paul Kocialkowski
h1. Replicant 4.0 Porting Guide
2
3
{{>toc}}
4
5
This guide is a step-by-step explanation of the process of porting a new device to Replicant 4.0.
6
7
h2. Overview
8
9
Porting a new device to Replicant is a long task, so make sure you're ready to go through all the steps mentioned below. While it's not technically hard (unless you have to write free software replacements yourself), the process itself takes time as many steps are involved:
10
* Checking that your devices meets [[Replicant40PortingGuide#Prerequisites|the required prerequisites]]
11
* Discovering the phone's hardware and the amount of non-free blobs involved
12
* Getting Replicant sources, reading all the relevant material about developing on Replicant
13
* Adding the device-specific repositories and files
14
* Setting up the build environment for the new device
15 4 Paul Kocialkowski
* Building a recovery image
16 1 Paul Kocialkowski
17 19 Paul Kocialkowski
*A general good advice when porting a new device to Replicant is to look at how things are done on other devices and look at the commits that were made.*
18
19 1 Paul Kocialkowski
h2. Prerequisites
20
21
Before porting your device to Replicant, you must make sure it complies with the following requirements:
22
* The phone is already supported by CyanogenMod (CM) 9.x (or, worst-case scenario, by a non-official CyanogenMod 9.x port)
23
* The phone has a GSM modem: Replicant doesn't support CDMA phones (but you can add support for it if you're skilled)
24
* There is a way of installing another operating system, either through the bootloader or via recovery (this is likely if there is a CM port)
25
* The kernel is not signed: this means that the bootloader doesn't check the kernel's signature to match with the vendor's key to allow it to run
26
27
If your device fails to comply with one of these requirements, it won't be possible to port Replicant to it.
28
If you don't know about whether your device complies or not, you'll probably learn it along the way.
29
30
h2. Discovering the phone's hardware and associated blobs
31
32 2 Paul Kocialkowski
h3. Finding the device's codenames
33 1 Paul Kocialkowski
34 2 Paul Kocialkowski
First of all, you'll have to find out the device's codename that was given by its manufacturer. "Wikipedia":http://www.wikipedia.org/ usually has that information on the device's article. For instance, the codename for the European version of the Nexus S given by Samsung is i9023. This codename will help in the process of getting informations about the device.
35 1 Paul Kocialkowski
36 2 Paul Kocialkowski
Then, a second codename (that can turn out the be the same as the previous one) is given to the device at Android-level. If your device is supported by CyanogenMod, you can find it out from the "CyanogenMod Wiki":http://wiki.cyanogenmod.org/ or on "CyanogenMod download page":http://get.cm/. For instance, the "Nexus S":http://wiki.cyanogenmod.org/w/Crespo_Info codename is: @crespo@.
37 1 Paul Kocialkowski
38 2 Paul Kocialkowski
h3. Investigating the hardware
39
40
It is useful to have a general idea of what kind of hardware is present in the phone. From the Wikipedia and CyanogenMod pages about the device, it's already possible to know what System on a Chip (SoC) it uses and a couple other details.
41
42
To learn more details, you can consider looking for a teardown of the device (for instance on "iFixit":http://www.ifixit.com/), that will reveal what chips are used on the device. Looking at the kernel defconfig for the device will also help a lot, you can also try to find the service manual for the device.
43
44
You can then compare that to the devices that are already supported in Replicant to get an idea of what will possibly work.
45
46
h3. Finding out if the device checks the kernel's signature
47
48 1 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.
49
50 2 Paul Kocialkowski
This is not an easy information to find out, but the developers involved in the CyanogenMod port will probably know that information. It's a good idea to just ask them.
51
52
h3. Discovering the way of flashing the device
53
54
To install the future Replicant image on the device, you have to find out how the device can be flashed with a new operating system. The "CyanogenMod Wiki":http://wiki.cyanogenmod.org/ has install guides for the supported devices and you'll probably find install guides for non-official CM ports as well. It is very important to understand the flashing procedure as it will have to be documented on the Replicant wiki.
55
56
There are basically two ways of flashing a new operating system:
57
# Through the bootloader: a program has to send the images to the phone in bootloader mode. Make sure that program is free if your device supports flashing via bootloader.
58
# With recovery: a recovery image has to be installed instead of the current kernel so that at next reboot, recovery permits the installation of another operating system. Make sure this doesn't involve rooting the phone using non-free software.
59
60 3 Paul Kocialkowski
h3. The non-free blobs
61 2 Paul Kocialkowski
62
The key information to get before starting the port is the list of the non-free components that are required by CyanogenMod.
63
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 on the @ics@ branch.
64
There is usually a link to the device repository from the "CyanogenMod Wiki":http://wiki.cyanogenmod.org/
65
66 1 Paul Kocialkowski
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
67
68
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.
69 3 Paul Kocialkowski
70
h2. Getting started with Replicant development
71
72
In order to prepare everything for the Replicant port:
73
* Install CyanogenMod on the phone
74
* Install the [[BuildDependencies]]
75
* Get the sources: [[GettingReplicantSources]]
76 20 Paul Kocialkowski
* Read the Android Source code guide: http://source.android.com/source/index.html
77
* Read the Android Device porting guide: http://source.android.com/devices/index.html
78 3 Paul Kocialkowski
* Read the Replicant developer guide: [[DeveloperGuide]]
79
* Learn how to do debug: [[GettingLogs]] [[GDBDebugging]]
80
81
h2. Cloning the device files
82
83
Once your Replicant tree is ready, you can start adding the necessary repos for your device.
84
That means cloning the necessary repos in the right place. These repos are:
85
* A *device-specific repo*. On CyanogenMod, it is usually called: @android_device_vendor_device@.
86
* Sometimes one or more *common repo(s)*, usually called: @android_device_vendor_devices-common@.
87
Some devices don't need any common repo, but some do.
88
* A *kernel repo*. On CyanogenMod, it is usually called: @android_kernel_samsung_devices@.
89
The kernel repo can be shared across a family of devices (for instance, on kernel repo for Samsung Exynos, one for Samsung OMAP, etc).
90
91
You can find the device-specific repo from the device's page on the "CyanogenMod Wiki":http://wiki.cyanogenmod.org/. 
92
Make sure you check out the branches that match the CM 9.0 version (the branch may be called @ics@).
93
94
Once you have cloned the device-specific repo for your device and checked out the correct branch, refer to the @cm.dependencies@ file to find what repos are left to clone.
95
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@).
96
97
If your cloned the kernel source for your device, it is likely that the kernel build is already integrated, so you can skip the next sections below.
98
99
h3. In case of a missing kernel repository
100
101
If the kernel repo is nowhere to be found (make sure you've asked the CyanogenMod team), you'll need to get the kernel source directly from the vendor, especially if your device is supported by a 3rd party CyanogenMod fork.
102
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.
103
That means the kernel sources will be available online. Here are some websites where such releases are done:
104
* "Samsung Open Source Release Center":http://opensource.samsung.com/
105
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).
106
This will hold a kernel archive with all the sources and instructions on how to build it and which defconfig to use.
107
* "CodeAurora":https://www.codeaurora.org/contribute/projects/qaep
108
For MSM/QSD devices, and particularly HTC ones.
109
* "HTCdev":http://www.htcdev.com/devcenter/downloads
110
* "Motorola Sourceforge":http://sourceforge.net/motorola/
111
* "Sony Mobile Developer":http://developer.sonymobile.com/downloads/opensource/
112
* "LG OpenSource":http://www.lg.com/global/support/opensource/opensource.jsp
113
114
Once you have the kernel sources, read the instructions to find out which defconfig to use.
115
116
Since manufacturers usually don't release the git history along with the files, you'll need to recreate a git repo:
117
* Clone the mainline kernel in the same version as the Makefile from the sources you just obtained
118
* Remove the cloned files *except the .git directory*
119
* Move the manufacturer kernel tree at the place of the files you just removed
120
* 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")
121
122
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@).
123
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@.
124
125
h3. In case of a prebuilt kernel
126
127
Some devices are still using a prebuilt kernel. Even though the CyanogenMod team is trying to avoid that, it remains in many repos.
128
For such devices, you will need to remove the prebuilt binaries and the instructions to copy the prebuilt kernel and its modules.
129
130
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).
131
Remove the instructions to copy these prebuilts on the makefiles. Remove instructions such as:
132
<pre>
133
PRODUCT_COPY_FILES += \
134
    $(LOCAL_KERNEL):kernel
135
136
LOCAL_KERNEL := $(LOCAL_PATH)/kernel
137
</pre>
138
and anything regarding @TARGET_PREBUILT_KERNEL@ as well as the instructions to copy the prebuilt modules.
139
140
The @BoardConfig.mk@ (or @BoardConfigCommon.mk@ in the common directory for your device) will most likely hold a line like:
141
<pre>
142
TARGET_PREBUILT_KERNEL := device/samsung/p5/kernel
143
</pre>
144
you must remove this line.
145
146
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:
147
<pre>
148
TARGET_KERNEL_SOURCE := kernel/samsung/p3
149
TARGET_KERNEL_CONFIG := samsung_p5_defconfig
150
</pre>
151
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).
152
153
h3. Building the correct kernel image format
154
155
There are different types of kernel images:
156
* Android image: that is a zImage, without a separate initramfs
157
* zImage: that is a zImage, with a built-in initramfs
158
* uImage: that is an image for the u-boot bootloader, with a built-in initramfs
159
160
You need to find out which type of kernel image your device uses. Asking people who know about that is the best idea.
161
162
h4. Android image
163
164
This is the easiest case to handle: just make sure the @CONFIG_INITRAMFS_SOURCE@ option in the kernel defonfig is left blank or undefined:
165
<pre>
166
CONFIG_INITRAMFS_SOURCE=""
167
</pre>
168
169
h4. zImage with built-in initramfs
170
171
Building a zImage with a built-in initramfs requires the following steps:
172
In the kernel defconfig, define the @CONFIG_INITRAMFS_SOURCE@ option that way:
173
<pre>
174
CONFIG_INITRAMFS_SOURCE="../../root"
175
</pre>
176
177
Once this is done, duplicate the defconfig and add the @_recovery@ prefix before the @_defconfig@ ending (e.g. @herring_recovery_defconfig@), edit that file and replace @CONFIG_INITRAMFS_SOURCE@ with:
178
<pre>
179
CONFIG_INITRAMFS_SOURCE="../../recovery/root"
180
</pre>
181
182
Back to the device repository, edit the @BoardConfig.mk@ file and add the following line:
183
<pre>
184
TARGET_KERNEL_RECOVERY_CONFIG := samsung_p5_recovery_defconfig
185
</pre>
186
and make sure to replace the defconfig by the appropriate defconfig you just cloned (the one with the @_recovery_defconfig@ ending).
187
188
Still in the device repository, create a @bootimg.mk@ file containing the following:
189
<pre>
190
LOCAL_PATH := $(call my-dir)
191
192
$(INSTALLED_BOOTIMAGE_TARGET): $(INSTALLED_KERNEL_TARGET)
193
	$(ACP) $(INSTALLED_KERNEL_TARGET) $@
194
195
$(INSTALLED_RECOVERYIMAGE_TARGET): $(INSTALLED_RECOVERY_KERNEL_TARGET)
196
	$(ACP) $(INSTALLED_RECOVERY_KERNEL_TARGET) $@
197
</pre>
198
199
Edit the @BoardConfig.mk@ file and add the following line:
200
<pre>
201
BOARD_CUSTOM_BOOTIMG_MK := device/vendor/device/bootimg.mk
202
</pre>
203
and make sure to replace @device/vendor/device/@ to the correct path to your device's repository.
204
205
h4. uImage with built-in initramfs
206
207
Follow the previous instructions (*zImage with built-in initramfs*) and set the @BOARD_USES_UBOOT@ variable in the @BoardConfig.mk@ file:
208
<pre>
209
BOARD_USES_UBOOT := true
210
</pre>
211 5 Paul Kocialkowski
212
213
h2. Setting up the build environment
214
215
Now that the repos are cloned, you need to modify some makefiles to cope with Replicant paths.
216
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 replacing the @cm@ prefix with @replicant@ (e.g. change PRODUCT_NAME := cm_crespo  to PRODUCT_NAME := replicant_crespo).
217
218
Now that your device files are ready, you can declare a new build target: these are held in @vendor/replicant/jenkins-build-targets@.
219
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@).
220
221
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:
222
<pre>
223
source build/envsetup.sh
224
lunch replicant_device-eng
225
</pre>
226
227
Adapt replicant_device-eng from what you added to the @jenkins-build-target@ (e.g. @replicant_crespo-eng@).
228
If an error occurs, it will explicitly report it and you'll need to fix it before doing anything.
229
If everything works correctly, you should see something like:
230
<pre>
231
============================================
232
PLATFORM_VERSION_CODENAME=REL
233
PLATFORM_VERSION=4.0.4
234
TARGET_PRODUCT=replicant_crespo
235
TARGET_BUILD_VARIANT=eng
236
TARGET_BUILD_TYPE=release
237
TARGET_BUILD_APPS=
238
TARGET_ARCH=arm
239
TARGET_ARCH_VARIANT=armv7-a
240
HOST_ARCH=x86
241
HOST_OS=linux
242
HOST_BUILD_TYPE=release
243
BUILD_ID=IMM76L
244
============================================
245
</pre>
246
247
*You must repeat these steps everytime before building anything on a freshly-opened terminal.*
248
Remember:
249
<pre>
250
source build/envsetup.sh
251
lunch replicant_device-eng
252
</pre>
253
(make sure to replace device by your device's product name).
254
255
h2. Building a recovery image
256
257
Now that everything is set-up, you can build the first image to test on your device: the recovery image.
258
259 6 Paul Kocialkowski
The build target is *recoveryimage*, so all you have to do is:
260 5 Paul Kocialkowski
<pre>
261
make -j9 recoveryimage
262
</pre>
263
264 6 Paul Kocialkowski
This should trigger the kernel build and the recovery initramfs build and in the end, produce the @out/target/product/device/recovery.img@ file.
265 5 Paul Kocialkowski
Once your image is built (it takes some time), flash it to the recovery partition of your device (if any). It's a good idea to look at the CyanogenMod installation guide to find out how to install that recovery image.
266 1 Paul Kocialkowski
267
There is usually also a key combination to hold to boot directly to recovery: hopefully, your recovery image will start.
268 6 Paul Kocialkowski
269
h2. Building the system
270
271
It is time to build a complete set of Replicant images. This includes at least the system and kernel images. Depending on the installation method, an userdata image might be needed too.
272
273
h3. Building the kernel
274
275
Let's start by building the boot image, that is both the kernel and the Android initramfs. The build target is *bootimage*:
276
<pre>
277
make -j9 bootimage
278
</pre>
279
280
In the end, the @out/target/product/device/boot.img@ file will be produced.
281
282
h3. Setting up the system image format
283
284
It is time for you to take a good look at the installation process. Mainly, about whether the images will be flashed using the bootloader or recovery.
285
Since CyanogenMod uses the zip installation method, that we do not want to use, you're on your own here.
286
287
h4. Finding the appropriate filesystem
288
289
It will be easy to find out the filesystem for the different partitions if the device already runs CyanogenMod:
290
<pre>
291
$ adb shell mount
292
rootfs / rootfs ro,relatime 0 0
293
tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
294
devpts /dev/pts devpts rw,relatime,mode=600 0 0
295
proc /proc proc rw,relatime 0 0
296
sysfs /sys sysfs rw,relatime 0 0
297
none /acct cgroup rw,relatime,cpuacct 0 0
298
tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
299
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
300
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
301
/dev/block/mtdblock2 /system yaffs2 ro,relatime 0 0
302
/dev/block/mtdblock3 /cache yaffs2 rw,nosuid,nodev,relatime 0 0
303
/dev/block/mtdblock5 /radio yaffs2 rw,relatime 0 0
304
/dev/block/mmcblk0p2 /data ext4 rw,nosuid,nodev,noatime,nodiratime,barrier=1,data=ordered,noauto_da_alloc 0 0
305
/dev/block/mtdblock6 /datadata yaffs2 rw,relatime 0 0
306
/dev/block/mtdblock4 /efs yaffs2 rw,relatime 0 0
307
/sys/kernel/debug /sys/kernel/debug debugfs rw,relatime 0 0
308
/dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
309
/dev/block/vold/179:1 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
310
tmpfs /mnt/sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
311
</pre>
312
313
So we can deduce that system is yaffs2 and data is ext4. Don't bother about the other partitions and mount-points, only */system* and */data* matter for now.
314
315
h4. Changing the images format for bootloader installation
316
317
You have to modify the @BoardConfig.mk@ file on the main device repository (it might be delegated to @BoardConfigCommon.mk@ on the common repos).
318
319
To build ext4 system and userdata images, make sure you have:
320
<pre>
321
TARGET_USERIMAGES_USE_EXT4 := true
322
</pre>
323
To build yaffs2 system and userdata images, make sure you have:
324
<pre>
325
TARGET_USERIMAGES_USE_EXT4 := false
326
</pre>
327
328
h4. Changing the images format for recovery installation
329
330 7 Paul Kocialkowski
If the images have to be flashed using recovery, you must make sure they are built in yaffs2 format, with the default page and spare sizes.
331 8 Paul Kocialkowski
Make sure to remove the following lines from @BoardConfig.mk@ (even though the values might be different):
332 7 Paul Kocialkowski
<pre>
333
BOARD_NAND_PAGE_SIZE := 4096
334
BOARD_NAND_SPARE_SIZE := 128
335
</pre>
336
Add the following to have yaffs2 images:
337
<pre>
338
TARGET_USERIMAGES_USE_EXT4 := false
339
</pre>
340
341
Even though the images are built as yaffs2, it doesn't mean that the filesystem on the device will be yaffs2: you have to set the correct filesystem, amongst: *ext4*, *yaffs2* in the built image file name.
342
That means you have to change the target images names. This is done by adding the following line (adapted for your device) on @BoardConfig.mk@:
343
<pre>
344
BOARD_CUSTOM_USERIMG_MK := device/vendor/device/userimg.mk
345
</pre>
346 10 Paul Kocialkowski
You need to create the @userimg.mk@ file on the device main repository, with the following contents (adapt the target name):
347 7 Paul Kocialkowski
348
<pre>
349 10 Paul Kocialkowski
INSTALLED_SYSTEMIMAGE_TARGET := $(PRODUCT_OUT)/system.ext4.img
350 7 Paul Kocialkowski
351
$(INSTALLED_SYSTEMIMAGE_TARGET): $(INSTALLED_SYSTEMIMAGE)
352
	@echo -e ${CL_INS}"Install system fs image: $@"${CL_RST}
353
	$(hide) mv $(INSTALLED_SYSTEMIMAGE) $(INSTALLED_SYSTEMIMAGE_TARGET)
354
355
systemimage: $(INSTALLED_SYSTEMIMAGE_TARGET)
356
</pre>
357 6 Paul Kocialkowski
358
h3. Building the system image
359
360
Building the system is the longest task. The build target is *systemimage*:
361
<pre>
362
make -j9 systemimage
363
</pre>
364
365
You might encounter build errors due to the lack of non-free libs. You'll need to find clean workarounds for that. Removing options from @BoardConfig.mk@ can help solve the situation.
366
For instance, the following error:
367
<pre>
368
make: *** No rule to make target `out/target/product/i9300/obj/lib/libTVOut.so', needed by `out/target/product/i9300/obj/EXECUTABLES/mediaserver_intermediates/LINKED/mediaserver'.  Stop.
369
</pre>
370
Was solved by turning @BOARD_USE_SECTVOUT@ to false:
371
<pre>
372
BOARD_USE_SECTVOUT := false
373
</pre>
374 9 Paul Kocialkowski
375
Once the systemimage is built, you have to build the *userdataimage* if you're going to flash using the bootloader:
376
<pre>
377
make -j9 userdataimage
378
</pre>
379
380
When all the images are built, you're ready for flashing the images.
381
Some more steps are required for recovery flashing:
382 11 Paul Kocialkowski
# Create a md5sum of the images: @md5sum system.ext4.img boot.img > checksum.md5@
383 9 Paul Kocialkowski
# Create a directory on the root of the usb storage (or sdcard) of the phone
384
# Copy the images and the md5 checksum to the newly-created directory
385
# Install the images using the *flash images* menu
386
# Wipe data using *wipe data/factory resert*
387
# Reboot the device: *reboot system now*
388
389
If everything was correctly setup, this should succeed. The best way to make sure it booted is to run @adb logcat@ and wait for an output.
390
That early, it is very likely that graphics will be broken, so don't expect anything to show up on the screen: only adb is a reliable way of knowing whether it worked.
391 12 Paul Kocialkowski
392 21 Paul Kocialkowski
h2. Android development tips
393
394
Keep in mind that all the make (and such) commands must be run in a terminal where *lunch* has been executed before.
395
396
Once you have a Replicant image installed on the device, there is no need to rebuild a whole image everytime you make a change (but it's a good idea to do it from time to time): you can instead rebuild only a single module by using (where module is the module's name):
397
<pre>
398
make module
399
</pre>
400
401
Even better, you can build the module that sits in the current directory by simply using @mm@. To push the new library to the device, use @adb push@ (you'll need to @adb remount@ the first time).
402
403
Moreover, instead of rebooting, you can kill the Android applications (@zygote@, @surfaceflinger@, @rild@) depending on what you are working on.
404
For instance for audio:
405
<pre>
406
adb shell killall zygote
407
</pre>
408
For graphics:
409
<pre>
410
adb shell killall surfaceflinger
411
</pre>
412
For the RIL:
413
<pre>
414
adb shell killall rild
415
</pre>
416
417
Be sure to always look what's going on in logs.
418
For the main buffer:
419
<pre>
420
adb logcat
421
</pre>
422
For the radio (RIL) buffer:
423
<pre>
424
adb logcat -b radio
425
</pre>
426
427 12 Paul Kocialkowski
h2. Graphics
428
429
Once Replicant booted on the phone, it's time to get graphics working. Several components are involved with graphics on android:
430
* *gralloc*: the graphical memory allocator, also handles the framebuffer
431
* *hwcomposer*: handles things like overlays and 2D blits to offload OpenGL
432
* *libEGL*: the OpenGL implementation (that's what uses the GPU to accelerate graphics)
433
434 13 Paul Kocialkowski
Generally speaking, libEGL is non-free while gralloc and hwcomposer might be free software (but they often rely on non-free blobs). On most Replicant-supported phones, we use the default gralloc, the software libEGL and no hwcomposer. We modified the gralloc so that is uses RGB565 on framebuffer, which turns out to be faster than any other format we tried.
435 12 Paul Kocialkowski
436
However, to have a fluid-enough experience, you need to disable most hardware-accelerated features of Android to enable Software GL.
437
This is done by modifying the @cm.mk@ Makefile on the device repository. Add the following lines after the others inherit calls:
438
<pre>
439
# Inherit Software GL configuration.
440
$(call inherit-product, vendor/replicant/config/software_gl.mk)
441
</pre>
442
443
Moreover, you might need to add the Software GL configuration on the @egl.cfg@ file, that is located somewhere in the device repository (perhaps under @config/@).
444
Add the following line at the beginning of the file (if it's not there already):
445
<pre>
446
0 0 android
447
</pre>
448
449
This will prevent surfaceflinger from doing a SEGFAULT.
450 14 Paul Kocialkowski
451
h2. Audio
452
453
If there is no audio support with free software on CyanogenMod, you'll have to find out details about how audio works on your device. There are mainly 3 different cases:
454
* Audio is standard ALSA
455
* Audio is ALSA with a non-standard interface aside
456
* Audio is not ALSA but something else that is not standard
457
458
To find out whether your device uses ALSA or not, look if you have the @/dev/snd/pcmC0D0c@ and @/dev/snd/pcmC0D0p@ nodes available. A non-standard interface aside might be indicated by the presence of the @/dev/snd/hwC0D0@ node.
459
460
If your device is standard ALSA, you can use the tinyalsa-audio library (located under @hardware/tinyalsa-audio@) with a configuration file (an example of such a file is available at @device/samsung/galaxys2/configs/tinyalsa-audio.xml@). You can find the propers controls to set on which scenario by running @tinymix@ (found under @external/tinyalsa@) with the non-free blob in place in the different scenarios.
461
462
If your device involves a non-standard interface or if it completely relies a non-standard interface, there is no readily available guide to find out how it works, but you can start by looking at the kernel driver and adding debug prints (with printk) there and figure out what is going on.
463 15 Paul Kocialkowski
464 23 Paul Kocialkowski
Remember to add the working audio module to the build targets (on the makefiles in the device repo).
465
466 15 Paul Kocialkowski
h2. Modem
467
468
In order to support telephony, messaging (SMS) and other network-related features (data as well), you need to make the modem work with Replicant. The modem is often called the radio in Android terminology.
469
470
The modem uses a protocol to communicate with the CPU. You need to find out which protocol the modem for your device is using. There are several possible cases:
471
* The protocol is AT, which is the only standard protocol, but it's very old: it is mostly plain ASCII and newer modems usually use a binary protocol
472
* The protocol is not standard (vendor-specific) but has been implemented in free software already
473
* The protocol is not standard and has no known free software implementation
474
475
To find out which protocol your phone uses, it is a good idea to look at the *radio* log buffer in CyanogenMod and try to find out from the messages (it may be verbose).
476
The protocol itself is implemented in the RIL (Radio Interface Layer): it is a good idea to take a look at the non-free ril the device uses (get its path with @getprop rild.libpath@).
477
478
If the modem uses the AT protocol, there are many available RIL implementations out there: Android has a reference-ril (@hardware/ril/reference-ril@) that implements AT and there is the hayes-ril library (located under @hardware/ril/hayes-ril/@) that makes it easier for you to add support for your device. Though, it is possible that the modem of your device implements undocumented commands, so you'll have to figure these out: the radio log might help a lot if it's verbose, else you'll have to trace the RIL somehow.
479
480 16 Paul Kocialkowski
If the protocol is not AT, it might still be supported: the "FreeSmartphone.Org":http://wiki.freesmartphone.org (FSO) project implements some undocumented protocols. You can also look at "oFono":https://ofono.org/.
481 15 Paul Kocialkowski
If your phone was manufactured by Samsung, there is a very good chance that it uses the Samsung-IPC protocol, which is implemented in [[libsamsung-ipc]] and [[Samsung-RIL]]. You will need to add support for your device in [[libsamsung-ipc]] ([[Samsung-RIL]] is device-independent: all the abstraction is done by [[libsamsung-ipc]]), which may be more or less easy depending on whether your modem type is already supported. In any case, you'll need to trace the RIL to find out. There may also be a separate daemon (often called *cbd*) that is in charge of the modem bootup (that's the biggest part you need to figure out), so that's the thing to trace.
482
483
If the protocol implementation is nowhere to be found, you'll have to write a free implementation yourself if you want to have free software support for the modem. It's a good idea to ask around whether other people from other communities, such as XDA or CyanogenMod, would be interested in helping you.
484 17 Paul Kocialkowski
485 22 Paul Kocialkowski
After finding a RIL that may work, add it to the build targets (in the device makefiles) and specify the path to the RIL with @rild.libpath@ (it is often already declared in system.prop in the device repo).
486
487 17 Paul Kocialkowski
Once the RIL is working, you may need the audio module cooperation to have sound during calls. For instance with [[Samsung-RIL]], you need to use an Audio-RIL-Interface that implements the Samsung-RIL-Socket interface.
488 18 Paul Kocialkowski
489
h2. Dealing with loaded firmwares
490
491
It is very likely that your device requires loaded firmwares for some components of the hardware. These are non-free programs that run separately from the CPU, on other chips. Since Replicant respects its users' freedom, no non-free firmwares are shipped with Replicant. It is possible that CyanogenMod includes shareable non-free firmwares in its tree: you must remove them.
492
493
Sometimes, components will crash (and may restart in an endless loop) when attempting to load a firmware that is not shipped with Replicant: you have to spot the code that loads the firmware and make it properly handle the case where the firmware is not available.
494
495
Though, you should keep in mind that some users may want to use that firmware, so you have to make the firmware loading possible. There are some exceptions to this however, especially when this involves blocking a free software alternative (this is the case with OMX media decoding). Moreover, firmwares should always be located under @/system/vendor/firmware/@ so that they are easy to spot and remove when the user decides to get rid of them (after installing them previously).
496
497
For instance, the WiFi firmwares path (often declared in the @BoardConfig.mk@ file) have to be changed with the @/system/vendor/firmware@ prefix. The bluetooth firmware path is often declared in the init files (such as @init.herring.rc@). Make sure to document the new firmwares locations on the wiki: see the [[DeveloperGuide#New-device-documentation-guide|Developer guide]].
498 19 Paul Kocialkowski
499
h3. Dealing with the kernel firmwares
500
501
The Linux kernel comes with its own share of firmware: you have to get rid of them too. Mostly, this is about removing the @firmwares@ directory and modifying the @Makefile@ to make it avoid firmwares.
502
Since the procedure is nearly exactly the same on all kernels, here is a reference commit for the changes to add to @Makefile@: "Removed non-free firmwares and related instructions":https://gitorious.org/replicant/kernel_samsung_crespo/commit/20a341a98d18d9d627fd42d09e0a1d9f8c8ce455
503 24 Paul Kocialkowski
504 25 Paul Kocialkowski
h2. Software media decoding
505
506
Most of the time, there is a chip dedicated to decoding media files (audio and video) and it very often requires a non-free loaded firmware. Moreover, it prevents software-only solutions from working, so you need to get rid of the libraries (even though they may be free software) that handle hardware media decoding. This is implemented in the OMX and stagefrighthw libraries. You need to spot and remove these products from the build targets of your device (in the device makefiles).
507
508
For reference, here is the commit that removes hardware media decoding on Nexus S (crespo): "OMX: Disable SEC OMX libraries to permit software decoding":https://gitorious.org/replicant/device_samsung_crespo/commit/c8edb6539977c8820d665691d53c33892cfa4fdd
509
510 24 Paul Kocialkowski
h2. Bottomline
511
512
Not every hardware feature can be supported by Replicant: there are some areas where there is simply no free software available. If this is about a critical component (audio, graphics too slow, telephony) and there is no solution in sight, you might as well consider the port a failure. On the other hand, there are lacks we can leave with, for instance 3D, camera or GPS support: don't let that get in the way of releasing images for your device!
513
514
h2. Pushing your work to Replicant repositories
515
516
Once your device works, or during the development process (it is recommended to do it as soon as it appears that the port will be successful), you have to push all your work to Replicant repositories. 
517
You need to ask for commit access to our repositories to be allowed to push your work. This means creating the repositories for your device, pushing your work to these and to the other repositories you modified and adding the new repositories to the manifest.
518
519
The [[DeveloperGuide#Repositories|Developer guide]] hold all the rules for naming repositories: make sure to act accordingly with these requirements!
520
521
The @manifest@ holds the list of the repositories we use in each Replicant version. Its syntax is xml, so it's easy to add your new repositories.
522
523
h2. Adding documentation about your device
524
525
Once your device is usable, you have to create documentation on the Replicant wiki to let others know about relevant material concerning the device, especially build and installation instructions. This is absolutely required before we can publish any image for your device!
526
527
The process is described in the [[DeveloperGuide#New-device-documentation-guide|Developer guide]].