Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 36

Michael Haas -, 01/01/2011 01:25 PM
Must build for cyanogen vendor, not generic vendor.

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