Project

General

Profile

DeprecatedPortingGuideMSMQSD » History » Version 70

Paul Kocialkowski, 02/05/2012 03:52 PM

1 67 Paul Kocialkowski
h1. Porting Guide: MSM/QSD
2 66 Paul Kocialkowski
3
h2. Introduction
4
5 1 Denis 'GNUtoo' Carikli
Many people bought many different phones, and some of them whish to help replicant and/or to port replicant to their phones or devices.
6 33 Michael Haas -
This guide will show what was done for the htc dream, so these people can understand the process better.
7 1 Denis 'GNUtoo' Carikli
When talking about porting, this page talks about re-using existing product definitions. You will not learn how to
8
build Android for a device not currently supported by Android. Instead, you will learn how to build a version of
9
[Cyanogenmod http://www.cyanogenmod.com/] without proprietary parts.
10 66 Paul Kocialkowski
To gain more insight in the Android build system, refer to "Android Build System documentation":http://source.android.com/porting/build_system.html which is part of
11
"Android Platform Developer's Guide":http://source.android.com/porting/. You should find an answer there if you have any questions about the Makefiles referenced in this document.
12 1 Denis 'GNUtoo' Carikli
13 66 Paul Kocialkowski
Note: The Android Build System documentation above has been removed. You can find a mirror of the (outdated) documentation "here":http://www.kandroid.org/online-pdk/guide/index.html and "here":http://www.netmite.com/android/mydroid/development/pdk/docs/.
14 62 Igor Almeida -
15 66 Paul Kocialkowski
16
h2. Terminology
17
18 1 Denis 'GNUtoo' Carikli
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.
19 33 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.
20 1 Denis 'GNUtoo' Carikli
TODO: point to 0707 standard or newer
21
22 66 Paul Kocialkowski
23
h2. Help with source code
24
25 1 Denis 'GNUtoo' Carikli
Keep in mind that on most devices, the full source code of the kernel is released.
26
However, some userspace libraries, or dlopened libraries (libraries loaded at runtime after the application started) are proprietary software,
27
so if you're porting to a new CPU/SOC keep in mind that you have the source code to the kernel interfaces.
28
That can help a lot, and sometimes there is even some sort of documentation in the headers.
29
30
31 66 Paul Kocialkowski
h2. Build the source
32
33
34 1 Denis 'GNUtoo' Carikli
The first thing to do is to download the replicant sources:
35 66 Paul Kocialkowski
[[BuildDream]] can be used as a reference: download and build the sources for your device.
36 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
37
of the Wildfire.
38 1 Denis 'GNUtoo' Carikli
39 32 Michael Haas -
You need to configure the build tree for our device. By default, a generic image
40
for the Android emulator will be built. 
41 66 Paul Kocialkowski
In [[BuildDream]], you would use the following command to set up the build:
42
<pre>
43 2 Denis 'GNUtoo' Carikli
lunch cyanogen_dream_sapphire-eng 
44 66 Paul Kocialkowski
</pre>
45 2 Denis 'GNUtoo' Carikli
Now, since you are not building for the HTC dream, you need to identify the right command that corresponds to your device.
46
In order to do that, run the following command and look at its output.
47 66 Paul Kocialkowski
<pre>
48 2 Denis 'GNUtoo' Carikli
$ source build/envsetup.sh
49
including device/geeksphone/one/vendorsetup.sh
50
including device/htc/ace/vendorsetup.sh
51 1 Denis 'GNUtoo' Carikli
including device/htc/bravoc/vendorsetup.sh
52
including device/htc/bravo/vendorsetup.sh
53 2 Denis 'GNUtoo' Carikli
including device/htc/buzz/vendorsetup.sh
54
including device/htc/glacier/vendorsetup.sh
55 1 Denis 'GNUtoo' Carikli
including device/htc/heroc/vendorsetup.sh
56
including device/htc/inc/vendorsetup.sh
57 2 Denis 'GNUtoo' Carikli
including device/htc/legend/vendorsetup.sh
58
including device/htc/liberty/vendorsetup.sh
59
including device/htc/supersonic/vendorsetup.sh
60
including device/htc/vision/vendorsetup.sh
61
including device/motorola/sholes/vendorsetup.sh
62
including device/nvidia/harmony/vendorsetup.sh
63
including vendor/cyanogen/vendorsetup.sh
64 66 Paul Kocialkowski
</pre>
65 37 Denis 'GNUtoo' Carikli
The last line is important:
66 66 Paul Kocialkowski
<pre>
67 37 Denis 'GNUtoo' Carikli
$ cat vendor/cyanogen/vendorsetup.sh
68
add_lunch_combo cyanogen_ace-eng
69
add_lunch_combo cyanogen_bravo-eng
70
add_lunch_combo cyanogen_bravoc-eng
71
add_lunch_combo cyanogen_buzz-eng
72
add_lunch_combo cyanogen_dream_sapphire-eng
73
add_lunch_combo cyanogen_espresso-eng
74
add_lunch_combo cyanogen_glacier-eng
75 1 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_harmony-eng
76 37 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_hero-eng
77 1 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_heroc-eng
78
add_lunch_combo cyanogen_inc-eng
79 37 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_legend-eng
80
add_lunch_combo cyanogen_liberty-eng
81
add_lunch_combo cyanogen_one-eng
82
add_lunch_combo cyanogen_passion-eng
83
add_lunch_combo cyanogen_sholes-eng
84 1 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_supersonic-eng
85
add_lunch_combo cyanogen_vibrant-eng
86 37 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_vision-eng
87 4 Denis 'GNUtoo' Carikli
add_lunch_combo cyanogen_z71-eng
88 1 Denis 'GNUtoo' Carikli
89
PATH=$PATH:$PWD/vendor/cyanogen/tools ; export PATH
90 66 Paul Kocialkowski
</pre>
91 37 Denis 'GNUtoo' Carikli
The output include the list of supported (by cyanogenmod) devices.
92 36 Michael Haas -
For instance if you have the Wildfire (codename 'buzz') phone do:
93 66 Paul Kocialkowski
<pre>
94 1 Denis 'GNUtoo' Carikli
lunch cyanogen_buzz-eng
95 66 Paul Kocialkowski
</pre>
96 1 Denis 'GNUtoo' Carikli
97 9 Denis 'GNUtoo' Carikli
Then build the source, backup what's on your device, including the operating system, and flash the new replicant image.
98 1 Denis 'GNUtoo' Carikli
99
Then test what works and what doesn't.
100
101
The images are located in 
102 66 Paul Kocialkowski
<pre>
103 1 Denis 'GNUtoo' Carikli
out/target/product/dream_sapphire
104 66 Paul Kocialkowski
</pre>
105 1 Denis 'GNUtoo' Carikli
in the case of the HTC Dream. You need to look in the path that corresponds to your device.
106 32 Michael Haas -
107
108 66 Paul Kocialkowski
h2. Trying free replacements
109
110
111 1 Denis 'GNUtoo' Carikli
The source code you just built contains some free replacements for the proprietary
112
libraries shipped by your phone vendor with the default firmware.
113
114 32 Michael Haas -
A list of proprietary libraries is available in
115 66 Paul Kocialkowski
<pre>
116 1 Denis 'GNUtoo' Carikli
device/htc/dream_sapphire/extract-files.sh
117 66 Paul Kocialkowski
</pre>
118 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
119 11 Denis 'GNUtoo' Carikli
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).
120 1 Denis 'GNUtoo' Carikli
121
122 66 Paul Kocialkowski
123
h3. RIL test
124
125 1 Denis 'GNUtoo' Carikli
I will take the example of how to use the free RIL (Radio Interface Library) to see if it works fine without modifications:
126
The proprietary RIL library (which you don't have in the phone) location is found looking at the extract-files.sh
127
here's a part of extract-files.sh:
128 66 Paul Kocialkowski
<pre>
129 1 Denis 'GNUtoo' Carikli
adb pull /system/lib/libhtc_ril.so ../../../vendor/htc/$DEVICE/proprietary/libhtc_ril.so
130 66 Paul Kocialkowski
</pre>
131 1 Denis 'GNUtoo' Carikli
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
132 14 Denis 'GNUtoo' Carikli
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).
133 1 Denis 'GNUtoo' Carikli
134
So looking at the above line the proprietary RIL is located here on the phone:
135 66 Paul Kocialkowski
<pre>
136 1 Denis 'GNUtoo' Carikli
/system/lib/libhtc_ril.so
137 66 Paul Kocialkowski
</pre>
138 15 Denis 'GNUtoo' Carikli
while the free ril is located here (known fact):
139 66 Paul Kocialkowski
<pre>
140 1 Denis 'GNUtoo' Carikli
/system/lib/libreference-ril.so
141 66 Paul Kocialkowski
</pre>
142 1 Denis 'GNUtoo' Carikli
In order to test the free RIL you could be tempted to do that:
143 66 Paul Kocialkowski
<pre>
144 1 Denis 'GNUtoo' Carikli
# ./adb remount
145
# ./adb shell
146
mv /system/lib/libreference-ril.so /system/lib/libhtc_ril.so
147 66 Paul Kocialkowski
</pre>
148 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:
149 66 Paul Kocialkowski
<pre>
150 1 Denis 'GNUtoo' Carikli
# ./adb shell
151
# setprop
152
usage: setprop <key> <value>
153 66 Paul Kocialkowski
</pre>
154 1 Denis 'GNUtoo' Carikli
What you can do to set the libre RIL is - possibly - this:
155 66 Paul Kocialkowski
<pre>
156 39 Konstantinos Karantias -
./adb shell
157
setprop rild.libpath /system/lib/libreference-ril.so
158
setprop rild.libargs -d/dev/smd0
159 66 Paul Kocialkowski
</pre>
160 13 Denis 'GNUtoo' Carikli
Here's how it looks on a working replicant on the HTC Dream:
161 66 Paul Kocialkowski
<pre>
162 13 Denis 'GNUtoo' Carikli
# ./adb shell
163
# getprop | grep ril
164 66 Paul Kocialkowski
[ro.ril.hsxpa]: r2
165
[ro.ril.gprsclass]: r10
166 12 Denis 'GNUtoo' Carikli
[rild.libpath]: [/system/lib/libreference-ril.so]
167
[rild.libargs]: [-d/dev/smd0]
168 1 Denis 'GNUtoo' Carikli
[init.svc.ril-daemon]: [running]
169 66 Paul Kocialkowski
[ro.ril.def.agps.mode]: r2
170 1 Denis 'GNUtoo' Carikli
[gsm.version.ril-impl]: [android reference-ril 1.0]
171 66 Paul Kocialkowski
</pre>
172
* /dev/smd0 is the (emulated) serial port
173
* /system/lib/libreference-ril.so is where to look for the RIL hardware specific library 
174 1 Denis 'GNUtoo' Carikli
175 39 Konstantinos Karantias -
Then, you can kill the ril daemon:
176 66 Paul Kocialkowski
<pre>
177 1 Denis 'GNUtoo' Carikli
./adb shell killall rild
178 66 Paul Kocialkowski
</pre>
179 1 Denis 'GNUtoo' Carikli
Then try the reference RIL. You can see debugging things and such by doing:
180 66 Paul Kocialkowski
<pre>
181 1 Denis 'GNUtoo' Carikli
./adb logcat -b radio
182 66 Paul Kocialkowski
</pre>
183 1 Denis 'GNUtoo' Carikli
184
That's also tested and worked on the gtklocker's HTC Hero, so I suppose it will work for the most HTC devices out there. If your device isn't listed anywhere, don't dare to try it.
185
186 64 Paul Kocialkowski
187 66 Paul Kocialkowski
h2. Replacing proprietary libraries for real
188
189
190 16 Denis 'GNUtoo' Carikli
On the HTC Dream the following proprietary libraries were replaced:
191 66 Paul Kocialkowski
(Refer to [[ProprietaryHtcDreamLibsReplacement]] for more up to date details(or fix it if it's less recent))
192 16 Denis 'GNUtoo' Carikli
193 1 Denis 'GNUtoo' Carikli
The first thing you will have to do is to modify the build system.
194
The key thing to do is to change 
195
196
197 66 Paul Kocialkowski
h3. RIL
198 1 Denis 'GNUtoo' Carikli
199 66 Paul Kocialkowski
200
201
h4. Android Reference RIL
202
203
204 1 Denis 'GNUtoo' Carikli
If the RIL you previously tried works fine, why not switching to it...directly in the build system.
205 16 Denis 'GNUtoo' Carikli
Here's the diff between A working RIL and a non-working RIL for the htcdream:
206 66 Paul Kocialkowski
<pre>
207 17 Denis 'GNUtoo' Carikli
android_device_htc_dream_sapphire$ git diff 5593d2899203ec378c306701788f1c43af9a6935 -- full_dream_sapphire.mk
208
diff --git a/full_dream_sapphire.mk b/full_dream_sapphire.mk
209 1 Denis 'GNUtoo' Carikli
index 9ec7feb..eb1b956 100644
210 17 Denis 'GNUtoo' Carikli
--- a/full_dream_sapphire.mk
211 1 Denis 'GNUtoo' Carikli
+++ b/full_dream_sapphire.mk
212 18 Denis 'GNUtoo' Carikli
@@ -40,7 +40,8 @@ PRODUCT_PROPERTY_OVERRIDES := \
213
     ro.media.dec.jpeg.memcap=10000000
214
 
215 32 Michael Haas -
 PRODUCT_PROPERTY_OVERRIDES += \
216 18 Denis 'GNUtoo' Carikli
-    rild.libpath=/system/lib/libhtc_ril.so \
217 19 Denis 'GNUtoo' Carikli
+    rild.libpath=/system/lib/libreference-ril.so \
218 1 Denis 'GNUtoo' Carikli
+    rild.libargs=-d/dev/smd0 \
219
     wifi.interface=tiwlan0
220
 
221
 # Time between scans in seconds. Keep it high to minimize battery drain.
222
223 66 Paul Kocialkowski
</pre>
224 64 Paul Kocialkowski
Note that full_dream_sapphire.mk is located here:
225 66 Paul Kocialkowski
<pre>
226 64 Paul Kocialkowski
device/htc/dream_sapphire/full_dream_sapphire.mk
227 66 Paul Kocialkowski
</pre>
228 65 Paul Kocialkowski
The diff is self-explanatory and how to do the change is left as an exercise to the reader.
229 64 Paul Kocialkowski
230 1 Denis 'GNUtoo' Carikli
In case the RIL need to be modified the sources are in :
231 66 Paul Kocialkowski
<pre>
232 1 Denis 'GNUtoo' Carikli
hardware/ril/reference-ril
233 66 Paul Kocialkowski
</pre>
234 64 Paul Kocialkowski
They are written in C.
235
236
237 66 Paul Kocialkowski
h4. HTC Generic RIL
238
239
240 64 Paul Kocialkowski
Another RIL has been written for MSM devices originally running Windows Mobile and is used on the Replicant project as it works better than the Android reference RIL on most devices.
241 66 Paul Kocialkowski
* It's originally hosted at: "https://gitorious.org/xdandroid/hardware_xdandroid-ril":https://gitorious.org/xdandroid/hardware_xdandroid-ril
242
* We made a copy of this with some modifications there: "https://gitorious.org/replicant/hardware_xdandroid-ril":https://gitorious.org/replicant/hardware_xdandroid-ril
243 1 Denis 'GNUtoo' Carikli
244 66 Paul Kocialkowski
*hardware/ril/libhtcgeneric-ril/Android.mk* :
245
<pre>
246 64 Paul Kocialkowski
BUILD_HTCGENERIC_RIL := false
247
248 1 Denis 'GNUtoo' Carikli
ifeq ($(TARGET_BOARD_PLATFORM),qsd8k)
249 64 Paul Kocialkowski
  BUILD_HTCGENERIC_RIL := true
250
else ifeq ($(TARGET_BOARD_PLATFORM),msm7x30)
251 32 Michael Haas -
  BUILD_HTCGENERIC_RIL := true
252 28 Denis 'GNUtoo' Carikli
else ifeq ($(TARGET_BOARD_PLATFORM),msm7k)
253
  BUILD_HTCGENERIC_RIL := true
254 32 Michael Haas -
endif
255 66 Paul Kocialkowski
</pre>
256 41 Denis 'GNUtoo' Carikli
257 1 Denis 'GNUtoo' Carikli
Then, on your device configuration, switch:
258 66 Paul Kocialkowski
259 68 Paul Kocialkowski
@rild.libpath=/system/lib/libreference-ril.so@
260 66 Paul Kocialkowski
to:
261 68 Paul Kocialkowski
@rild.libpath=/system/lib/libhtcgeneric-ril.so@
262 66 Paul Kocialkowski
263
h3. Audio libraries
264
265 56 Paul Kocialkowski
On the HTC dream the audio libraries were modified.
266 66 Paul Kocialkowski
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":http://gitorious.org/replicant/android_hardware_msm7k/commit/e0b55a19b2fc004915503ebdfd7c4c02c4264611.
267
Note several things on "the commit":http://gitorious.org/replicant/android_hardware_msm7k/commit/e0b55a19b2fc004915503ebdfd7c4c02c4264611:
268
* the routing was disabled, I had to re-enable it
269
* 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.
270
* I had nearly no knowledge of C++
271
* it was easy
272 1 Denis 'GNUtoo' Carikli
273
On the nexus one the proprietary libacoustic libraries are only used for bluetooth(all the rest works if you pushed the firmwares).
274
275 66 Paul Kocialkowski
On the dream (msm7k), libacoustic has been fully replaced, see "it loads the values from the /system/etc/AudioPara4.csv CSV file to MSM shared memory, which fixes in-call volume regulation and adds support for No Mic Wired Headset. It should also add support for other other things (probably including bluetooth devices) but this has not been tested yet. 
276 56 Paul Kocialkowski
The existing replacement code (hardware/msm7k/libaudio/AudioAcoustic.cpp) should work for your msm7k device but it has only been tested on the Dream. 
277
278 66 Paul Kocialkowski
*Note that (even if unconfirmed) it should more likely work the same way for every msm7k device, so try the code without any modification first and do the following steps only if the code does not work for your msm7k device! *
279 1 Denis 'GNUtoo' Carikli
280 66 Paul Kocialkowski
If it does not work, check that your device contains the /system/etc/AudioPara4.csv CSV file. If it does not, the file may have another name, then you should modify replicant code to use the filename of your device and test if it works.
281 1 Denis 'GNUtoo' Carikli
282 56 Paul Kocialkowski
To make sure it parses the CSV file, run adb logcat | grep Audio and find the following lines: 
283 66 Paul Kocialkowski
<pre>
284 56 Paul Kocialkowski
D/AudioAcousticMSM72XX(  122): Successfully opened /system/etc/AudioPara4.csv
285
D/AudioAcousticMSM72XX(  122): CSV Header: Dream_TMU_20090305
286 1 Denis 'GNUtoo' Carikli
D/AudioAcousticMSM72XX(  122): Read:
287 56 Paul Kocialkowski
D/AudioAcousticMSM72XX(  122): 24 Audio_Path_Table entries
288
D/AudioAcousticMSM72XX(  122): 24 Audio_Path_Uplink_Table entries
289 1 Denis 'GNUtoo' Carikli
D/AudioAcousticMSM72XX(  122): 35 Phone_Acoustic_Table entries
290 56 Paul Kocialkowski
D/AudioAcousticMSM72XX(  122): 35 BT_Phone_Acoustic_Table entries
291 1 Denis 'GNUtoo' Carikli
D/AudioAcousticMSM72XX(  122): 24 HTC_VOC_CAL_CODEC_TABLE_Table entries
292 56 Paul Kocialkowski
D/AudioAcousticMSM72XX(  122): 0 CE_Acoustic_Table entries
293 1 Denis 'GNUtoo' Carikli
</pre>
294 68 Paul Kocialkowski
295 66 Paul Kocialkowski
Then, if it parses the file but does not work, it's probably because the addresses (or the size) where the tables must be written in MSM shared memory are not the same for the Dream and for your device. 
296 56 Paul Kocialkowski
In order to find the correct addresses, you'll have to use [[CyanogenMod]] code with the non-free libhtc_acoustic.so lib that you can get from [[CyanogenMod]] downloadable zip for your device.
297 68 Paul Kocialkowski
298 66 Paul Kocialkowski
Then download [[CyanogenMod]] code:
299 68 Paul Kocialkowski
300 66 Paul Kocialkowski
Now you need to modify the kernel-side driver to print some useful infos on file kernel-msm/arch/arm/mach-msm/htc_acoustic.c, function acoustic_mmap(), add the following code:
301 68 Paul Kocialkowski
302 66 Paul Kocialkowski
<pre>
303 56 Paul Kocialkowski
D(" -- vma dump start --\n");
304
305
D("vm_start=%x (%d)\n", vma->vm_start, vma->vm_start);
306
D("vm_end=%x (%d)\n", vma->vm_end, vma->vm_end);
307
D("vm_page_prot=%x (%d)\n", vma->vm_page_prot,vma->vm_page_prot);
308
D("vm_flags=%x (%d)\n", vma->vm_flags, vma->vm_flags);
309
D("vm_pgoff=%x (%d)\n", vma->vm_pgoff, vma->vm_pgoff);
310
311 66 Paul Kocialkowski
D(" -- vma dump end --\n");
312 56 Paul Kocialkowski
</pre>
313 66 Paul Kocialkowski
314
<pre>
315
<6>[   22.250274":http://gitorious.org/replicant/android_hardware_msm7k/commit/c650b45892aa8be87f3e88ee6eae5df053a0a047]: htc-acoustic: open
316 56 Paul Kocialkowski
<6>[   22.252716] htc-acoustic: mmap
317
<6>[   22.253265] htc-acoustic:  -- vma dump start --
318
<6>[   22.254028] htc-acoustic: vm_start=4010c000 (1074839552)
319 1 Denis 'GNUtoo' Carikli
<6>[   22.254699] htc-acoustic: vm_end=40119000 (1074892800)
320
<6>[   22.255310] htc-acoustic: vm_page_prot=38f (911)
321 56 Paul Kocialkowski
<6>[   22.256011] htc-acoustic: vm_flags=400844ff (1074283775)
322
<6>[   22.256622] htc-acoustic: vm_pgoff=1f4a (8010)
323
<6>[   22.257293] htc-acoustic:  -- vma dump end --
324
<6>[   22.742675] htc-acoustic: ioctl
325
<6>[   22.743103] htc-acoustic: ioctl: ACOUSTIC_ARM11_DONE called 123.
326
<6>[   22.746612] htc-acoustic: ioctl: ONCRPC_ACOUSTIC_INIT_PROC success.
327 66 Paul Kocialkowski
<6>[   22.747344] htc-acoustic: release
328 56 Paul Kocialkowski
</pre>
329 66 Paul Kocialkowski
330
Now you can get the size of the dedicated memory area: vm_end - vm_start = 0x40119000 - 0x4010c000 = *0xd000*.
331
<pre>
332 56 Paul Kocialkowski
void acoustic_mmap_dump(void)
333 1 Denis 'GNUtoo' Carikli
{
334
	uint8_t *test_map_base;
335
	uint8_t *ptr, nval;
336
	int fd, fdd=0;
337 66 Paul Kocialkowski
	off_t [[TargetAddr]];
338 56 Paul Kocialkowski
	int len;
339
340
	fd = open("/dev/htc-acoustic", O_RDWR | O_SYNC);
341
	fdd = open("/data/dump", O_RDWR | O_TRUNC | O_CREAT);
342
343 1 Denis 'GNUtoo' Carikli
	test_map_base = (uint8_t *)
344
	    mmap(0, 0xd000, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
345
		 0);
346
//	test_virt_base = test_map_base + (TargetAddr & MAP_MASK);
347 66 Paul Kocialkowski
//	LOGD("virtual base at %p (phys=0x%X)\n", test_virt_base, [[TargetAddr]]);
348 1 Denis 'GNUtoo' Carikli
349
	LOGD(" -- htc-acoustic memory read -- \n");
350
	LOGD("beginning adress is@%p\n", test_map_base);
351 58 Paul Kocialkowski
          for (len = 0; len < 0xd000; len++)
352
		{
353
			if( write(fdd, test_map_base, sizeof(uint8_t) ) < 0)
354 1 Denis 'GNUtoo' Carikli
			{
355 58 Paul Kocialkowski
				LOGE("write failed");
356 1 Denis 'GNUtoo' Carikli
				break;
357
			}
358 58 Paul Kocialkowski
			//LOGD("0x%x (%d) @%p",  *(test_map_base), *(test_map_base), test_map_base);
359 1 Denis 'GNUtoo' Carikli
		  test_map_base++;
360 58 Paul Kocialkowski
		}
361
362
363
	munmap(test_map_base, 0xd000);
364
	close(fdd);
365
	close(fd);
366
}
367 66 Paul Kocialkowski
</pre>
368 68 Paul Kocialkowski
369
370 66 Paul Kocialkowski
<pre>
371 58 Paul Kocialkowski
#define ACOUSTIC_IOCTL_MAGIC 'p'
372
#define ACOUSTIC_NOTICE		_IOW(ACOUSTIC_IOCTL_MAGIC, 42, unsigned int)
373 1 Denis 'GNUtoo' Carikli
#define ACOUSTIC_ARM11_DONE	_IOW(ACOUSTIC_IOCTL_MAGIC, 22, unsigned int)
374 58 Paul Kocialkowski
375
void acoustic_mmap(void)
376
{
377 1 Denis 'GNUtoo' Carikli
	char *test_map_base;
378
	volatile int *ptr, nval;
379
	int fd, fdd;
380 66 Paul Kocialkowski
	off_t [[TargetAddr]];
381 58 Paul Kocialkowski
	int len;
382
383 1 Denis 'GNUtoo' Carikli
	fd = open("/dev/htc-acoustic", O_RDWR | O_SYNC);
384 58 Paul Kocialkowski
	fdd = open("/data/dump", O_RDWR);
385
386
	test_map_base = (char *)
387
	    mmap(0, 0xd000, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
388
		 0);
389 1 Denis 'GNUtoo' Carikli
//	test_virt_base = test_map_base + (TargetAddr & MAP_MASK);
390 66 Paul Kocialkowski
//	LOGD("virtual base at %p (phys=0x%X)\n", test_virt_base, [[TargetAddr]]);
391 58 Paul Kocialkowski
392
	LOGD(" -- htc-acoustic memory write -- \n");
393
          for (len = 0; len < 0xd000; len++)
394 1 Denis 'GNUtoo' Carikli
		{
395
		  read(fdd, test_map_base, sizeof(char) );
396
		  test_map_base++;
397
		}
398
399
400
	munmap(test_map_base, 0xd000);
401
	close(fdd);
402
	close(fd);
403
}
404 58 Paul Kocialkowski
405 1 Denis 'GNUtoo' Carikli
void acoustic_done(void)
406
{
407 58 Paul Kocialkowski
     int fd;
408
	       fd = open("/dev/htc-acoustic",O_RDWR);
409
410 1 Denis 'GNUtoo' Carikli
               if (fd < 0) {
411 58 Paul Kocialkowski
	            LOGE("Cannot open htc-acoustic device");
412
	            close(fd);
413
	            return;
414
               }
415
416
       ioctl(fd,ACOUSTIC_ARM11_DONE, NULL);
417
       close(fd);
418
}
419
</pre>
420 68 Paul Kocialkowski
421 1 Denis 'GNUtoo' Carikli
Now replace:
422 58 Paul Kocialkowski
<pre>
423 1 Denis 'GNUtoo' Carikli
    set_acoustic_parameters = (int (*)(void))::dlsym(acoustic, "set_acoustic_parameters");
424 66 Paul Kocialkowski
    if ((*set_acoustic_parameters) == 0 ) {
425 58 Paul Kocialkowski
        LOGE("Could not open set_acoustic_parameters()");
426
        return;
427
    }
428
429 1 Denis 'GNUtoo' Carikli
    int rc = set_acoustic_parameters();
430
    if (rc < 0) {
431 59 Paul Kocialkowski
        LOGE("Could not set acoustic parameters to share memory: %d", rc);
432
//        return;
433
    }
434 66 Paul Kocialkowski
</pre>
435 68 Paul Kocialkowski
436 66 Paul Kocialkowski
with:
437 68 Paul Kocialkowski
438 59 Paul Kocialkowski
<pre>
439 1 Denis 'GNUtoo' Carikli
acoustic_mmap();
440 66 Paul Kocialkowski
acoustic_done();
441 59 Paul Kocialkowski
</pre>
442 66 Paul Kocialkowski
443 59 Paul Kocialkowski
Replace the hardware/msm7k/ folder by the replicant one. The next step is to find the right addresses to write the tables in MSM shared memory. To find this out, you have to read the dump and understand where each table begins. So first, you have to hexdump the dump:
444 68 Paul Kocialkowski
445 66 Paul Kocialkowski
<pre>
446
00000000  35 71 36 61 37 00 38 00  39 03 3a 00 3b 00 3c 00  |5q6a7.8.9.:.;.<.|
447 59 Paul Kocialkowski
00000010  3d 00 3e 00 3f 00 40 00  41 1c 42 00 43 00 44 00  |=.>.?.@.A.B.C.D.|
448
00000020  45 00 46 00 47 00 48 00  49 00 4a 01 4b 00 4c 00  |E.F.G.H.I.J.K.L.|
449
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
450
*
451 1 Denis 'GNUtoo' Carikli
00000080  35 71 36 61 37 00 38 00  39 03 3a 00 3b 00 3c 00  |5q6a7.8.9.:.;.<.|
452 59 Paul Kocialkowski
00000090  3d 00 3e 00 3f 00 40 00  41 1c 42 00 43 00 44 00  |=.>.?.@.A.B.C.D.|
453
000000a0  45 00 46 00 47 00 48 00  49 00 4a 01 4b 00 4c 00  |E.F.G.H.I.J.K.L.|
454
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
455 66 Paul Kocialkowski
</pre>
456 68 Paul Kocialkowski
457 1 Denis 'GNUtoo' Carikli
it's the 2 first elements of the table we want to find the address (which will be 00000000, the beginning of the table). Now read [[AudioPara]]4.csv. On the dream, you can read:
458 66 Paul Kocialkowski
<pre>
459 59 Paul Kocialkowski
A0,HTC_VOC_CODEC_EARCUPLE_VOICE,35,71,36,61,37,0,38,0,39,3,3A,0,3B,0,3C,0,3D,0,3E,0,3F,0,40,0,41,1C,42,0,43,0,44,0,45,0,46,0,47,0,48,0,49,0,4A,1,4B,0,4C,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
460
A1,HTC_VOC_CODEC_EARCUPLE_MIDI,35,71,36,61,37,0,38,0,39,3,3A,0,3B,0,3C,0,3D,0,3E,0,3F,0,40,0,41,1C,42,0,43,0,44,0,45,0,46,0,47,0,48,0,49,0,4A,1,4B,0,4C,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
461 66 Paul Kocialkowski
</pre>
462
463 59 Paul Kocialkowski
Now if you read the [[ParseAudioParaLine]] function from [[AudioAcoustic]].cpp (on the already existing free audio acoustic code), you can see:
464 66 Paul Kocialkowski
<pre>
465
        case 'A':
466 59 Paul Kocialkowski
[…]
467 1 Denis 'GNUtoo' Carikli
            while ( (token = strtok(NULL, ",")) ) {
468
                Audio_Path_Table[table_num].array[field_count++] = strtol(token, &ps, 16);
469 59 Paul Kocialkowski
            };
470
            break;
471
</pre>
472 66 Paul Kocialkowski
473 59 Paul Kocialkowski
So "A" is for the Audio_Path_Table table. 
474
Now you have to do the same work for every table. You can see that another tables begins when the table-specific characters change e.g.:
475 68 Paul Kocialkowski
476 66 Paul Kocialkowski
<pre>
477 59 Paul Kocialkowski
00001780  35 00 36 00 37 ff 38 00  39 00 3a 00 3b 00 3c c4  |5.6.7.8.9.:.;.<.|
478
00001790  3d c4 3e 08 3f 80 40 05  41 00 42 00 43 00 44 00  |=.>.?.@.A.B.C.D.|
479
000017a0  45 00 46 00 47 00 48 00  49 00 4a 00 4b 00 4c 00  |E.F.G.H.I.J.K.L.|
480
000017b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
481
*
482
00001800  00 00 00 40 13 20 00 00  b2 7f fd 23 00 00 33 2d  |...@. .....#..3-|
483
00001810  00 00 80 0c 9a ff 80 1d  33 f3 ec 01 ee ff 0a 20  |........3...... |
484
00001820  65 7f 00 00 00 ed 00 00  00 00 d9 3f 00 00 80 0c  |e..........?....|
485 1 Denis 'GNUtoo' Carikli
00001830  9a ff 0c 1b 33 f3 ec 01  ee ff 0a 20 65 7f ff 7f  |....3...... e...|
486 59 Paul Kocialkowski
00001840  00 08 ff 7f 9f 14 00 00  14 00 00 08 00 20 00 20  |............. . |
487
00001850  fa 00 46 00 02 00 ff 02  40 00 20 00 50 46 40 00  |..F.....@. .PF@.|
488
00001860  a0 41 00 08 63 00 ff 4d  ff 4d 02 00 00 3f d0 07  |.A..c..M.M...?..|
489
00001870  00 00 00 00 00 01 00 01  00 02 50 00 00 03 50 01  |..........P...P.|
490
00001880  64 00 a8 1c c2 01 e0 2e  a0 0f ff ff 00 00 00 00  |d...............|
491
00001890  00 00 00 00 00 00 00 00  00 40 00 00 00 00 00 00  |.........@......|
492
000018a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
493
</pre>
494 66 Paul Kocialkowski
495 59 Paul Kocialkowski
You can see that a new table begins at 0x1800.
496
Note that some tables may not start at easy-to-find addresses such as 0x1800 but may start at in the middle of an hexdump line (so it makes the task even harder).
497
498
When you have found all the correct addresses for every table in your CSV file, you should check that your tables have the same size than the tables you got from the dump. If it's not, adjust the tables defined in [[AudioAcoustic]].h and the tables defined at the top of [[AudioAcoustic]].cpp. 
499 66 Paul Kocialkowski
When all that stuff is ok, it's possible that there is a necessary footer to make it work. On the Dream, it is:
500 42 Denis 'GNUtoo' Carikli
<pre>
501 66 Paul Kocialkowski
0000c8e0  78 56 34 12 00 00 00 00  00 00 00 00 00 00 00 00  |xV4.............|
502 1 Denis 'GNUtoo' Carikli
</pre>
503 68 Paul Kocialkowski
504 42 Denis 'GNUtoo' Carikli
(present at the end of the dump file).
505 1 Denis 'GNUtoo' Carikli
506
Now that you found out the size of the memory map, the address of each table, adjusted the size of the tables and found the footer, it's time to put the remaining infos on the free code.
507
Modify with the values you found out, on the file hardware/msm7k/libaudio/AudioAcoustic.cpp:
508 66 Paul Kocialkowski
<pre>
509 43 Denis 'GNUtoo' Carikli
static int mmap_size = 0xd000;
510 1 Denis 'GNUtoo' Carikli
static int mmap_address_audio_path_table = 0x0;
511
static int mmap_address_audio_path_uplink_table = 0xc00;
512
static int mmap_address_phone_acoustic_table = 0x1800;
513 43 Denis 'GNUtoo' Carikli
static int mmap_address_bt_phone_acoustic_table = 0x4a00;
514 1 Denis 'GNUtoo' Carikli
static int mmap_address_htc_voc_cal_codec_table_table = 0xc700;
515 66 Paul Kocialkowski
static int mmap_address_htc_acoustic_end = 0xc8e0;
516
</pre>
517 1 Denis 'GNUtoo' Carikli
and adapt the array sizes both on the top of [[AudioAcoustic]].cpp and [[AudioAcoustic]].h (if you didn't do it already).
518 43 Denis 'GNUtoo' Carikli
519 1 Denis 'GNUtoo' Carikli
Then build an image (make -j9 systemimage) and it should work. If it does not, please check that you successfully passed all the required steps. 
520
But the fact is that you replaced Dream values with the correct values for your device, so it will break audio acoustic for Dream.
521 66 Paul Kocialkowski
The solution would be to write a set_device_configuration() which selects the good values for the device we build replciant for and the appropriated tables. 
522 1 Denis 'GNUtoo' Carikli
Nothing like that has been written yet since replicant [[AudioAcoustic]] hasn't been ported to any other device yet. Please notify replicant developers to write such a function (or do it yourself) before you send the code.
523 66 Paul Kocialkowski
524
h3. GPS
525
526 43 Denis 'GNUtoo' Carikli
Two GPS libraries exist:
527 66 Paul Kocialkowski
* libgps
528
* libloc_api
529 43 Denis 'GNUtoo' Carikli
Both provide the same functionalities at the application level.
530
Choose the one that is supported by your device or that has support for a device close to your device.
531 66 Paul Kocialkowski
532
h4. libgps
533
534
For adding support to libgps you need to enable it like in "this commit":http://gitorious.org/replicant/android_device_htc_dream_sapphire/commit/153ab7e8fcf6bfc294b200d60a6f01feb5bb571a:
535 1 Denis 'GNUtoo' Carikli
add the following(or modify if it's already there but holds another value) in device/htc/dream_sapphire/BoardConfig.mk (replace dream_saphire by your device code) :
536 66 Paul Kocialkowski
<pre>
537 43 Denis 'GNUtoo' Carikli
BOARD_HAVE_GPS_HARDWARE := true
538
BOARD_GPS_LIBRARIES := libhardware
539 66 Paul Kocialkowski
</pre>
540 1 Denis 'GNUtoo' Carikli
I'm not sure if the "BOARD_HAVE_GPS_HARDWARE := true" is really needed.
541
542
If your device is different from the htc dream you may have to modify the GPS library code to match your device,
543
Here's the adaptation made for the htc dream:
544 66 Paul Kocialkowski
<pre>
545 43 Denis 'GNUtoo' Carikli
hardware/libhardware_legacy/gps$ diff -u ../../../../repos_external/phh_libhardware_legacy/gps/gps-rpc.c ./gps-rpc.c 
546
--- ../../../../repos_external/phh_libhardware_legacy/gps/gps-rpc.c	2010-08-15 11:35:03.210095153 +0200
547 1 Denis 'GNUtoo' Carikli
+++ ./gps-rpc.c	2011-01-06 16:46:45.417685002 +0100
548
@@ -464,8 +464,8 @@
549
 }
550 43 Denis 'GNUtoo' Carikli
 
551 1 Denis 'GNUtoo' Carikli
 int init_gps6125() {
552
-	struct CLIENT *clnt=clnt_create(NULL, 0x3000005B, 0, NULL);
553
-	struct CLIENT *clnt_atl=clnt_create(NULL, 0x3000001D, 0, NULL);
554
+	struct CLIENT *clnt=clnt_create(NULL, 0x3000005B, 0x90380d3d, NULL);
555
+	struct CLIENT *clnt_atl=clnt_create(NULL, 0x3000001D, 0x51c92bd8, NULL);
556 43 Denis 'GNUtoo' Carikli
 	int i;
557
 	_clnt=clnt;
558 1 Denis 'GNUtoo' Carikli
 	SVCXPRT *svc=svcrtr_create();
559
@@ -538,33 +538,21 @@
560
 
561
 
562
 int init_gps_rpc() {
563
-	int fd=open("/sys/class/htc_hw/amss", O_RDONLY);
564 66 Paul Kocialkowski
-	char bufr32;
565 1 Denis 'GNUtoo' Carikli
-	bzero(buf, 32);
566
-	read(fd, buf, 32);
567
-	if(strncmp(buf, "6125", 4)==0)
568
-		amss=A6125;
569 44 Denis 'GNUtoo' Carikli
-	else if((strncmp(buf, "5225", 4)==0) || (strncmp(buf, "6150", 4)==0))
570
-		amss=A5225;
571 1 Denis 'GNUtoo' Carikli
-	else
572
-		amss=A6125; //Fallback to 6125 ATM
573
-	if(amss==A6125)
574
-		init_gps6125();
575
-	else if(amss==A5225)
576
-		init_gps5225();
577
+	amss=A6125;
578
+	init_gps6125();
579 44 Denis 'GNUtoo' Carikli
 	return 0;
580 1 Denis 'GNUtoo' Carikli
 }
581
 
582
 void gps_get_position() {
583 44 Denis 'GNUtoo' Carikli
 	int i;
584 1 Denis 'GNUtoo' Carikli
-	for(i=5;i;--i) if(!can_send) sleep(1);//Time out of 5 seconds on can_send
585
+	for(i=3;i;--i) if(!can_send) sleep(1);//Time out of 5 seconds on can_send
586 44 Denis 'GNUtoo' Carikli
 	can_send=0;
587 1 Denis 'GNUtoo' Carikli
 	pdsm_get_position(_clnt, 0, 0, 1, 1, 1, 0x3B9AC9FF, 1, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,1,32,2,client_IDsr2);
588 66 Paul Kocialkowski
 }
589 1 Denis 'GNUtoo' Carikli
 
590
 void exit_gps_rpc() {
591
-	if(amss==A6125)
592 44 Denis 'GNUtoo' Carikli
-		pdsm_client_end_session(_clnt, 0, 2);
593 1 Denis 'GNUtoo' Carikli
+	//if(amss==A6125)
594 44 Denis 'GNUtoo' Carikli
+	//	pdsm_client_end_session(_clnt, 0, 2);
595
 	//5225 doesn't seem to like end_session ?
596 1 Denis 'GNUtoo' Carikli
 	//Bah it ends session on itself after 10seconds.
597
 }
598
</pre>
599 66 Paul Kocialkowski
600 1 Denis 'GNUtoo' Carikli
so let's go step by steps on that diff:
601 44 Denis 'GNUtoo' Carikli
First we see that:
602 1 Denis 'GNUtoo' Carikli
<pre>
603 66 Paul Kocialkowski
+	struct CLIENT *clnt=clnt_create(NULL, 0x3000005B, 0x90380d3d, NULL);
604 44 Denis 'GNUtoo' Carikli
+	struct CLIENT *clnt_atl=clnt_create(NULL, 0x3000001D, 0x51c92bd8, NULL);
605 1 Denis 'GNUtoo' Carikli
</pre>
606 68 Paul Kocialkowski
607 1 Denis 'GNUtoo' Carikli
This corresponds to some devices nodes:
608 66 Paul Kocialkowski
<pre>
609 1 Denis 'GNUtoo' Carikli
# ls -l /dev/oncrpc
610 44 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,   0 Jan  6 16:43 00000000:0
611
crw-rw----    1 radio    system    253,  11 Jan  6 16:43 30000000:5a10cf88
612
crw-rw----    1 radio    system    253,   9 Jan  6 16:43 30000002:aa2b1a44
613
crw-rw----    1 radio    system    253,   4 Jan  6 16:43 30000003:94103dec
614 1 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  30 Jan  6 16:43 3000000a:71d1094b
615
crw-rw----    1 radio    system    253,  28 Jan  6 16:43 3000000e:2bf06595
616 44 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  26 Jan  6 16:43 3000000f:46d257e5
617
crw-rw----    1 radio    system    253,  23 Jan  6 16:43 30000013:e94e8f0c
618 1 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  22 Jan  6 16:43 30000014:7cfcd2c6
619
crw-rw----    1 radio    system    253,  21 Jan  6 16:43 30000016:c713bd79
620
crw-rw----    1 radio    system    253,  19 Jan  6 16:43 30000019:acb4a896
621 44 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  18 Jan  6 16:43 3000001b:97d7b24a
622
crw-rw----    1 radio    system    253,  12 Jan  6 16:43 3000001d:51c92bd8
623
crw-rw----    1 radio    system    253,   8 Jan  6 16:43 30000021:f330a24e
624 1 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  14 Jan  6 16:43 3000003c:03d4377c
625 44 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  29 Jan  6 16:43 30000048:0da5b528
626
crw-rw----    1 radio    system    253,  17 Jan  6 16:43 30000059:00000000
627
crw-rw----    1 radio    system    253,  16 Jan  6 16:43 3000005a:00000000
628
crw-rw----    1 radio    system    253,  13 Jan  6 16:43 3000005b:90380d3d
629
crw-rw----    1 radio    system    253,   7 Jan  6 16:43 3000005f:95d1d9f5
630
crw-rw----    1 radio    system    253,   5 Jan  6 16:43 30000060:bcfb5d63
631
crw-rw----    1 radio    system    253,   2 Jan  6 16:43 30000061:fb837d0b
632
crw-rw----    1 radio    system    253,  31 Jan  6 16:43 30000066:1f4b343e
633
crw-rw----    1 radio    system    253,  27 Jan  6 16:43 3000006b:0aabc7a4
634
crw-rw----    1 radio    system    253,  25 Jan  6 16:43 3000006c:00000000
635 1 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  20 Jan  6 16:43 30000075:f708938d
636 44 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  15 Jan  6 16:43 30000079:00000000
637
crw-rw----    1 radio    system    253,   1 Jan  6 16:43 30000081:ccc5b439
638
crw-rw----    1 radio    system    253,  24 Jan  6 16:43 3000fe00:00000000
639
crw-rw----    1 radio    system    253,  10 Jan  6 16:43 3000fffe:00000000
640
crw-rw----    1 radio    system    253,   6 Jan  6 16:43 30100001:00000000
641
crw-rw----    1 radio    system    253,   3 Jan  6 16:43 30100002:00000000
642 66 Paul Kocialkowski
</pre>
643 68 Paul Kocialkowski
644 66 Paul Kocialkowski
Theses 2 lines should ring a bell:
645 1 Denis 'GNUtoo' Carikli
<pre>
646 66 Paul Kocialkowski
crw-rw----    1 radio    system    253,  13 Jan  6 16:43 3000005b:90380d3d
647 45 Denis 'GNUtoo' Carikli
crw-rw----    1 radio    system    253,  12 Jan  6 16:43 3000001d:51c92bd8
648
</pre>
649 66 Paul Kocialkowski
650 45 Denis 'GNUtoo' Carikli
Next there is that line:
651 66 Paul Kocialkowski
<pre>
652 45 Denis 'GNUtoo' Carikli
+	for(i=3;i;--i) if(!can_send) sleep(1);//Time out of 5 seconds on can_send
653
</pre>
654 68 Paul Kocialkowski
655 66 Paul Kocialkowski
This is the time between 2 requests, if you put it too low it can reboot your phone(it will crashes and reboot)
656
657
h4. libloc_api
658 50 Denis 'GNUtoo' Carikli
659
For adding support for libloc_api you need to modify the BOARD_GPS_LIBRARIES variable
660 66 Paul Kocialkowski
661 50 Denis 'GNUtoo' Carikli
"That repository":https://github.com/CyanogenMod/android_hardware_qcom_gps should have newer devices support(like in AOSP) and older too(like rmcc's commits)
662 66 Paul Kocialkowski
663
h4. testing
664
665
<pre>
666 45 Denis 'GNUtoo' Carikli
cd hardware/libhardware_legacy/tests/gpstest/
667 66 Paul Kocialkowski
mm
668 45 Denis 'GNUtoo' Carikli
</pre>
669 66 Paul Kocialkowski
gives you a gpstest binary, copy it to the device and run it, it'll tell you if it has a fix
670
671
h4. Note on the GPS
672 45 Denis 'GNUtoo' Carikli
673 42 Denis 'GNUtoo' Carikli
Note that messing with GPS can reboot(that is to say your phone crashes and reboots because of that) your phone on certain devices(like the htc dream or the nexus one).
674 51 Denis 'GNUtoo' Carikli
675
The GPS is attached to the modem on the htc dream and the nexus one.
676
The only way to request a fix or to activate it is trough a rpc mecanism that is between the modem and the CPU that runs Android.
677
That RPC mecanism uses shared memory between the modem and the CPU that runs Android.
678
679
On the htcdream and the nexusone a serial line is emulated on top of the RPC mecanism: the serial lines can be accesed at /dev/smd0 for the modem(AT commands) and /dev/smd27 for the GPS NMEA.
680 52 Denis 'GNUtoo' Carikli
So compatibility with applications that understand NMEA is garanteed.
681 51 Denis 'GNUtoo' Carikli
682 66 Paul Kocialkowski
Note that the GPS parsing library doesn't require to use NMEA, it could also uses the RPC directly(to be verified)
683
684
h3. Sensors
685 1 Denis 'GNUtoo' Carikli
686 52 Denis 'GNUtoo' Carikli
Devices with an hardware keyboard slide can rotate with the slide of the keyboard, so accelerometers are not strictly necessary. Examples of such device include the HTC dream.
687 51 Denis 'GNUtoo' Carikli
Other devices lack that hardware keyboard, and so the only way to rotate is trough theses accelerometers. Examples of such device include the nexus one.
688
689
The nexusone has akmd.free which is the free implementation of akmd, the sensor daemon(which handle rotation)
690 66 Paul Kocialkowski
691
h4. akmd.free
692
693 52 Denis 'GNUtoo' Carikli
akmd.free is located in:
694 66 Paul Kocialkowski
<pre>
695 52 Denis 'GNUtoo' Carikli
hardware/akmd_free
696 66 Paul Kocialkowski
</pre>
697 52 Denis 'GNUtoo' Carikli
it has currently(at the time of writing) support for akm8973+bma150 based sensors.
698
akmd.free was made specifically for the htc hero by its authors.
699
The device supported include the nexus one(tested) and the HTC hero(not tested,not activated).
700
701 66 Paul Kocialkowski
In order to activate the support for it you must add that in your [[BoardConfig]].mk
702
<pre>
703
BUILD_AKMD := true
704 52 Denis 'GNUtoo' Carikli
</pre>
705 66 Paul Kocialkowski
706 32 Michael Haas -
If you need to add support for other akm sensors  you could modify hardware/akmd_free/jni/Android.mk, for instance the nexusone had an issue with rotation beeing done in the reverse sense, so I did that:
707 66 Paul Kocialkowski
<pre>
708 63 Paul Kocialkowski
+#ifdef TARGET_DEVICE_NEXUSONE
709 66 Paul Kocialkowski
+    abuf[index] = Vector(-bma150_datar0, -bma150_datar1, bma150_datar2);
710 63 Paul Kocialkowski
+#else
711 66 Paul Kocialkowski
     abuf[index] = Vector(bma150_datar0, -bma150_datar1, bma150_datar2);
712 63 Paul Kocialkowski
+#endif
713 66 Paul Kocialkowski
</pre>
714 63 Paul Kocialkowski
And that:
715
<pre>
716 66 Paul Kocialkowski
ifeq ($(TARGET_DEVICE),passion)
717 63 Paul Kocialkowski
  LOCAL_CFLAGS += -DTARGET_DEVICE_NEXUSONE
718
endif
719 66 Paul Kocialkowski
</pre>
720
721
h3. Slowness issues
722 28 Denis 'GNUtoo' Carikli
723 66 Paul Kocialkowski
If the device is too slow without non-free libs, there can still be some workarounds:
724
* Adding debug.sf.hw=0 in the proprieties: in a makefile on the device files, add:
725 69 Paul Kocialkowski
726 66 Paul Kocialkowski
<pre>
727 23 Denis 'GNUtoo' Carikli
* Use TARGET_LIBAGL_USE_GRALLOC_COPYBITS with libagl: if your device uses gralloc+copybits, you can try a fix that improved the speed on Nexus One: in a makefile on the device files, add:
728 66 Paul Kocialkowski
729 23 Denis 'GNUtoo' Carikli
The commits with these fixes for Nexus One are:
730 66 Paul Kocialkowski
* https://gitorious.org/replicant/android_device_htc_passion/commit/86aeb1822a90b71e2cbb1af71200e759d98f4993
731
* https://gitorious.org/replicant/android_hardware_msm7k/commit/d2d79391f10789ed9d2f5dd818aac3b23c48d69e
732
733 24 Denis 'GNUtoo' Carikli
h2. Re-using source code
734
735
The previous source code re-used some public source code that was licensed under the Apache 2.0 license.
736
The ril will also re-use some public source code licensed under Apache 2.0.
737
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.
738 1 Denis 'GNUtoo' Carikli
It is even advised to look at the public apache 2.0 source code of other rils libraries or components of android.
739 66 Paul Kocialkowski
740
h3. Ril
741
742
* vilvord ril
743
* openmoko (android on freerunner) ril
744
745
h2. Source organization and commit access
746
747 24 Denis 'GNUtoo' Carikli
Until now we made some changes in the tree, but we want the changes to land upstream in replicant.
748
For instance let's say we modified only the ril path like in the ril section in 
749 66 Paul Kocialkowski
<pre>
750 24 Denis 'GNUtoo' Carikli
device/htc/dream_sapphire/full_dream_sapphire.mk 
751 1 Denis 'GNUtoo' Carikli
</pre>
752 70 Paul Kocialkowski
753 24 Denis 'GNUtoo' Carikli
first we save our modifications:
754 66 Paul Kocialkowski
<pre>
755 24 Denis 'GNUtoo' Carikli
cd device/htc/dream_sapphire/
756
git diff > git_diff.patch
757 1 Denis 'GNUtoo' Carikli
</pre>
758 70 Paul Kocialkowski
759 24 Denis 'GNUtoo' Carikli
then we find where is the root of the git repository we are in:
760 66 Paul Kocialkowski
<pre>
761 25 Denis 'GNUtoo' Carikli
cd replicant-2.2 #top replicant directory where everything is in
762
cd .repo
763
cat manifest.xml
764 1 Denis 'GNUtoo' Carikli
</pre>
765 70 Paul Kocialkowski
766 25 Denis 'GNUtoo' Carikli
and we find that:
767 66 Paul Kocialkowski
<pre>
768 25 Denis 'GNUtoo' Carikli
  <project path="device/htc/buzz" name="CyanogenMod/android_device_htc_buzz" remote="github" />
769 1 Denis 'GNUtoo' Carikli
</pre>
770 70 Paul Kocialkowski
771 25 Denis 'GNUtoo' Carikli
so...now our repository is in device/htc/buzz
772 26 Denis 'GNUtoo' Carikli
We will now look where the source repository is:
773 66 Paul Kocialkowski
<pre>
774 27 Denis 'GNUtoo' Carikli
cd device/htc/buzz
775 26 Denis 'GNUtoo' Carikli
cd .git
776
cat config
777 1 Denis 'GNUtoo' Carikli
</pre>
778 70 Paul Kocialkowski
779 26 Denis 'GNUtoo' Carikli
We find that:
780 66 Paul Kocialkowski
<pre>
781 26 Denis 'GNUtoo' Carikli
	url = git://github.com/CyanogenMod/android_device_htc_buzz.git
782 66 Paul Kocialkowski
</pre>
783 32 Michael Haas -
784 1 Denis 'GNUtoo' Carikli
Then create a directory, not under the replicant-2.2 directory that will contain your repositories:
785 66 Paul Kocialkowski
<pre>
786 27 Denis 'GNUtoo' Carikli
mkdir repo
787
cd repo
788 1 Denis 'GNUtoo' Carikli
</pre>
789 70 Paul Kocialkowski
790 27 Denis 'GNUtoo' Carikli
and clone the source:
791 66 Paul Kocialkowski
<pre>
792 1 Denis 'GNUtoo' Carikli
git clone git://github.com/CyanogenMod/android_device_htc_buzz.git
793
cd android_device_htc_buzz
794
</pre>
795 70 Paul Kocialkowski
796 1 Denis 'GNUtoo' Carikli
apply the previous patch:
797 66 Paul Kocialkowski
<pre>
798 1 Denis 'GNUtoo' Carikli
git apply path/to/git_diff.patch
799
</pre>
800 70 Paul Kocialkowski
801 1 Denis 'GNUtoo' Carikli
commit locally the result:
802 66 Paul Kocialkowski
<pre>
803 1 Denis 'GNUtoo' Carikli
git commit -s
804
</pre>
805 70 Paul Kocialkowski
806 1 Denis 'GNUtoo' Carikli
Note that the commit message should have the following format:
807
The first line should be a summary
808
Followed by a linebreak
809
And then the details explaining the commit
810 66 Paul Kocialkowski
If you made an error writing the commit message do
811 1 Denis 'GNUtoo' Carikli
<pre>
812 66 Paul Kocialkowski
git commit --amend
813 1 Denis 'GNUtoo' Carikli
</pre>
814
815
TODO: complete for sending the git patch(git format-patch -1,git send-email)
816 66 Paul Kocialkowski
817
h4. Pushing to replicant
818
819 1 Denis 'GNUtoo' Carikli
TODO: git remote add+git push