Project

General

Profile

Actions

DeprecatedPortingGuideMSMQSD » History » Revision 28

« Previous | Revision 28/72 (diff) | Next »
Denis 'GNUtoo' Carikli, 12/25/2010 12:39 AM


Introduction
Many people bought many different phones, and some of them whish to help replicant and/or to port replicant to their phones or devices.
This guide will show what was done for the htc dream, so theses people could understand the process better. Build the source

The first thing to do is to download the replicant sources:
[wiki:BuildDream] can be used as a reference: download and build the sources for your device.
Let's say the user has an htc wildfire.

The main difference will be that instead of doing that: {{{
lunch cyanogen_dream_sapphire-eng
}}}
you would need to identify the right command that correspond to your device, so in order to do that:
when you run the following command look at the output. {{{
$ source build/envsetup.sh
including device/geeksphone/one/vendorsetup.sh
including device/htc/ace/vendorsetup.sh
including device/htc/bravoc/vendorsetup.sh
including device/htc/bravo/vendorsetup.sh
including device/htc/buzz/vendorsetup.sh
including device/htc/glacier/vendorsetup.sh
including device/htc/heroc/vendorsetup.sh
including device/htc/inc/vendorsetup.sh
including device/htc/legend/vendorsetup.sh
including device/htc/liberty/vendorsetup.sh
including device/htc/supersonic/vendorsetup.sh
including device/htc/vision/vendorsetup.sh
including device/motorola/sholes/vendorsetup.sh
including device/nvidia/harmony/vendorsetup.sh
including vendor/cyanogen/vendorsetup.sh
}}}
The output include the list of supported(by cyanogenmod) devices.
For instance if you have the bravo phone do: {{{
$ cat device/htc/buzz/vendorsetup.sh #
  1. Copyright (C) 2008 The Android Open Source Project #
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at #
  5. http://www.apache.org/licenses/LICENSE-2.0 #
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. #
  1. This file is executed by build/envsetup.sh, and can use anything
  2. defined in envsetup.sh. #
  3. In particular, you can add lunch options with the add_lunch_combo
  4. function: add_lunch_combo generic-eng

add_lunch_combo generic_buzz-eng
}}}
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.
then instead of typing that: {{{
lunch cyanogen_dream_sapphire-eng
}}}
type what correspond to your device: {{{
lunch generic_buzz-eng
}}}
Then build the source, backup what's on your device, including the operating system, and flash the new replicant image.

Then test what works and what doesn't.

The images are located in {{{
out/target/product/dream_sapphire
}}}
in the case of the htcdream, look in the path that correspond to your device.

Trying free replacements

As you built The source code you now have some libraries that could replace the proprietary libraries.
The list of proprietary libraries are available in {{{
device/htc/dream_sapphire/extract-files.sh
}}}
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)

=== Ril test ===
I will take the example of how to use the free ril to see if it works fine without modifications:
The proprietary ril library(which you don't have in the phone) location is found looking at the extract-files.sh
here's a part of extract-files.sh: {{{
adb pull /system/lib/libhtc_ril.so ../../../vendor/htc/$DEVICE/proprietary/libhtc_ril.so
}}}
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)
So looking at the above line the proprietary ril is located here: {{{
/system/lib/libhtc_ril.so
}}}
while the free ril is located here(known fact): {{{
/system/lib/libreference-ril.so
}}}
In order to test the free ril you could be tempted to do that: {{{
  1. ./adb remount
  2. ./adb shell
    mv /system/lib/libreference-ril.so /system/lib/libhtc_ril.so
    }}}
    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: {{{
  3. ./adb shell
  4. setprop
    usage: setprop <key> <value>
    }}}
    Here's how it looks on a working replicant on the htcdream: {{{
  5. ./adb shell
  6. getprop | grep ril
    [ro.ril.hsxpa]: [2]
    [ro.ril.gprsclass]: [10]
    [rild.libpath]: [/system/lib/libreference-ril.so]
    [rild.libargs]: [-d/dev/smd0]
    [init.svc.ril-daemon]: [running]
    [ro.ril.def.agps.mode]: [2]
    [gsm.version.ril-impl]: [android reference-ril 1.0]
    }}} * /dev/smd0 is the (emulated)serial port * /system/lib/libreference-ril.so is where to look for the ril hardware specific library

Then change the following properties and reboot: {{{
./adb shell reboot
}}}
Then tryout the reference ril.

Replace proprietary libraries for real

