[轉]How to compile Android Device Driver as a Module(.ko)


How to compile Android Device Driver as a Module(.ko)

Here are the quick steps to be followed.

Prerequisite:
1. kernel sources from vendor say HTC wildfire(2.1 update-1)
2. Android source code for Éclair
3. Create a new folder called Kernel and copy the contents from the sources download via vendor

Step1: Copy config.gz from running hardware

adb pull /proc/config.gz
gunzip config.gz
mv config .config


Step 2: Copy/Overwrite the .config file to the kenel root directory

open .config file and search for
CONFIG_MODULE_NAME1=y
CONFIG_MODULE_NAME2=y


and replace 'y' with 'm', we use CONFIG_MODULE_NAME1 as module

CONFIG_MODULE_NAME1=m
CONFIG_MODULE_NAME2=y

Step 3: Check the active kernel version on the hardware using 'OR' if you are using own Boot.img then skip this and move on to step 4:

adb shell
# uname -a

or you may get the details of the kernel from the Settings->Aboutphone->SoftwareInformation: Kernel version

2.6.29-6fb59e13 HTC-kernel@xxxxxxxx

open Makefile in the kernel folder, search and replace "EXTRAVERSION =" with "EXTRAVERSION =-6fb59e13"

Step 4: Set the Env variables

export ARCH=arm
exprot CROSS_COMPILE=arm-eabi-
export PATH=$PATH:~/eclair/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/


now perform make modules for make from the kernel sources

kernel:$ make modules or make

after successful compilation, check out the .ko files next to the sources in the same directory

Complete example: How to get LG headset sources compile in to kernel module(.ko)
ref: http://android-jotting.blogspot.tw/2010/12/how-to-compile-android-device-driver-as.html

Mac 終端機顏色設定

对于从Unix/Linux平台转到Mac的同学来说,“终端”是经常要使用的一个工具。不过可能有很多人已经发现了,当我们使用ls命令来显示目录内容的时候,“终端”对于目录、可执行文件等特殊类型的文件并没有使用颜色来显示,只有使用“ls -G”时,才能显示颜色,这可真是不方便啊。有没有方法可以默认显示颜色呢?方法当然有。

方案一

第一个方案是让ls自动变成ls -G。我们要在用户目录下(~)创建一个名为.bash_profile的文件,如果这个文件已经存在,我们直接编辑这个文件就可以了。在~/.bash_profile中加入下面的内容:

alias ls=”ls -G”
保存文件后,重新启动“终端”。这时,运行ls命令,我们就可以看到文件已经可以用彩色来显示了。



方案二

上面这个方案虽然解决了彩色显示问题,但是还有一点不足,就是无法设置显示的颜色。比如说,我想用红色显示目录,那么这种方法是做不到的。下面我们来看看一个更好的解决方案。同样是修改~/.bash_profile文件,在文件中加入下面两行配置。

export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad
保存文件,重新运行“终端”,我们发现目录的颜色由蓝色变成了青色。

 

配置

那么应该怎样来配置成我喜欢的颜色呢?下面我们就来详细说一些这些配置。

~/.bash_profile是bash shell中当前登录用户的配置文件。bash是“终端”中默认的shell。

alias ls=”ls -G”是给”ls -G”起了一个别名,当执行ls时,就相当于执行了ls -G。

CLICOLOR是用来设置是否进行颜色的显示。CLI是Command Line Interface的缩写。

LSCOLORS是用来设置当CLICOLOR被启用后,各种文件类型的颜色。LSCOLORS的值中每两个字母为一组,分别设置某个文件类型的文字颜色和背景颜色。LSCOLORS中一共11组颜色设置,按照先后顺序,分别对以下的文件类型进行设置:

directory
symbolic link
socket
pipe
executable
block special
character special
executable with setuid bit set
executable with setgid bit set
directory writable to others, with sticky bit
directory writable to others, without sticky bit
LSCOLORS中,字母代表的颜色如下:

a 黑色
b 红色
c 绿色
d 棕色
e 蓝色
f 洋红色
g 青色
h 浅灰色
A 黑色粗体
B 红色粗体
C 绿色粗体
D 棕色粗体
E 蓝色粗体
F 洋红色粗体
G 青色粗体
H 浅灰色粗体
系统默认颜色
所以,如果我们想把目录显示成红色,就可以把LSCOLORS设置为bxfxaxdxcxegedabagacad就可以了 


所以对照这张表就可以得知:
bxfxaxdxcxegedabagacad
就是对于directory而言,它的前景色就是: b(red),而背景色就是:x(默认的背景色).

[轉載] Developing for Linux under MacOSX using Xcode

[ref]: http://ricardo-dias.com/2012/01/08/developing-for-linux-under-os-x-in-xcode/


In this mini-article I will show you how I develop applications for Linux in XCode 4. At the moment I’m using XCode 4.2.1, in OSX Lion, with Ubuntu 10.04 running on a virtual machine.
Although the article is related to XCode, after reading and trying out for yourself, you will notice that you can use whatever IDE you like. Here I’m just showing you how you can code in a OSX-only IDE and deploy in Linux.

Requirements

You will need some tools before we start:
  • VMWare or similar virtual machine application for Mac
    • Used to run our Linux system, and that’s where we will compile and run the target application.
      You can also use a physical computer instead. However, you will need network connectivity from mac to that computer because the communication between this linux System and our Mac is done by SSH.
  • OSXFuse
    • Requirement for the next point
  • SSHFS
    • It will be used to mount a remote directory in our Mac, and access it as if it was an external hard disk drive
