Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 38

Denis 'GNUtoo' Carikli, 01/03/2011 09:45 PM

1 1 Denis 'GNUtoo' Carikli
== Introduction ==
2
Many people bought many different phones, and some of them whish to help replicant and/or to port replicant to their phones or devices.
3 33 Michael Haas -
This guide will show what was done for the htc dream, so these people can understand the process better.
4 34 Michael Haas -
When talking about porting, this page talks about re-using existing product definitions. You will not learn how to
5
build Android for a device not currently supported by Android. Instead, you will learn how to build a version of
6
[Cyanogenmod http://www.cyanogenmod.com/] without proprietary parts.
7 35 Michael Haas -
To gain more insight in the Android build system, refer to [http://source.android.com/porting/build_system.html Android Build System documentation] which is part of
8 34 Michael Haas -
[http://source.android.com/porting/ Android Platform Developer's Guide]. You should find an answer there if you have any questions about the Makefiles referenced in this document.
9 32 Michael Haas -
10 1 Denis 'GNUtoo' Carikli
== Terminology ==
11 33 Michael Haas -
The RIL is the radio interface library, that is to say, a library that talks to the modem, usually (but not always) trough AT commands.
12 32 Michael Haas -
Basically the modem runs on a separate CPU,and there is some sort of communication needed between the main CPU and the modem CPU to make telephony work. For instance, the modem must tell you when you've got a call, and you must tell the modem that you want to call someone.
13 1 Denis 'GNUtoo' Carikli
TODO: point to 0707 standard or newer
14
15 31 Denis 'GNUtoo' Carikli
== Help with source code ==
16 32 Michael Haas -
Keep in mind that on most devices, the full source code of the kernel is released.
17
However, some userspace libraries, or dlopened libraries (libraries loaded at runtime after the application started) are proprietary software,
18 31 Denis 'GNUtoo' Carikli
so if you're porting to a new CPU/SOC keep in mind that you have the source code to the kernel interfaces.
19
That can help a lot, and sometimes there is even some sort of documentation in the headers.
20 1 Denis 'GNUtoo' Carikli
21
== Build the source ==
22
23
The first thing to do is to download the replicant sources:
24
[wiki:BuildDream] can be used as a reference: download and build the sources for your device.
25 32 Michael Haas -
Let's say the user has a HTC Wildfire. It is useful to know the codename of the device in question, which is "Buzz" in case
26
of the Wildfire.
27 1 Denis 'GNUtoo' Carikli
28 32 Michael Haas -
You need to configure the build tree for our device. By default, a generic image
29
for the Android emulator will be built. 
30
In [wiki:BuildDream], you would use the following command to set up the build:
31 2 Denis 'GNUtoo' Carikli
{{{
32
lunch cyanogen_dream_sapphire-eng 
33
}}}
34 32 Michael Haas -
Now, since you are not building for the HTC dream, you need to identify the right command that corresponds to your device.
35
In order to do that, run the following command and look at its output.
36 2 Denis 'GNUtoo' Carikli
{{{
37
$ source build/envsetup.sh
38
including device/geeksphone/one/vendorsetup.sh
39
including device/htc/ace/vendorsetup.sh
40
including device/htc/bravoc/vendorsetup.sh
41
including device/htc/bravo/vendorsetup.sh
42
including device/htc/buzz/vendorsetup.sh
43
including device/htc/glacier/vendorsetup.sh
44 1 Denis 'GNUtoo' Carikli
including device/htc/heroc/vendorsetup.sh
45
including device/htc/inc/vendorsetup.sh
46 2 Denis 'GNUtoo' Carikli
including device/htc/legend/vendorsetup.sh
47
including device/htc/liberty/vendorsetup.sh
48
including device/htc/supersonic/vendorsetup.sh
49
including device/htc/vision/vendorsetup.sh
50
including device/motorola/sholes/vendorsetup.sh
51
including device/nvidia/harmony/vendorsetup.sh
52
including vendor/cyanogen/vendorsetup.sh
53
}}}
54 37 Denis 'GNUtoo' Carikli
The last line is important:
55 1 Denis 'GNUtoo' Carikli
{{{
56 37 Denis 'GNUtoo' Carikli
$ cat vendor/cyanogen/vendorsetup.sh
57
add_lunch_combo cyanogen_ace-eng
58
add_lunch_combo cyanogen_bravo-eng
59
add_lunch_combo cyanogen_bravoc-eng
60
add_lunch_combo cyanogen_buzz-eng
61
add_lunch_combo cyanogen_dream_sapphire-eng
62
add_lunch_combo cyanogen_espresso-eng
63
add_lunch_combo cyanogen_glacier-eng
64
add_lunch_combo cyanogen_harmony-eng
65
add_lunch_combo cyanogen_hero-eng
66
add_lunch_combo cyanogen_heroc-eng
67
add_lunch_combo cyanogen_inc-eng
68
add_lunch_combo cyanogen_legend-eng
69
add_lunch_combo cyanogen_liberty-eng
70
add_lunch_combo cyanogen_one-eng
71
add_lunch_combo cyanogen_passion-eng
72
add_lunch_combo cyanogen_sholes-eng
73
add_lunch_combo cyanogen_supersonic-eng
74
add_lunch_combo cyanogen_vibrant-eng
75
add_lunch_combo cyanogen_vision-eng
76
add_lunch_combo cyanogen_z71-eng
77 4 Denis 'GNUtoo' Carikli
78 37 Denis 'GNUtoo' Carikli
PATH=$PATH:$PWD/vendor/cyanogen/tools ; export PATH
79 4 Denis 'GNUtoo' Carikli
}}}
80 37 Denis 'GNUtoo' Carikli
The output include the list of supported (by cyanogenmod) devices.
81
For instance if you have the Wildfire (codename 'buzz') phone do:
82 36 Michael Haas -
{{{
83 1 Denis 'GNUtoo' Carikli
lunch cyanogen_buzz-eng
84 36 Michael Haas -
}}}
85
86 1 Denis 'GNUtoo' Carikli
Then build the source, backup what's on your device, including the operating system, and flash the new replicant image.
87 9 Denis 'GNUtoo' Carikli
88
Then test what works and what doesn't.
89 1 Denis 'GNUtoo' Carikli
90
The images are located in 
91
{{{
92
out/target/product/dream_sapphire
93 32 Michael Haas -
}}}
94 8 Denis 'GNUtoo' Carikli
in the case of the HTC Dream. You need to look in the path that corresponds to your device.
95 1 Denis 'GNUtoo' Carikli
96
== Trying free replacements ==
97 32 Michael Haas -
98
The source code you just built contains some free replacements for the proprietary
99
libraries shipped by your phone vendor with the default firmware.
100
101 1 Denis 'GNUtoo' Carikli
A list of proprietary libraries is available in
102 10 Denis 'GNUtoo' Carikli
{{{
103
device/htc/dream_sapphire/extract-files.sh
104 32 Michael Haas -
}}}
105
Note: don't run this file, just look at it. If you run it, the proprietary files will be copied from your phone into the build tree. A build containing proprietary files would put you and
106 1 Denis 'GNUtoo' Carikli
your users at risk. Additionally, it is illegal to redistribute such build, because the libraries are not redistributable(the copyright owner didn't allow you to redistribute them).
107 32 Michael Haas -
108
109
=== RIL test ===
110
I will take the example of how to use the free RIL (Radio Interface Library) to see if it works fine without modifications:
111 11 Denis 'GNUtoo' Carikli
The proprietary RIL library (which you don't have in the phone) location is found looking at the extract-files.sh
112
here's a part of extract-files.sh:
113
{{{
114
adb pull /system/lib/libhtc_ril.so ../../../vendor/htc/$DEVICE/proprietary/libhtc_ril.so
115 32 Michael Haas -
}}}
116
Note: don't run this command, just look at it. If you run it, the proprietary files will be copied from your phone into the build tree. A build containing proprietary files would put you and
117
your users at risk. Additionally, it is illegal to redistribute such build, because the libraries are not redistributable(the copyright owner didn't allow you to redistribute them).
118
119 12 Denis 'GNUtoo' Carikli
So looking at the above line the proprietary RIL is located here on the phone:
120
{{{
121
/system/lib/libhtc_ril.so
122 32 Michael Haas -
}}}
123 13 Denis 'GNUtoo' Carikli
while the free ril is located here (known fact):
124 14 Denis 'GNUtoo' Carikli
{{{
125 1 Denis 'GNUtoo' Carikli
/system/lib/libreference-ril.so
126 32 Michael Haas -
}}}
127 13 Denis 'GNUtoo' Carikli
In order to test the free RIL you could be tempted to do that:
128 14 Denis 'GNUtoo' Carikli
{{{
129 15 Denis 'GNUtoo' Carikli
# ./adb remount
130 14 Denis 'GNUtoo' Carikli
# ./adb shell
131 1 Denis 'GNUtoo' Carikli
mv /system/lib/libreference-ril.so /system/lib/libhtc_ril.so
132
}}}
133
But that wouldn't work as it wouldn't be using the right serial port, the correct way to try that is to use getprop/setprop:
134 14 Denis 'GNUtoo' Carikli
{{{
135 1 Denis 'GNUtoo' Carikli
# ./adb shell
136
# setprop
137
usage: setprop <key> <value>
138 32 Michael Haas -
}}}
139 13 Denis 'GNUtoo' Carikli
Here's how it looks on a working replicant on the HTC Dream:
140
{{{
141
# ./adb shell
142
# getprop | grep ril
143
[ro.ril.hsxpa]: [2]
144
[ro.ril.gprsclass]: [10]
145 1 Denis 'GNUtoo' Carikli
[rild.libpath]: [/system/lib/libreference-ril.so]
146
[rild.libargs]: [-d/dev/smd0]
147 15 Denis 'GNUtoo' Carikli
[init.svc.ril-daemon]: [running]
148
[ro.ril.def.agps.mode]: [2]
149
[gsm.version.ril-impl]: [android reference-ril 1.0]
150 32 Michael Haas -
}}}
151
 * /dev/smd0 is the (emulated) serial port
152 13 Denis 'GNUtoo' Carikli
 * /system/lib/libreference-ril.so is where to look for the RIL hardware specific library 
153 14 Denis 'GNUtoo' Carikli
154 12 Denis 'GNUtoo' Carikli
Then change the following properties and reboot:
155
{{{
156 7 Denis 'GNUtoo' Carikli
./adb shell reboot
157 32 Michael Haas -
}}}
158 10 Denis 'GNUtoo' Carikli
Then try the reference RIL.
159 32 Michael Haas -
160 16 Denis 'GNUtoo' Carikli
== Replacing proprietary libraries for real ==
161 32 Michael Haas -
162
On the HTC Dream the following proprietary libraries were replaced:
163 16 Denis 'GNUtoo' Carikli
(Refer to [wiki:ProprietaryHtcDreamLibsReplacement] for more up to date details(or fix it if it's less recent))
164
165
The first thing you will have to do is to modify the build system.
166 1 Denis 'GNUtoo' Carikli
The key thing to do is to change 
167 32 Michael Haas -
168
=== RIL ===
169
If the RIL you previously tried works fine, why not switching to it...directly in the build system.
170 16 Denis 'GNUtoo' Carikli
Here's the diff between A working RIL and a non-working RIL for the htcdream:
171
{{{
172
android_device_htc_dream_sapphire$ git diff 5593d2899203ec378c306701788f1c43af9a6935 -- full_dream_sapphire.mk
173
diff --git a/full_dream_sapphire.mk b/full_dream_sapphire.mk
174
index 9ec7feb..eb1b956 100644
175
--- a/full_dream_sapphire.mk
176
+++ b/full_dream_sapphire.mk
177
@@ -40,7 +40,8 @@ PRODUCT_PROPERTY_OVERRIDES := \
178
     ro.media.dec.jpeg.memcap=10000000
179
 
180
 PRODUCT_PROPERTY_OVERRIDES += \
181
-    rild.libpath=/system/lib/libhtc_ril.so \
182
+    rild.libpath=/system/lib/libreference-ril.so \
183
+    rild.libargs=-d/dev/smd0 \
184
     wifi.interface=tiwlan0
185 17 Denis 'GNUtoo' Carikli
 
186
 # Time between scans in seconds. Keep it high to minimize battery drain.
187
188
}}}
189
Note that full_dream_sapphire.mk is located here:
190
{{{
191 18 Denis 'GNUtoo' Carikli
device/htc/dream_sapphire/full_dream_sapphire.mk
192
}}}
193
The diff is self-explanatory and how to do the change is left as an exercise to the reader.
194 32 Michael Haas -
195 18 Denis 'GNUtoo' Carikli
In case the RIL need to be modified the sources are in :
196 19 Denis 'GNUtoo' Carikli
{{{
197
hardware/ril/reference-ril
198
}}}
199 21 Denis 'GNUtoo' Carikli
They are written in C.
200 19 Denis 'GNUtoo' Carikli
201 32 Michael Haas -
=== Audio libraries ===
202
On the HTC dream the audio libraries were modified.
203 19 Denis 'GNUtoo' Carikli
If your device is an msm7k "CPU" (in reality it's called a SOC, or system on a chip), it already contain the routing fix. Else I will analyse the following commit to give hints on how to modify an audio library:
204
{{{
205
commit e0b55a19b2fc004915503ebdfd7c4c02c4264611
206
Author: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
207
Date:   Thu Dec 23 16:49:35 2010 +0100
208
209
    libaudio: AudioHardware: don't depend on the proprietary libhtc_acoustic.so for routing
210
    
211
    /system/lib/libhtc_acoustic.so is proprietary(and not redistributable),
212
      so we don't depend on it, but still we want audio routing
213
    
214
    This commit was inspired from a previous commit I made(for replicant 1.5):
215
      http://gitorious.org/replicant/msm7k/commit/6d13023d634e54814ecc74b22f77de27f1b8ac2c
216
    
217
    Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
218
219
diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp
220
index 78b6a3e..af63e5a 100644
221
--- a/libaudio/AudioHardware.cpp
222
+++ b/libaudio/AudioHardware.cpp
223
@@ -43,6 +43,74 @@ const uint32_t AudioHardware::inputSamplingRates[] = {
224
         8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
225
 };
226
 // ----------------------------------------------------------------------------
227
+static int snd_get_endpoint(int cnt,msm_snd_endpoint * ept){
228
+     int fd;
229
+     int status;
230
+     fd = open("/dev/msm_snd",O_RDWR);
231
+     if (fd < 0) {
232
+	  LOGE("Cannot open msm_snd device");
233
+	  close(fd);
234
+	  return -1;
235
+     }
236
+     status = ioctl(fd,SND_GET_ENDPOINT, ept);
237
+     close(fd);
238
+     return status;
239
+}
240
+
241
+static int snd_get_num(){
242
+     int fd;
243
+     int status;
244
+     int mNumSndEndpoints;
245
+     fd = open("/dev/msm_snd",O_RDWR);
246
+     if (fd < 0) {
247
+	  LOGE("Cannot open msm_snd device");
248
+	  return -1;
249
+     }
250
+
251
+     if(ioctl(fd,SND_GET_NUM_ENDPOINTS,&mNumSndEndpoints)<0 ) {
252
+	  LOGE("get number of endpoints error");
253
+	  close(fd);
254
+	  return -1;
255
+     }
256
+     close(fd);
257
+     return mNumSndEndpoints;
258
+}
259
+
260
+static int msm72xx_enable_audpp (uint16_t enable_mask)
261
+{
262
+    int fd;
263
+
264
+
265
+    fd = open ("/dev/msm_pcm_ctl", O_RDWR);
266
+    if (fd < 0) {
267
+        LOGE ("Cannot open audio device");
268
+        return -1;
269
+    }
270
+
271
+    if (enable_mask & ADRC_ENABLE) {
272
+        enable_mask &= ~ADRC_ENABLE;
273
+    }
274
+    if (enable_mask & EQ_ENABLE) {
275
+        enable_mask &= ~EQ_ENABLE;
276
+    }
277
+    if (enable_mask & RX_IIR_ENABLE) {
278
+        enable_mask &= ~RX_IIR_ENABLE;
279
+    }
280
+
281
+    printf ("msm72xx_enable_audpp: 0x%04x", enable_mask);
282
+    if (ioctl (fd, AUDIO_ENABLE_AUDPP, &enable_mask) < 0) {
283
+	LOGE ("enable audpp error");
284
+	close (fd);
285
+	return -1;
286
+    }
287
+
288
+    close (fd);
289
+    return 0;
290
+}
291
+
292
+static int set_acoustic_parameters(){
293
+     return 0;
294
+}
295
 
296
 AudioHardware::AudioHardware() :
297
     mInit(false), mMicMute(true), mBluetoothNrec(true), mBluetoothId(0),
298
@@ -63,38 +131,10 @@ AudioHardware::AudioHardware() :
299
     SND_DEVICE_BT_EC_OFF(-1)
300
 {
301
 
302
-    int (*snd_get_num)();
303
-    int (*snd_get_endpoint)(int, msm_snd_endpoint *);
304
-    int (*set_acoustic_parameters)();
305
-
306
     struct msm_snd_endpoint *ept;
307
 
308
-    acoustic = ::dlopen("/system/lib/libhtc_acoustic.so", RTLD_NOW);
309
-    if (acoustic == NULL ) {
310
-        LOGE("Could not open libhtc_acoustic.so");
311
-        /* this is not really an error on non-htc devices... */
312
-        mNumSndEndpoints = 0;
313
-        mInit = true;
314
-        return;
315
-    }
316
-
317
-    set_acoustic_parameters = (int (*)(void))::dlsym(acoustic, "set_acoustic_parameters");
318
-    if ((*set_acoustic_parameters) == 0 ) {
319
-        LOGE("Could not open set_acoustic_parameters()");
320
-        return;
321
-    }
322
-
323
-    int rc = set_acoustic_parameters();
324
-    if (rc < 0) {
325
-        LOGE("Could not set acoustic parameters to share memory: %d", rc);
326
-//        return;
327
-    }
328
-
329
-    snd_get_num = (int (*)(void))::dlsym(acoustic, "snd_get_num_endpoints");
330
-    if ((*snd_get_num) == 0 ) {
331
-        LOGE("Could not open snd_get_num()");
332
-//        return;
333
-    }
334
+    LOGI("Not using the proprietary libhtc_acoustic library");
335
+    mInit = true;
336
 
337
     mNumSndEndpoints = snd_get_num();
338
     LOGD("mNumSndEndpoints = %d", mNumSndEndpoints);
339
@@ -102,11 +142,6 @@ AudioHardware::AudioHardware() :
340
     mInit = true;
341
     LOGV("constructed %d SND endpoints)", mNumSndEndpoints);
342
     ept = mSndEndpoints;
343
-    snd_get_endpoint = (int (*)(int, msm_snd_endpoint *))::dlsym(acoustic, "snd_get_endpoint");
344
-    if ((*snd_get_endpoint) == 0 ) {
345
-        LOGE("Could not open snd_get_endpoint()");
346
-        return;
347
-    }
348
 
349
     for (int cnt = 0; cnt < mNumSndEndpoints; cnt++, ept++) {
350
         ept->id = cnt;
351
@@ -488,17 +523,14 @@ status_t AudioHardware::doAudioRouteOrMute(uint32_t device)
352
                               mMode != AudioSystem::MODE_IN_CALL, mMicMute);
353 1 Denis 'GNUtoo' Carikli
 }
354
 
355 19 Denis 'GNUtoo' Carikli
+
356
+
357
 status_t AudioHardware::doRouting()
358
 {
359
-    /* currently this code doesn't work without the htc libacoustic */
360
-    if (!acoustic)
361
-        return 0;
362
 
363
     Mutex::Autolock lock(mLock);
364
     uint32_t outputDevices = mOutput->devices();
365
     status_t ret = NO_ERROR;
366
-    int (*msm72xx_enable_audpp)(int);
367
-    msm72xx_enable_audpp = (int (*)(int))::dlsym(acoustic, "msm72xx_enable_audpp");
368
     int audProcess = (ADRC_DISABLE | EQ_DISABLE | RX_IIR_DISABLE);
369
     AudioStreamInMSM72xx *input = getActiveInput_l();
370
     uint32_t inputDevice = (input == NULL) ? 0 : input->devices();
371
@@ -576,11 +608,7 @@ status_t AudioHardware::doRouting()
372
 
373
     if (sndDevice != -1 && sndDevice != mCurSndDevice) {
374
         ret = doAudioRouteOrMute(sndDevice);
375
-        if ((*msm72xx_enable_audpp) == 0 ) {
376
-            LOGE("Could not open msm72xx_enable_audpp()");
377
-        } else {
378
-            msm72xx_enable_audpp(audProcess);
379
-        }
380 30 Denis 'GNUtoo' Carikli
+        msm72xx_enable_audpp(audProcess);
381
         mCurSndDevice = sndDevice;
382
     }
383
}}}
384
Note several things:
385 22 Denis 'GNUtoo' Carikli
 * the routing was disabled, I had to re-enable it
386 28 Denis 'GNUtoo' Carikli
 * I had to replace some non-existant functions, for that I used public playwav2.c source code that the author released to us under the apache 2.0 license.
387
 * I had nearly no knowledge of C++
388 32 Michael Haas -
 * it was easy
389 28 Denis 'GNUtoo' Carikli
390 32 Michael Haas -
== Re-using source code ==
391
The previous source code re-used some public source code that was licensed under the Apache 2.0 license.
392 28 Denis 'GNUtoo' Carikli
The ril will also re-use some public source code licensed under Apache 2.0.
393
That is the advised way to do it as it save some time and is easier to do, however proper credit must be attributed, at least in the commit message.
394 22 Denis 'GNUtoo' Carikli
It is even advised to look at the public apache 2.0 source code of other rils libraries or components of android.
395
396 23 Denis 'GNUtoo' Carikli
=== Ril ===
397
 * vilvord ril
398
 * openmoko (android on freerunner) ril
399
400
== Source organization and commit access ==
401
Until now we made some changes in the tree, but we want the changes to land upstream in replicant.
402
For instance let's say we modified only the ril path like in the ril section in 
403
{{{
404 24 Denis 'GNUtoo' Carikli
device/htc/dream_sapphire/full_dream_sapphire.mk 
405
}}}
406
first we save our modifications:
407
{{{
408
cd device/htc/dream_sapphire/
409
git diff > git_diff.patch
410
}}}
411
then we find where is the root of the git repository we are in:
412 1 Denis 'GNUtoo' Carikli
{{{
413
cd replicant-2.2 #top replicant directory where everything is in
414 24 Denis 'GNUtoo' Carikli
cd .repo
415
cat manifest.xml
416
}}}
417
and we find that:
418
{{{
419
  <project path="device/htc/buzz" name="CyanogenMod/android_device_htc_buzz" remote="github" />
420
}}}
421
so...now our repository is in device/htc/buzz
422
We will now look where the source repository is:
423
{{{
424
cd device/htc/buzz
425
cd .git
426
cat config
427
}}}
428
We find that:
429
{{{
430
	url = git://github.com/CyanogenMod/android_device_htc_buzz.git
431
}}}
432
433 25 Denis 'GNUtoo' Carikli
Then create a directory, not under the replicant-2.2 directory that will contain your repositories:
434
{{{
435
mkdir repo
436
cd repo
437
}}}
438
and clone the source:
439
{{{
440
git clone git://github.com/CyanogenMod/android_device_htc_buzz.git
441
cd android_device_htc_buzz
442 26 Denis 'GNUtoo' Carikli
}}}
443
apply the previous patch:
444 27 Denis 'GNUtoo' Carikli
{{{
445 26 Denis 'GNUtoo' Carikli
git apply path/to/git_diff.patch
446
}}}
447
commit locally the result:
448
{{{
449
git commit -s
450
}}}
451 32 Michael Haas -
Note that the commit message should have the following format:
452
The first line should be a summary
453 1 Denis 'GNUtoo' Carikli
Followed by a linebreak
454 27 Denis 'GNUtoo' Carikli
And then the details explaining the commit
455
If you made an error writing the commit message do
456
{{{
457
git commit --amend
458
}}}
459 1 Denis 'GNUtoo' Carikli
460
TODO: complete for sending the git patch(git format-patch -1,git send-email)
461
462
==== Pushing to replicant ====
463
TODO: git remote add+git push