On the htcdream the following proprietary libraries were replaced:
( Refer to [wiki:ProprietaryHtcDreamLibsReplacement] for more up to date details(or fix it if it's less recent) )

The first thing you will have to do is to modify the build system.
The key thing to do is to change

=== ril ===
if the ril you previously tried works fine, why not switching to it...directly in the build system.
Here's the diff between A working ril and a non-working ril for the htcdream: {{{
android_device_htc_dream_sapphire$ git diff 5593d2899203ec378c306701788f1c43af9a6935 -- full_dream_sapphire.mk
diff --git a/full_dream_sapphire.mk b/full_dream_sapphire.mk
index 9ec7feb..eb1b956 100644
--- a/full_dream_sapphire.mk
+++ b/full_dream_sapphire.mk
@ -40,7 +40,8 @ PRODUCT_PROPERTY_OVERRIDES := \
ro.media.dec.jpeg.memcap=10000000

PRODUCT_PROPERTY_OVERRIDES = \
- rild.libpath=/system/lib/libhtc_ril.so \
rild.libpath=/system/lib/libreference-ril.so \
+ rild.libargs=-d/dev/smd0 \
wifi.interface=tiwlan0
  1. Time between scans in seconds. Keep it high to minimize battery drain.

}}}
Note that full_dream_sapphire.mk is located here: {{{
device/htc/dream_sapphire/full_dream_sapphire.mk
}}}
The diff is self-explanatory and how to do the change is left as an exercise to the reader.

In case the ril need to be modified the sources are in : {{{
hardware/ril/reference-ril
}}}
They are written in C.

