tag:blogger.com,1999:blog-23653885414014906432023-11-15T05:47:36.270-08:00Test driveTest Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-2365388541401490643.post-34000167431293658112012-12-04T16:32:00.001-08:002012-12-04T16:32:21.745-08:00My first day with openstack---development environment setup<span style="font-family: Georgia, Times New Roman, serif;">I want to add new extension to Openstack Quantum. Before I can do any coding, I need to have a decent development environment. The developer guide on the Openstack.org wiki does not really help much for me. With some googling, I came cross a github page:https://gi<wbr></wbr>thub.com/b<wbr></wbr>cwaldon/va<wbr></wbr>grant_devs<wbr></wbr>tack</span><br />
<div>
<span style="font-family: Georgia, Times New Roman, serif;">Here are what I did to create my first openstack development environment:</span><br />
<span style="font-family: Georgia, 'Times New Roman', serif;">1. git clone https://github.com/bcwaldon/vagrant_devstack </span><br />
<span style="font-family: Georgia, 'Times New Roman', serif;"><br /></span>
<span style="font-family: Georgia, 'Times New Roman', serif;">2. cd vagrant_devstack</span><br />
<span style="font-family: Georgia, 'Times New Roman', serif;"> based on the README, I also added submodules </span><br />
<br />
<span style="font-family: Georgia, 'Times New Roman', serif;"> git submodule init</span><br />
<span style="font-family: Georgia, 'Times New Roman', serif;"> git submodule update</span><br />
<div>
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span></div>
<br />
<span style="font-family: Georgia, 'Times New Roman', serif;">3. vagrant up</span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif;">In the Vagrantfile, it tries to download vagrant box from http://c479942.r42.cf2.rackcdn.com/precise64.box, but the file is not there anymore. I googled again and found this one http://dl.dropbox.com/u/1537815/precise64.box. I changed Vagrantfile to use the new box and restarted "vagrant up".</span></div>
<div>
<br />
After waiting for sometime, I see following error message<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">"<span style="font-size: x-small;">Mounting NFS shared folders failed. This is most often caused by the NFS </span></span><span style="font-size: x-small;"><span style="font-family: 'Courier New', Courier, monospace;">client software not being installed on the guest machine. Please verify </span><span style="font-family: 'Courier New', Courier, monospace;">that the NFS client software is properly installed, and consult any resources </span><span style="font-family: 'Courier New', Courier, monospace;">specific to the linux distro you're using for more information on how to </span></span><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: x-small;">do this.</span>"</span><br />
<div>
<br /></div>
<div>
Most likely, you have a dirty vagrant environment, try vagrant reload to see if the problem goes away.</div>
<div>
<br /></div>
<br />
<span style="font-family: Georgia, Times New Roman, serif;">After a good a mount of time waiting on devstack to be installed, I hit on following error:</span><br />
<span style="font-family: Georgia, Times New Roman, serif;">"</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+ sudo rm -rf /home/vagrant/cache /home/vagrant/devstack /home/vagrant/postinstall.sh</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">rm: cannot remove `/home/vagrant/cache': Device or resource busy</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">++ failed</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">++ local r=1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">+++ jobs -p</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">++ kill</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">++ set +o xtrace</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">---- End output of su -c 'set -e; cd /home/vagrant/devstack; RECLONE=yes bash stack.sh > devstack.log' vagrant ----</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Ran su -c 'set -e; cd /home/vagrant/devstack; RECLONE=yes bash stack.sh > devstack.log' vagrant returned 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Chef never successfully completed! Any errors should be visible in the</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">output above. Please fix your recipes so that they properly complete.</span><br />
<div>
"</div>
<span style="font-family: Georgia, 'Times New Roman', serif; line-height: 16px;">To understand the problem, I did vagrant ssh and login to my VM. It seems that the original devstack directory has been removed. I did another git clone </span><span style="font-family: Georgia, 'Times New Roman', serif;">git://github.com/openstack-dev/devstack.git to get the devstack. Then I manually run stack.sh. It seems that at the end of lib/nova:cleanup_nova, the function tries to clean out the instances directory and the cache directory is among the deleting directories. But this directory is really mounted from my host machine by vagrant. The quick and dirty fix for this is to not to cleanup directory</span><br />
<span style="font-family: Georgia, 'Times New Roman', serif;"><br /></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif;">agrant@precise64:~/devstack/lib$ git diff .</span><span style="font-family: Menlo, Monaco, Courier New, monospace; font-size: x-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">diff --git a/lib/nova b/lib/nova
index fbb5a01..ae4554d 100644
--- a/lib/nova
+++ b/lib/nova
@@ -102,7 +102,7 @@ function cleanup_nova() {
sudo iscsiadm --mode node | grep $VOLUME_NAME_PREFIX | cut -d " " -f2 | sudo iscsiadm --mode node --op delete || true
# Clean out the instances directory.
- sudo rm -rf $NOVA_INSTANCES_PATH/*
+ #sudo rm -rf $NOVA_INSTANCES_PATH/*
fi
}</span></div>
<div>
<br /></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">Since I have a changed devstack tree in my VM, I don't want cookbook script to re-clone the devstack tree. I have changed vagrant_devstack/cookbooks/devstack/recipes/default.rb to not clone devstack source code by disable following commands:</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;"></span><br /></span>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;">execute "git clone #{node[:devstack][:repository]}" do</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> cwd node[:devstack][:dir]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> user node[:devstack][:user]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> group node[:devstack][:group]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> not_if { File.directory?("#{node[:devstack][:dir]}/devstack") }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;">end</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;">execute "git checkout #{node[:devstack][:branch]}" do</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> cwd "#{node[:devstack][:dir]}/devstack"</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> user node[:devstack][:user]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;"> group node[:devstack][:group]</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;">end</span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-size: x-small;"><br /></span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-family: Georgia, Times New Roman, serif;">I'm not familiar with cookbook, I thought that</span><span style="font-family: Menlo, Monaco, Courier New, monospace; font-size: x-small;"> "not_if { File.directory?("#{node[:</span>devstack<span style="font-family: Menlo, Monaco, Courier New, monospace; font-size: x-small;">][:</span>dir<span style="font-family: Menlo, Monaco, Courier New, monospace; font-size: x-small;">]}/</span>devstack<span style="font-family: Menlo, Monaco, Courier New, monospace; font-size: x-small;">")" </span><span style="font-family: Georgia, Times New Roman, serif;">will avoid to overwrite my devstack directory on VM. But it seems that my devstack directory got wipe out everytime. Anyway, quickly disable lines above,solved my problem.</span></div>
<div style="font-family: Menlo, Monaco, 'Courier New', monospace; line-height: 18px; white-space: pre-wrap;">
<span style="font-size: x-small;"><br /></span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-family: Georgia, Times New Roman, serif;">After changed script, I did vagrant reload in my host directory, the vagrant reload failed immediately while the cookbook tries to relink my host public key to the VM ~/.ssh/id_rsa. The quick fix for this is go to vagrant-openstack/recipes/cache.rb and fix following commands</span><br />
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">execute "ln -s /home/#{u}/.host-ssh/id_rsa /home/#{u}/.ssh/id_rsa" </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">do</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> user u</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> group u</span><br />
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> not_if { File.exists?("/home/#{u}/.ssh/id_rsa") }</span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">end</span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-family: Georgia, Times New Roman, serif;">Again, I thought not_if statement should avoid the file relink is id_rsa is there already. But it seems that</span><span style="font-family: Menlo, Monaco, Courier New, monospace; font-size: x-small;"> not_if </span><span style="font-family: Georgia, Times New Roman, serif;">does not work.</span></div>
<div style="font-family: Menlo, Monaco, 'Courier New', monospace; line-height: 18px; white-space: pre-wrap;">
<span style="font-size: x-small;"><br /></span></div>
<div style="line-height: 18px; white-space: pre-wrap;">
<span style="font-family: Georgia, Times New Roman, serif;">After all these changes, my vagrant up finished successfully. I have devstack up running. By default, the devstack does not enable quantum. But it is what I really need. To enable quantum + openvswitch, I did following changes:</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;">diff --git a/stackrc b/stackrc
index 01e9556..f47ad40 100644
--- a/stackrc
+++ b/stackrc
@@ -14,7 +14,9 @@ DATABASE_TYPE=mysql
# ``disable_service`` functions in ``localrc``.
# For example, to enable Swift add this to ``localrc``:
# enable_service swift
-ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE
+ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE,quantum,q-svc,q-agt
+Q_PLUGIN=openvswitch</span></div>
<div>
<span style="font-size: x-small;"><span style="font-family: Courier New, Courier, monospace; line-height: 18px; white-space: pre-wrap;">+ENABLE_TENANT_TUNNELS=True</span><span style="font-family: Menlo, Monaco, 'Courier New', monospace; line-height: 18px; white-space: pre-wrap;">
</span></span></div>
<div style="font-family: Menlo, Monaco, 'Courier New', monospace;">
<span style="font-size: x-small; line-height: 18px; white-space: pre-wrap;"><br /></span></div>
<div>
<span style="font-family: Menlo, Monaco, 'Courier New', monospace; font-size: x-small; line-height: 18px; white-space: pre-wrap;">A</span><span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">fter restart devstack, the quantum is up running.</span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;"><br /></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">Now on my host directory, I have a cache/stack directory that has all the devstack source code. The /opt/stack on the VM has a running copy of the devstack. I did a </span><span style="font-family: Courier New, Courier, monospace; line-height: 18px; white-space: pre-wrap;">git branch work</span><span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">; </span><span style="font-family: Courier New, Courier, monospace; line-height: 18px; white-space: pre-wrap;">git checkout work </span><span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">on all the directories under cache/stack so that we can have a dev branch.</span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;"><br /></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif;"><span style="line-height: 18px; white-space: pre-wrap;">Next, I will need to find a IDE to do my developemnt. eclipse+pydev+egit seems a good choice for me. First. I installed eclipse, then from </span><span style="line-height: 18px; white-space: pre-wrap;">http://pydev.org/updates, I installed pydev. From </span><span style="line-height: 18px; white-space: pre-wrap;">http://download.eclipse.org/egit/updates, I installed egit.</span></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">I used egit to import all the git repos from cache/stack directory. And then convert each of repo into general project. Switching to pydev perspective, right click on project names that just imported, select PyDev and set the project as PyDev project.</span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;"><br /></span></div>
<div>
<span style="font-family: Georgia, Times New Roman, serif; line-height: 18px; white-space: pre-wrap;">That is it, next, I will need to find out what "not_if" means and how fix the cookbook script so that I can make a right patch.</span></div>
<div style="font-family: Menlo, Monaco, 'Courier New', monospace;">
<span style="font-size: x-small; line-height: 18px; white-space: pre-wrap;"><br /></span></div>
<div style="font-family: Menlo, Monaco, 'Courier New', monospace;">
<br /></div>
</div>
<div>
<br /></div>
<div>
<span style="background-color: white;"><br /></span></div>
Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-35184772668171736632009-12-26T15:51:00.000-08:002009-12-26T15:57:20.048-08:00Ethernet support for EclairI have created two patches for Ethernet support in Eclair. I don't want to check them in until I finish a complete test. For the early access, you can download it from the download section in android-x86.org<br /><br />BTW--Chih-wei has also posted a nice video on youtube to demonstrate a really fast fastboot of Android-x86 on EeePC 901. You can find the video from http://www.youtube.com/watch?v=QeSg7S<br /><br />YiTest Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com0tag:blogger.com,1999:blog-2365388541401490643.post-87533947104499133562009-11-14T18:16:00.001-08:002009-11-14T18:19:18.378-08:00release of android-x86 20091113 test buildThe Android-x86 project is glad to announce a new test build<br />20091113 for public testing. A live cd ISO and USB image are<br />available from our site:<br /><br /> http://www.android-x86.org/download<br /> http://code.google.com/p/android-x86/downloads/list<br /><br />Features:<br />Build 20091113 is Android 1.6 (Donut) based and it is a release candidate for android-x86 1.6 stable release.<br />In addition to the features available in previous release, the new build contains<br /><br /> * Hardware OpenGL support from olv in 0xlab.<br /> * Fn key support for EeePC platforms.<br /> * External USB bluetooth support.<br /> * NDK for X86 platforms is supported (based on the original work from guillaume.etievent@laposte.net)<br /> * new touch features to simulate home/menu/back keys to support touch only device.<br /> * Improvement on the keyboard support. User can use ctrl+c directly from terminal simulator now.<br /> * A lots of bug fixes.<br /><br />Released Files:<br /> * Live CD iso: android-x86-20091113.iso<br /><br /> sha1sum: dec0b99a6fe1e33e05b665e82f3020f612eb14bf<br /><br /> * Live USB image: android-x86-20091113_usb.img.gz<br /><br /> sha1sum: ce040ced2da92c278c7df2527b5f3498a68afbfa<br /><br />Source code:<br /> The source code is available in our git server:<br /><br /> $ repo init -u git://git.android-x86.org/android-x86/platform/manifest.git<br /> $ repo sync<br /><br />Test reports (success or fail) are welcome.<br />Please send the reports to the Android-x86 discussion group.<br />http://groups.google.com/group/android-x86Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-14699603137182207792009-10-08T09:49:00.000-07:002009-10-08T10:04:44.467-07:00compile openssl for mingwI was googling a correct step to build openssl with mingw. I followed different posts from different people, none of them give me anything good. After a whole afternoon of trying and failing, eventually, I got it right with following steps:<div>1. install cygwin on my PC. To avoid too much trying and failing, I have installed the full cygwin. Storage space is cheap but time is very expensive.</div><div>2. install mingw</div><div>3. download openssl from openssl.org. I used 0.9.8k</div><div>4. untar/unzip 0.9.8k package to cygwin how directory</div><div>5. start Cygwin xterm (ya, Cygwin not msys)</div><div>6. in the xterm, go to openssl-0.9.8k directory that you just unpacked</div><div>7. ./Configure mingw</div><div>8. make</div><div><br /></div><div>The steps above create static library that can be used with mingw. To create the dll, you need to do:</div><div>$ echo EXPORTS > libcrypto.def </div><div>$ nm libcrypto.a | grep ' T _' | sed 's,^.* T _,,' >> libcrypto.def </div><div>$ dllwrap -o libcrypto.dll --def libcrypto.def libcrypto.a -lws2_32 -lgdi32 </div><div> $ echo EXPORTS > libssl.def </div><div>$ nm libssl.a | grep 'T _' | sed 's,^.* T _,,' >> libssl.def </div><div>$ dllwrap -o libssl.dll --def libssl.def libssl.a libcrypto.dll</div><div> After this, you can copy the *.a to /mingw/lib and *.dll to /ming/bin</div>Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com2tag:blogger.com,1999:blog-2365388541401490643.post-22867761248953456542009-09-12T21:52:00.001-07:002009-09-12T21:52:23.224-07:00The wifi problem has been fixed<span class="Apple-style-span" style="font-family: 'Times New Roman'; "><div style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; width: auto; font: normal normal normal 100%/normal Georgia, serif; text-align: left; ">Recntly, people reported issues with wifi. The bug really has nothing to do with the wifi. It is a memory corruption issue inside the system property manager. Long ago, I changed the size of system property name to support user configure-able battery sysfs path. This change will cause the size of shared memory for the system properties to increase. But the original code of shared memory creation uses a hard coded size and I was not aware of that. When the amonut of the total used system property entries increased to certain level, segfault will happen since system property entry may have pointed to a wrong address. After adjusted the code to create the share memory, it seems that the problem goes away.<div>If you are still seeing the issue, please report it in the discussion group.</div><div>Thanks<br /><div>Yi </div></div></div></span>Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com0tag:blogger.com,1999:blog-2365388541401490643.post-18986126532536097732009-09-03T21:47:00.000-07:002009-09-14T18:53:22.414-07:00What is nextNow, we have a realtivly stable system. Here are some items on my to do list:<div>1. enable vold to support external stroage by using fuzzy matching</div><div>2.In Android, by default, mkdir set the new directory permission to 0700. When install an new apk from web ui, the download provider tries to create a new directory called download in /sdcard. On G1 phone, the external storage is using vfat partition. And it does not enforce permission. So we can download and install the apk without any problem. But with android-x86, the external storage can use either ext2, ext3 or vfat, with the unix paritions, the permission will be enforced. So the apk install will fail. I may need to add new code the fix the permission.<br /></div><div>3. hardware cursor, this item in my to do list for a very long time already.</div>Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-87419371967170530352009-08-25T20:27:00.001-07:002009-08-25T20:29:23.663-07:00The Android Etherent State Tracker Cont.Ok, I have committed the first release of the etherent state tracker for the Android. You can check out code from git.android-x86.org by using branch name eth-nm-dev-br. It is an alpha release. Please report the issues to the android-x86 groupTest Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com0tag:blogger.com,1999:blog-2365388541401490643.post-34131713100100970812009-08-24T09:49:00.000-07:002009-08-24T09:51:51.271-07:00Etherent state tracker cont.Slow.... the build is so slow, it eats up my 50% of time.<br /><br />I'm getting there. I still need to clean up the conntectivityservice. This class does now know anything other than wifi and mobile. I need to add etherent into it. But before that I will try out the basic functionality and release a test path .Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com0tag:blogger.com,1999:blog-2365388541401490643.post-77239893160849045112009-08-16T22:46:00.001-07:002009-08-16T22:52:52.006-07:00Add state tracker for etherent devicesAndroid has state tracker (the connection management) for both mobile connections and wifi connections. But it does not support ethernet devices.<br />This is not an issue for a phone , but it causes following issues with netbook:<br />1. you can not manage your ethernet device from UI at all<br />2. With current way of enabling ethernet device (netcfg eth0 dhcp). If you unplug/plug cable, you will not have your dhcp ip address reset<br />3. ethernet device can not report connectivity changes correctly<br /><br />Now, I'm working on the ethernet state tracker support for Android-x86. This blog thread is created to track this work.Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-83022582077369735802009-06-06T23:53:00.000-07:002009-06-07T00:04:57.863-07:00How to access a C native service from Java side in AndroidI have mentioned how to add a native service by C. Now, it is the time to discuss about the client implementation. A client, in this document is a activity. It can talk to the native service to instruct the native service to do something for it.<br />It seems that there has no way to do this with a standard method supported by Android SDK. So I went to another route. I built a platform library. The platform library talks to the servicemanager.java to access the binder hence the native service. The code is very simple. To find out how to build and use a platform library, you can check out the android source code and take a look at the README.txt in the directory development/samples/PlatformLibrary<br /><br />package com.servicelib.mybinder;<br /><br />import android.util.Config;<br />import android.util.Log;<br />import android.os.ServiceManager;<br />import android.os.Binder;<br />import android.os.IBinder;<br />import android.os.Parcel;<br />import android.os.RemoteException;<br /><br /><br />public final class MyBinderLibrary {<br /><br /><br /> private static IBinder mServiceManager = null;<br /><br /> public MyBinderLibrary() {<br /><br /> }<br /><br /> public static IBinder AttachService(String name) {<br /> if (mServiceManager == null) {<br /> mServiceManager = ServiceManager.getService(name);<br /> }<br /><br /> return mServiceManager;<br /> }<br /><br /> public static int SendKillSignal() throws RemoteException<br /> {<br /> Parcel data = Parcel.obtain();<br /> Parcel reply = Parcel.obtain();<br /> int result;<br /> try{<br /> data.writeInterfaceToken(mServiceManager.getInterfaceDescriptor());<br /> mServiceManager.transact(TRANSACTION_sendKill,data,reply,0);<br /> reply.readException();<br /> result = reply.readInt();<br /> }<br /> finally{<br /> reply.recycle();<br /> data.recycle();<br /> }<br /><br /> return result;<br /> }<br /> static final int TRANSACTION_sendKill = (IBinder.FIRST_CALL_TRANSACTION+0);<br />}<br /><br /><br />So, in your activity, call the methods in this class directly. So that you can talk to the native service. You need to make sure the name of the service is correct.Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-36621450598365951082009-05-29T09:36:00.001-07:002009-05-29T22:05:43.360-07:00connect G1 phone to adb on UbuntuYou can find very detailed instructions on android page. But they missed one thing, that is adb needs to be run with root permission. So after you setup everything, do:<br />adb kill-server<br />sudo adb devicesTest Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com0tag:blogger.com,1999:blog-2365388541401490643.post-39354682630407422002009-05-28T22:50:00.000-07:002009-05-29T22:06:24.824-07:00The mouse cursor issueI did the mouse cursor support for X86 platforms. As matter fact, the same change should be able to run anyway.<br /><br />But when I try to drag the screen to switch to next screen, I see the screen keeps flicking. It looks like a bug. In order to debug this problem, I wrote a small application to just draw lines on the screen. When I start to draw, I can see the lines keep jumping back to position 0,0 during the mouse cursor movement . It seems that the mouse cursor keeps sending out wrong mouse position.<br />After some debugging, I found out that it is cause by the batching mode of mouse event. Current mouse cursor tries to simulate the touch events, in order to do that, I have to convert the rel_x/y to abs_x/y and this conversion was never done for batched events. Because of this, both rel_x/y and abs_x/y are sent with touch events.<br />I have published the patch to<br />http://code.google.com/p/patch-hosting-for-android-x86-support/downloads/listTest Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-6624933180631538932009-05-22T22:44:00.000-07:002009-05-22T23:47:48.383-07:00How to write Android native service by C contntinueHere is some thing I did; first, I copied biner.c to my private directory and used it as a library to access kernel binder driver. And then, I wrote my service to use the functions in binder.c to talk to service manager.<br />In order to talk with service manager, we need following things:<br />1. an unique id for the service we are going to build. It is a string16 <br />2. add permission for our service to service manager.<br /><br />For the point 1, I create an uint16 array like<br />uint16_t svcmgr_id16[] = {<br /> 'B','i','n','d','e','r','.','T','e','s','t','.','I','B','i','n',<br /> 'd','e','r','t','e','s','t'<br />};<br /><br />for the point 2, I'm kind of lazy, I add a new item to the allowd[] in servicemanager. It looks like this:<br />{10001, "Binder.Test.IBindertest"}<br /><br />Ok, lets get something real, we need to do following steps to make everything to work:<br />1. connect to the binder by calling binder_open function. The binder_open function creates a shared memory with /dev/binder. I copied service manager code to create a 128K shared memory.<br />2.create an io block through bio_init function to talk with service manager through binder. You need to provide a buff to bio_init. I use an integer array with size of 128<br />3. fill in the target (servicemanager) and source(Binder.Test.IBindertest) by calling bio_put_string16_x<br />4. call binder_call with command SVC_MGR_ADD_SERVICE. It is a blocking call. You need to provide a binder_io object for the result.<br />5. if binder_call returns 0, call binder_loop with a message handler callback function to process messages sent from service client.<br /><br />The message processing callback function:<br />The prototype of the message processing callback functions is:<br />static int binder_handler(struct binder_state *bs,<br /> struct binder_txn *txn,<br /> struct binder_io *msg,<br /> struct binder_io *reply)<br /><br />In the callback function, we at least need to handle INTERFACE_TRANSACTION so that our service client can find our service.<br /> switch(txn->code) {<br /> case INTERFACE_TRANSACTION:<br /> bio_put_string16(reply,svcmgr_id16);<br /> break;<br /> case <other>:<br /> default:<br /> error handling.Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com2tag:blogger.com,1999:blog-2365388541401490643.post-75630106144642135012009-05-18T22:19:00.000-07:002009-05-18T22:21:08.937-07:00How to write Android native service by CIt is not as hard as I thought before I start. When I look into the frameworks/base/cmds/servicemanager, I realized that it should be an easy job. So I decide to give it a try. I will list what I do after I complete it.Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-46224958112072434642009-05-12T16:10:00.000-07:002009-05-12T16:48:47.466-07:00How to build and use a shared libraries in AndroidActually, it is very simple to build and use your own shared library,<br /><p>For the shared library, you need to create an Android.mk like this: </p> <pre> LOCAL_PATH := $(call my-dir)<br />include $(CLEAR_VARS)<br /></pre> <pre> LOCAL_SRC_FILES := hello.c<br /></pre> <pre> LOCAL_CFLAGS :=<br /></pre> <pre> LOCAL_C_INCLUDES :=<br /></pre> <pre> LOCAL_SHARED_LIBRARIES := libc <=== may be not required </pre> <pre> LOCAL_MODULE := libhello<br /></pre> <pre> include $(BUILD_SHARED_LIBRARY)<br /></pre> <p> For the executable that needs use this shared library, the Android.mk needs to be written as :<br /></p> <pre> LOCAL_PATH:= $(call my-dir)<br /></pre> <pre> include $(CLEAR_VARS)<br /></pre> <pre> LOCAL_SRC_FILES := main.c<br /></pre> <pre> LOCAL_SHARED_LIBRARIES := libc libhello<br /></pre> <pre> LOCAL_MODULE := myprog <=== the name of final executable </pre> <pre> include $(BUILD_EXECUTABLE)<br /></pre> <p><br />Besides makefile changes, we also need to change build/core/prelink-linux-arm.map. Android does prelink (a modified version), all the memory location of DSO are predefined. In order to build a shared library for Android, you need to define the address and size for the memory used by your DSO (before you start to build anything). For current example, I have added following lines at the end of .map file. </p> <pre> libhello.so 0x9A100000<br /></pre> <pre> The C code I'm using to build this example is<br />main.c<br /></pre> <pre> #include "myprog.h"<br /></pre> <pre> int main(void)<br />{<br /> hello("World!");<br /> return 0;<br />}<br /></pre> <p><br /></p> <pre> Hello.c<br />#include <stdio.h><br /></stdio.h></pre> <pre> void hello(const char* name)<br />{<br /> printf("Hello %s!\n", name);<br />}<br /><br /></pre>Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com1tag:blogger.com,1999:blog-2365388541401490643.post-27849155854769464012009-05-09T20:55:00.000-07:002009-05-09T21:22:41.600-07:00Android Suspend and resume (the wakelock problem)I enabled wakelock in my Android kernel today, after the wakelock is enabled on my PC, my machine failed to wake up. It seems that the machine gets back to suspend right after it is waken up.<br />I spent two hours to read the wakelock code and try to find out the reason for the problem. It seems that the wakelock.c checks a flag called entry_event_num during the machine resume process. The value of entry_event_num is saved before the machine goes into sleep, and wakelock checks it during the machine resume. If the value of entry_event_num did not changed since machine went to sleep, then wakelock will put the machine back to sleep again.<br />It looks like that the entry_event_num flag is used to verify whether the machnie is waken up from an expected event. If it is not, then machine will continue to sleep. To me this is more like a hack for a hardware bug.<br />So I hacked it to make my PC to sleep well and wake up on time :-). Here is the code I have changed:<br />diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c<br />index 7833d28..175f8a3 100644<br />--- a/kernel/power/wakelock.c<br />+++ b/kernel/power/wakelock.c<br />@@ -292,11 +292,13 @@ static void suspend(struct work_struct *work)<br /> tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,<br /> tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec);<br /> }<br />+#if 0<br /> if (current_event_num == entry_event_num) {<br /> if (debug_mask & DEBUG_SUSPEND)<br /> pr_info("suspend: pm_suspend returned with no event\n");<br /> wake_lock_timeout(&unknown_wakeup, HZ / 2);<br /> }<br />+#endif<br /> }<br /> static DECLARE_WORK(suspend_work, suspend);<br /><br /><br />Actually, the wakelock is really not a good idea. From my current understanding, if one of the application hold a wakelock without timeout and dead, the machine may not be able to go to sleep forever until you reboot your machine.Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com2tag:blogger.com,1999:blog-2365388541401490643.post-91123628832277871752009-05-08T22:03:00.000-07:002009-05-08T23:35:45.278-07:00Android on X86 Battery Service problemRecently, I got this EeePC netbook, beside accessing e-mail and web, I leave it on my desk for most of the time. One day, I saw this web site which talks about running Android on EeePC 701, so I decided to give it a try. Normally I like to record steps and findings when I try something, so that's wh I created this blog to record my experience on Android.<br /><br />Here you go with my first blog...<br /><br />When running Android Eee_701 build on a real machine, the battery service will not show the correct battery status on the status bar. Depending on what your battery is, you may get a warning says battery level lower than 15% or simply a question mark with the battery icon.<br /><br />There are two issues cause these problems:<br /><ol><li>the power_supply sysfs paths used by the batteryservice jni layer are not correct. Current sysfs path for battery status is hardcoded inside com_android_server_BatteryService.cpp and it is for G1 only.</li><li>The way how Android handles the content of battery status files in sysfs may not be right for your machine. For example, ACPI used by x86 has a different way to provide battery charging level. It is (charge_now/charge_full)*100. But G1 phone only has one parameter, and it is current charging level in a scale of 100.</li></ol><br />Fixing these issues are not difficult, yet the hard part is how to make the fix portable, what about tomorrow you want the same code to work on a different platform?<br />It is for sure not a good idea to continue to hardcode for the sysfs path or content processing methods inside com_android_BatteryService.cpp again.<br /><br />Here is my 2 cents:<br />We could put power_supply sysfs paths inside vendor/asus/eee_701/system.prop and then have com_android_BatteryService.cpp pick them up from system property during the run time. By doing this, you don't need to change any of your code, if you add new type of battery with different sysfs path, you don't even need to change your code.<br />Now, you may want to ask me what about processing the file contents differently? For that, we may need to do more works. We could create an abstract class that can be inherited by the real battery status class. The abstract class implements the battery status common interface and methods. The real battery status class will only need to implement the special parts for different battery. And the BatteryService jni layer calls the real battery status class to collect battery status. So when you have a new battery, only a minimum mount of the code need to be changed.<br /><br />I have actually implemented the entire thing and the same code works on G1, EeePC and VirtualBox very well.Test Drivehttp://www.blogger.com/profile/02838214327856600071noreply@blogger.com0