Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 30

Denis 'GNUtoo' Carikli, 12/25/2010 12:45 AM

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