Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 35

Michael Haas -, 01/01/2011 01:20 PM
Use better URL for general android documentation

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