Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 33

Michael Haas -, 12/25/2010 01:28 PM
More cosmetics

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 32 Michael Haas -
5 1 Denis 'GNUtoo' Carikli
== Terminology ==
6 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.
7 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.
8 1 Denis 'GNUtoo' Carikli
TODO: point to 0707 standard or newer
9
10 31 Denis 'GNUtoo' Carikli
== Help with source code ==
11 32 Michael Haas -
Keep in mind that on most devices, the full source code of the kernel is released.
12
However, some userspace libraries, or dlopened libraries (libraries loaded at runtime after the application started) are proprietary software,
13 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.
14
That can help a lot, and sometimes there is even some sort of documentation in the headers.
15 1 Denis 'GNUtoo' Carikli
16
== Build the source ==
17
18
The first thing to do is to download the replicant sources:
19
[wiki:BuildDream] can be used as a reference: download and build the sources for your device.
20 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
21
of the Wildfire.
22 1 Denis 'GNUtoo' Carikli
23 32 Michael Haas -
You need to configure the build tree for our device. By default, a generic image
24
for the Android emulator will be built. 
25
In [wiki:BuildDream], you would use the following command to set up the build:
26 2 Denis 'GNUtoo' Carikli
{{{
27
lunch cyanogen_dream_sapphire-eng 
28
}}}
29 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.
30
In order to do that, run the following command and look at its output.
31 2 Denis 'GNUtoo' Carikli
{{{
32
$ source build/envsetup.sh
33
including device/geeksphone/one/vendorsetup.sh
34
including device/htc/ace/vendorsetup.sh
35
including device/htc/bravoc/vendorsetup.sh
36
including device/htc/bravo/vendorsetup.sh
37
including device/htc/buzz/vendorsetup.sh
38
including device/htc/glacier/vendorsetup.sh
39 1 Denis 'GNUtoo' Carikli
including device/htc/heroc/vendorsetup.sh
40
including device/htc/inc/vendorsetup.sh
41 2 Denis 'GNUtoo' Carikli
including device/htc/legend/vendorsetup.sh
42
including device/htc/liberty/vendorsetup.sh
43
including device/htc/supersonic/vendorsetup.sh
44
including device/htc/vision/vendorsetup.sh
45
including device/motorola/sholes/vendorsetup.sh
46
including device/nvidia/harmony/vendorsetup.sh
47
including vendor/cyanogen/vendorsetup.sh
48
}}}
49 32 Michael Haas -
The output include the list of supported (by cyanogenmod) devices.
50
For instance if you have the Wildfire (codename 'buzz') phone do:
51 2 Denis 'GNUtoo' Carikli
{{{
52
$ cat device/htc/buzz/vendorsetup.sh 
53
#
54
# Copyright (C) 2008 The Android Open Source Project
55
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
57
# you may not use this file except in compliance with the License.
58
# You may obtain a copy of the License at
59
#
60
#      http://www.apache.org/licenses/LICENSE-2.0
61
#
62
# Unless required by applicable law or agreed to in writing, software
63
# distributed under the License is distributed on an "AS IS" BASIS,
64
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
65
# See the License for the specific language governing permissions and
66
# limitations under the License.
67
#
68
69
# This file is executed by build/envsetup.sh, and can use anything
70
# defined in envsetup.sh.
71 1 Denis 'GNUtoo' Carikli
#
72 2 Denis 'GNUtoo' Carikli
# In particular, you can add lunch options with the add_lunch_combo
73
# function: add_lunch_combo generic-eng
74
75
add_lunch_combo generic_buzz-eng
76
}}}
77 3 Denis 'GNUtoo' Carikli
Note that the developper is supposed to know the code of his device, that is to say that the htc wildfire correspond to the "buzz" codename.
78 4 Denis 'GNUtoo' Carikli
then instead of typing that:
79
{{{
80
lunch cyanogen_dream_sapphire-eng 
81
}}}
82 32 Michael Haas -
type what corresponds to your device:
83 3 Denis 'GNUtoo' Carikli
{{{
84 1 Denis 'GNUtoo' Carikli
lunch generic_buzz-eng
85
}}}
86
Then build the source, backup what's on your device, including the operating system, and flash the new replicant image.
87
88 9 Denis 'GNUtoo' Carikli
Then test what works and what doesn't.
89
90 1 Denis 'GNUtoo' Carikli
The images are located in 
91
{{{
92
out/target/product/dream_sapphire
93
}}}
94 32 Michael Haas -
in the case of the HTC Dream. You need to look in the path that corresponds to your device.
95 8 Denis 'GNUtoo' Carikli
96 1 Denis 'GNUtoo' Carikli
== Trying free replacements ==
97
98 32 Michael Haas -
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
A list of proprietary libraries is available in
102 1 Denis 'GNUtoo' Carikli
{{{
103 10 Denis 'GNUtoo' Carikli
device/htc/dream_sapphire/extract-files.sh
104
}}}
105 32 Michael Haas -
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
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 1 Denis 'GNUtoo' Carikli
108 32 Michael Haas -
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
The proprietary RIL library (which you don't have in the phone) location is found looking at the extract-files.sh
112 11 Denis 'GNUtoo' Carikli
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
}}}
116 32 Michael Haas -
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
So looking at the above line the proprietary RIL is located here on the phone:
120 12 Denis 'GNUtoo' Carikli
{{{
121
/system/lib/libhtc_ril.so
122
}}}
123 32 Michael Haas -
while the free ril is located here (known fact):
124 13 Denis 'GNUtoo' Carikli
{{{
125 14 Denis 'GNUtoo' Carikli
/system/lib/libreference-ril.so
126 1 Denis 'GNUtoo' Carikli
}}}
127 32 Michael Haas -
In order to test the free RIL you could be tempted to do that:
128 13 Denis 'GNUtoo' Carikli
{{{
129 14 Denis 'GNUtoo' Carikli
# ./adb remount
130 15 Denis 'GNUtoo' Carikli
# ./adb shell
131 14 Denis 'GNUtoo' Carikli
mv /system/lib/libreference-ril.so /system/lib/libhtc_ril.so
132 1 Denis 'GNUtoo' Carikli
}}}
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
{{{
135 14 Denis 'GNUtoo' Carikli
# ./adb shell
136 1 Denis 'GNUtoo' Carikli
# setprop
137
usage: setprop <key> <value>
138
}}}
139 32 Michael Haas -
Here's how it looks on a working replicant on the HTC Dream:
140 13 Denis 'GNUtoo' Carikli
{{{
141
# ./adb shell
142
# getprop | grep ril
143
[ro.ril.hsxpa]: [2]
144
[ro.ril.gprsclass]: [10]
145
[rild.libpath]: [/system/lib/libreference-ril.so]
146 1 Denis 'GNUtoo' Carikli
[rild.libargs]: [-d/dev/smd0]
147
[init.svc.ril-daemon]: [running]
148 15 Denis 'GNUtoo' Carikli
[ro.ril.def.agps.mode]: [2]
149
[gsm.version.ril-impl]: [android reference-ril 1.0]
150
}}}
151 32 Michael Haas -
 * /dev/smd0 is the (emulated) serial port