=== Audio libraries ===
On the htcdream the audio libraries were modified.
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: {{{
commit e0b55a19b2fc004915503ebdfd7c4c02c4264611
Author: Denis 'GNUtoo' Carikli <>
Date: Thu Dec 23 16:49:35 2010 +0100

libaudio: AudioHardware: don't depend on the proprietary libhtc_acoustic.so for routing
/system/lib/libhtc_acoustic.so is proprietary(and not redistributable),
so we don't depend on it, but still we want audio routing
This commit was inspired from a previous commit I made(for replicant 1.5):
http://gitorious.org/replicant/msm7k/commit/6d13023d634e54814ecc74b22f77de27f1b8ac2c
Signed-off-by: Denis 'GNUtoo' Carikli &lt;&gt;

diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp
index 78b6a3e..af63e5a 100644
--- a/libaudio/AudioHardware.cpp
++ b/libaudio/AudioHardware.cpp
@ -43,6 +43,74 @ const uint32_t AudioHardware::inputSamplingRates[] = {
8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
};
// ----------------------------------------------------------------------------
+static int snd_get_endpoint(int cnt,msm_snd_endpoint * ept){
int fd;
+ int status;
+ fd = open("/dev/msm_snd",O_RDWR);
+ if (fd < 0) {
+ LOGE;
+ close(fd);
+ return -1;
+ }
+ status = ioctl(fd,SND_GET_ENDPOINT, ept);
+ close(fd);
+ return status;
}

static int snd_get_num(){
int fd;
+ int status;
+ int mNumSndEndpoints;
+ fd = open("/dev/msm_snd",O_RDWR);
+ if (fd < 0) {
+ LOGE;
+ return -1;
+ }

if(ioctl(fd,SND_GET_NUM_ENDPOINTS,&mNumSndEndpoints)<0 ) {
+ LOGE;
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return mNumSndEndpoints;
}

static int msm72xx_enable_audpp (uint16_t enable_mask)
{
+ int fd;


+ fd = open ("/dev/msm_pcm_ctl", O_RDWR);
+ if (fd < 0) {
+ LOGE ("Cannot open audio device");
+ return -1;
+ }

if (enable_mask & ADRC_ENABLE) {
+ enable_mask &= ~ADRC_ENABLE;
+ }
+ if (enable_mask & EQ_ENABLE) {
+ enable_mask &= ~EQ_ENABLE;
+ }
+ if (enable_mask & RX_IIR_ENABLE) {
+ enable_mask &= ~RX_IIR_ENABLE;
+ }

printf ("msm72xx_enable_audpp: 0x%04x", enable_mask);
+ if (ioctl (fd, AUDIO_ENABLE_AUDPP, &enable_mask) < 0) {
+ LOGE ("enable audpp error");
+ close (fd);
+ return -1;
+ }

close (fd);
+ return 0;
}

static int set_acoustic_parameters(){
return 0;
+}

AudioHardware::AudioHardware() :
mInit(false), mMicMute(true), mBluetoothNrec(true), mBluetoothId(0),
@ -63,38 +131,10 @ AudioHardware::AudioHardware() :
SND_DEVICE_BT_EC_OFF(-1) {

- int (*snd_get_num)();
- int (*snd_get_endpoint)(int, msm_snd_endpoint *);
- int (*set_acoustic_parameters)();
-
struct msm_snd_endpoint *ept;

- acoustic = ::dlopen("/system/lib/libhtc_acoustic.so", RTLD_NOW);
- if (acoustic == NULL ) {
- LOGE;
- /* this is not really an error on non-htc devices... /
- mNumSndEndpoints = 0;
- mInit = true;
- return;
- }

set_acoustic_parameters = (int (
)(void))::dlsym(acoustic, "set_acoustic_parameters");
- if ((set_acoustic_parameters) == 0 ) {
- LOGE");
- return;
- }

int rc = set_acoustic_parameters();
- if (rc < 0) {
- LOGE;
// return;
}

snd_get_num = (int (
)(void))::dlsym(acoustic, "snd_get_num_endpoints");
- if ((*snd_get_num) == 0 ) {
- LOGE");
// return;
}
+ LOGI;
+ mInit = true;

mNumSndEndpoints = snd_get_num();
LOGD("mNumSndEndpoints = %d", mNumSndEndpoints);
@ -102,11 +142,6 @ AudioHardware::AudioHardware() :
mInit = true;
LOGV("constructed %d SND endpoints)", mNumSndEndpoints);
ept = mSndEndpoints;
- snd_get_endpoint = (int (*)(int, msm_snd_endpoint *))::dlsym(acoustic, "snd_get_endpoint");
- if ((*snd_get_endpoint) == 0 ) {
- LOGE("Could not open snd_get_endpoint()");
- return;
- }
for (int cnt = 0; cnt < mNumSndEndpoints; cnt++, ept++) {
ept->id = cnt;
@ -488,17 +523,14 @ status_t AudioHardware::doAudioRouteOrMute(uint32_t device)
mMode != AudioSystem::MODE_IN_CALL, mMicMute);
}



status_t AudioHardware::doRouting() {
- /* currently this code doesn't work without the htc libacoustic */
- if (!acoustic)
- return 0;

Mutex::Autolock lock(mLock);
uint32_t outputDevices = mOutput->devices();
status_t ret = NO_ERROR;
- int (msm72xx_enable_audpp)(int);
- msm72xx_enable_audpp = (int (
)(int))::dlsym(acoustic, "msm72xx_enable_audpp");
int audProcess = (ADRC_DISABLE | EQ_DISABLE | RX_IIR_DISABLE);
AudioStreamInMSM72xx *input = getActiveInput_l();
uint32_t inputDevice = (input == NULL) ? 0 : input->devices();
@ -576,11 +608,7 @ status_t AudioHardware::doRouting()
if (sndDevice != 1 && sndDevice != mCurSndDevice) {
ret = doAudioRouteOrMute(sndDevice);
if ((*msm72xx_enable_audpp) == 0 ) {
- LOGE("Could not open msm72xx_enable_audpp()");
- } else {
- msm72xx_enable_audpp(audProcess);
- }
+ msm72xx_enable_audpp(audProcess);
mCurSndDevice = sndDevice;
}
}}}
Re-using source code
The previous source code re-used some public source code that was licensed under the apache 2.0 license.
The ril will also re-use some public source code licensed under the apache 2.0.
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.
It is even advised to look at the public apache 2.0 source code of other rils libraries or components of android.

=== Ril === * vilvord ril * openmoko (android on freerunner) ril

Source organization and commit access
Until now we made some changes in the tree, but we want the changes to land upstream in replicant.
For instance let's say we modified only the ril path like in the ril section in {{{
device/htc/dream_sapphire/full_dream_sapphire.mk
}}}
first we save our modifications: {{{
cd device/htc/dream_sapphire/
git diff > git_diff.patch
}}}
then we find where is the root of the git repository we are in: {{{
cd replicant-2.2 #top replicant directory where everything is in
cd .repo
cat manifest.xml
}}}
and we find that: {{{
<project path="device/htc/buzz" name="CyanogenMod/android_device_htc_buzz" remote="github" />
}}}
so...now our repository is in device/htc/buzz
We will now look where the source repository is: {{{
cd device/htc/buzz
cd .git
cat config
}}}
We find that: {{{
url = git://github.com/CyanogenMod/android_device_htc_buzz.git
}}}

Then create a directory, not under the replicant-2.2 directory that will contain your repositories: {{{
mkdir repo
cd repo
}}}
and clone the source: {{{
git clone git://github.com/CyanogenMod/android_device_htc_buzz.git
cd android_device_htc_buzz
}}}
apply the previous patch: {{{
git apply path/to/git_diff.patch
}}}
commit locally the result: {{{
git commit -s
}}}
Note that the commit message should have the following format:
The first line should be a sumarry
Then there should be a linebreak
And then the details explaining the commit
If you made an error writing the commit message do {{{
git commit --amend
}}}

TODO: complete for sending the git patch(git format-patch -1,git send-email)

==== Pushing to replicant ====
TODO: git remote add+git push

Updated by Denis 'GNUtoo' Carikli over 14 years ago · 28 revisions

Also available in: PDF HTML TXT