Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 31

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