Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 27

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