Once you have all these, we are ready to go, but take some seconds to make sure you can compile the application in your slave Linux system. This will ensure that any problems you may encounter are not related to your slave machine or the code you are trying to compile.

Accessing slave machine using SSH

Now you will need the slave machine’s IP address, typing ifconfig in its Terminal.
As you can see in the image above, in my case I’ll be using 172.16.68.128 as the slave’s IP Address.
Then we make sure we can access it from your Mac typing the next command in Mac Terminal:
ssh username@ip
If we are asked for the password, then we got a valid SSH connection and we can move on…

Adding an alias for the Linux Slave IP

Because IPs can change sometimes, even inside Local Area Network, I added an alias for this IP, so that I could use it in scripts instead of the IP address itself. When it changes, I only have to modify one single file. You can do the same, by editing the hosts file, so grab the Mac Terminal and type as you see:
sudo vim /etc/hosts
Add a new line in the end, pressing I to enter insert mode:
172.16.68.128 vmcode
Now press ESC to exit “INSERT mode” and type :wq (yes, including the colon). If you have any problems using vim to edit this file, you can try nano instead – just replace “vim” with “nano” in the first command of this section. Now, you can use the virtual hostname “vmcode” instead of the real IP (which will be a lot easier to remember).

Setup script files

Now we need to setup two script files. I called them mountDir and sshbuild. The first one will mount the remote directory in our Mac and the latter is used to remotely compile the application.
Firstly pick a directory for these scripts, where you need to place the sshfs-static-leopard file, because it will be needed for the mountDir script.

Mounting Directory Script

Using your favorite text editor, create a new file called “mountDir” (no extension), and paste the following code:
#!/bin/bash
echo password | ./sshfs-static-leopard username@vmcode:codedir ~/path/to/mount/dir -o password_stdin
I’m explaining some of the variables in the command, that you should change to fit your needs:
  • username and password are the credentials for the user in the slave Linux machine
  • codedir is the directory in slave machine you want to mount in Mac
  • ~/path/to/mount/dir is the path to the Mac’s directory where you want to mount the slave’s directory
If you are using a real box instead of a VM, I recommend you configure ssh public keys instead of storing your password in plain text. You SHOULD NOT use the same password as of your Mac User
This was pointed by reader Daid, and I explained him I used it in plain text because I’m connecting to this VM, used only for compiling purposes and not accessible from outside, so I’m not that worried about it.

Building remotely

The SSH command accepts a second argument, that is the command you want to execute right after the remote login. Save and create another file called “sshbuild” with the following content:
#!/bin/bash
ssh username@vmcode 'cd codedir; make'
Note that username and codedir must match the ones you used before.

Setting up XCode

Before we move to XCode, you first need to mount the directory: open the Terminal, cd to your scripts dir, and run sh mountDir. Now you should see the contents of remote dir in your Mac’s ~/path/to/mount/dir.
Any change you make to these files will be reproduced in the remote slave system (our VM), because SSHFS will be syncing in real-time.
Start XCode, then click File > New > New Workspace… and chose a location for the workspace file (I used the same as the scripts). You should see a window with three different spaces, they should have texts in the middle, from left ro right, saying “No Files”“No Editor” and “No Selection”. Open a Finder window in the location ~/path/to/mount/ and then drag the subfolder that has a name starting with “OSXFUSE” to the “No Files” space in XCode.
A popup will show up. Firstly, XCode will prompt you about your build tool. You should type the complete path to the sshbuild script, starting on root, on the “Build Tool” field.
After clicking “Next”, you will be presented something like the image below, you should select the second option, which is “Create folder references for any added folders”.
Basically you are adding a reference to that directory, so instead of working in a local copy, you will edit the remote files directly. Now that you have all the directories in the slave’s codedir in the left panel of XCode, you can now open, edit and save any of your files using XCode. Now hit Command+B to run the build tool, and if everything goes well, you should see a message box saying Build Successful.

Running the Application

As you are developing for Linux, you should preferably debug under Linux. However, I often use an Application called X11, taht can be found in your Applications/Utilities folder. Type this command under X11 console window and the application should run in your Mac as if it was on Linux, even if it needs to open windows:
ssh -X username@vmcode
cd codedir./application

Conclusion

Here I shown you how I develop applications for Linux using the resourceful XCode and all it’s features, without quitting Mac OSX. I hope you found it useful and it helps you by increasing your productivity. Leave a reply, share your thoughts and suggestions and happy coding ;)

– edit 11/01/2012 –
After reading this article, Simon Elliston Ball posted a reply with a link to his blog suggesting a different solution – vagrant – that let’s you achieve the same results, but storing your files on Mac instead of the Linux system. I believe there are some advantages of doing this way, so you may choose the solution that best fits your needs. Thank you Simon.

Missing Library folder in Mac OS X Lion


Problem
In your home folder, you notice that there is no longer a Library folder.
Cause
This is the default setting by design in Mac OS X Lion.
SolutionTo get your Library folder back:
  1. Go to your Applications folder.
  2. Go to the Utilities folder.
  3. Double click on Terminal.
  4. Select all the text in the box below and press cmd + C to Copy.
    chflags nohidden ~/Library
  5. In the Terminal window press cmd + V or click Edit > Paste (on the top menu).
  6. Press Enter.
To revert back to the default setting change “nohidden” to “hidden” in Step 4.

虹光大成就-密教灌頂(一)