152
 * /system/lib/libreference-ril.so is where to look for the RIL hardware specific library 
153 13 Denis 'GNUtoo' Carikli
154 14 Denis 'GNUtoo' Carikli
Then change the following properties and reboot:
155 12 Denis 'GNUtoo' Carikli
{{{
156
./adb shell reboot
157 7 Denis 'GNUtoo' Carikli
}}}
158 32 Michael Haas -
Then try the reference RIL.
159 10 Denis 'GNUtoo' Carikli
160 32 Michael Haas -
== Replacing proprietary libraries for real ==
161 16 Denis 'GNUtoo' Carikli
162 32 Michael Haas -
On the HTC Dream the following proprietary libraries were replaced:
163
(Refer to [wiki:ProprietaryHtcDreamLibsReplacement] for more up to date details(or fix it if it's less recent))
164 16 Denis 'GNUtoo' Carikli
165
The first thing you will have to do is to modify the build system.
166
The key thing to do is to change 
167 1 Denis 'GNUtoo' Carikli
168 32 Michael Haas -
=== RIL ===
169
If the RIL you previously tried works fine, why not switching to it...directly in the build system.
170
Here's the diff between A working RIL and a non-working RIL for the htcdream:
171 16 Denis 'GNUtoo' Carikli
{{{
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
 
186 17 Denis 'GNUtoo' Carikli
 # 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
device/htc/dream_sapphire/full_dream_sapphire.mk
192 18 Denis 'GNUtoo' Carikli
}}}
193
The diff is self-explanatory and how to do the change is left as an exercise to the reader.
194
195 32 Michael Haas -
In case the RIL need to be modified the sources are in :
196 18 Denis 'GNUtoo' Carikli
{{{
197 19 Denis 'GNUtoo' Carikli
hardware/ril/reference-ril
198
}}}
199
They are written in C.
200 21 Denis 'GNUtoo' Carikli
201 19 Denis 'GNUtoo' Carikli
=== Audio libraries ===
202 32 Michael Haas -
On the HTC dream the audio libraries were modified.
203
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 19 Denis 'GNUtoo' Carikli
{{{
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
 }
354 1 Denis 'GNUtoo' Carikli
 
355
+
356 19 Denis 'GNUtoo' Carikli
+
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
+        msm72xx_enable_audpp(audProcess);
381 30 Denis 'GNUtoo' Carikli
         mCurSndDevice = sndDevice;
382
     }
383
}}}
384
Note several things:
385
 * the routing was disabled, I had to re-enable it
386 22 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 28 Denis 'GNUtoo' Carikli
 * I had nearly no knowledge of C++
388
 * it was easy
389 32 Michael Haas -
390 28 Denis 'GNUtoo' Carikli
== Re-using source code ==
391 32 Michael Haas -
The previous source code re-used some public source code that was licensed under the Apache 2.0 license.
392
The ril will also re-use some public source code licensed under Apache 2.0.
393 28 Denis 'GNUtoo' Carikli
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
It is even advised to look at the public apache 2.0 source code of other rils libraries or components of android.
395 22 Denis 'GNUtoo' Carikli
396
=== Ril ===
397 23 Denis 'GNUtoo' Carikli
 * 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
device/htc/dream_sapphire/full_dream_sapphire.mk 
405 24 Denis 'GNUtoo' Carikli
}}}
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
{{{
413 1 Denis 'GNUtoo' Carikli
cd replicant-2.2 #top replicant directory where everything is in
414
cd .repo
415 24 Denis 'GNUtoo' Carikli
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
Then create a directory, not under the replicant-2.2 directory that will contain your repositories:
434 25 Denis 'GNUtoo' Carikli
{{{
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
}}}
443 26 Denis 'GNUtoo' Carikli
apply the previous patch:
444
{{{
445 27 Denis 'GNUtoo' Carikli
git apply path/to/git_diff.patch
446 26 Denis 'GNUtoo' Carikli
}}}
447
commit locally the result:
448
{{{
449
git commit -s
450
}}}
451
Note that the commit message should have the following format:
452 32 Michael Haas -
The first line should be a summary
453
Followed by a linebreak
454 1 Denis 'GNUtoo' Carikli
And then the details explaining the commit
455 27 Denis 'GNUtoo' Carikli
If you made an error writing the commit message do
456
{{{
457
git commit --amend
458
}}}
459
460 1 Denis 'GNUtoo' Carikli
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