Android Tutorial

7.10.2011

Making handset by using Beagleboard. Brilliant Service Co., Ltd Technical Div. Yosuke Fujii. (Technical translator. Shinjiro Ninomiya)

0.Preface

We, Brilliant Service Co., Ltd., are trying to make a handset which is embedded Android as our company’s own handset project. We will expose our know-how while developing.

Participants for our project as per below.

<Hardware>
    Ex Co.,Ltd

<Software>
    Brilliant Service Co., Ltd



- CEO  Yoshihiko Sugimoto
- Technical Div. Ryota Kajitani, Yuma Yagi, Yutaka Kawahara, Yosuke Fujii
- IT Company X  Mr.S

Note
**Beagleboard Rev.B5 is used as a mainboard.
** Using environment ubuntu8.10
**Communication’s module W-SIM*2


1.Pre-condition

 1.1 Setting of Android development environment.

Linux environment
  Please refer to the following link:
  http://source.android.com/download
  http://d.hatena.ne.jp/bs-android/20090324/1237864332 (Only Japanese)

  Note. uboot-mkimage should be installed.
  ** ubuntu8.10 can be installed via synaptic manager.
  ** For ubuntu8.04, via apt-get install

 1.2 Setting of using tools

  Installing GNU C & C++ Compilers
    Using release is arm-2007q3-51. It can be installed via following link:
    http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3057

  Note.
    For installing, TAR uncompress, using installer and other method are available for the users.
    When uncompress TAR, set the path where it will be installed yourself.
    (Write $PATH in ~/.bashrc file)



2. Get Android sources for Beagleboard

 2.1  Initializing repo


First, prepare for downloading basic Android source.
Enter command in terminal window.

$ mkdir  mydroid
$ cd mydoroid
$ repo init -u git://android.git.kernel.org/platform/manifest.git

For above step, set for downloading the latest Android source into mydroid.

 2.2 Prepare for getting kernel for Omap

When Android works on Beagleboard, you need to delete unnecessary subproject
from Android repository and to download the project which is not included
in standard project.
Then, you need to use setting file.
Make local_manifest.xml in mydroid/.repo/.
"local_manifest.xml" should be as per below.


<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remove-project name="kernel/common"/>
  <project path="kernel" name="kernel/omap" revision="refs/heads/android-omap-2.6.29"/>
  <project path="external/alsa-lib" name="platform/external/alsa-lib"/>
  <project path="external/alsa-utils" name="platform/external/alsa-utils"/>
  <project path="hardware/alsa_sound" name="platform/hardware/alsa_sound"/>
</manifest>


 2.3 Get source


When 2.1 and 2.2 are done, preparation for downloading is finished.
Enter the following command in terminal window.

$ repo sync

When above command is executed, it will start to get source.
If it may fail, try same command again.



3. Prepare for patch

 3.1  Structure of Linux kernel environment

ALSA audio driver is used for BeagleBorard.
Some problems have been reported for binding ALSA on beagleboard and Android,
however, we did succeed to sound by using ALSA.


 3.2.1  Add Build definition for Sound device.

Sound device of Beagleboard cannot be built in omap kernel in Android project.
Therefore, we extracted differences from old kernel, then applied patch.
mydroid/kernel/sound/soc/omap/Kconfig

Following has been added for setting SND_OMAP_SOC_OMAP3_BEAGLE.
  Note.
    Please be careful of the dependence. We have added next to
    "config SND_OMAP_SOC_N810"


config SND_OMAP_SOC_OMAP3_BEAGLE
    tristate "SoC Audio support for OMAP3 Beagle"
    depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP3_BEAGLE
    select SND_OMAP_SOC_MCBSP
    select SND_SOC_TWL4030
    help
      Say Y if you want to add support for SoC audio on the Beagleboard.


mydroid/kernel/sound/soc/omap/Makefile
# OMAP Machine Support
snd-soc-n810-objs := n810.o
snd-soc-omap3beagle-objs := omap3beagle.o
snd-soc-osk5912-objs := osk5912.o
snd-soc-overo-objs := overo.o
snd-soc-omap2evm-objs := omap2evm.o
snd-soc-sdp3430-objs := sdp3430.o
snd-soc-omap3pandora-objs := omap3pandora.o

obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o
obj-$(CONFIG_SND_OMAP_SOC_OMAP3_BEAGLE) += snd-soc-omap3beagle.o
obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o
obj-$(CONFIG_SND_OMAP_SOC_OVERO) += snd-soc-overo.o
obj-$(CONFIG_MACH_OMAP2EVM) += snd-soc-omap2evm.o
obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o
obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o

We have made a kernel configuration file which was added Android, ADB, ALSA and FrameBuffer functions enabled.

omap3_beagle_android_defconfig should be saved in mydroid/kernel/arch/arm/configs.


3.3 Construction of Android environment
 3.3.1 ALSA sound driver

ALSA sound library and the other related files have already obtained
through setting local_manifest.xml in ch.2.2,

To use these libraries in Android, you need to add config.

mydroid/build/target/board/generic/BoardConfig.mk
# config.mk
#
# Product-specific compile-time definitions.
#

# The generic product target doesn't have any hardware-specific pieces.
TARGET_NO_BOOTLOADER := true
TARGET_NO_KERNEL := true
TARGET_NO_RADIOIMAGE := true
HAVE_HTC_AUDIO_DRIVER := true
BOARD_USES_ALSA_AUDIO := true
BUILD_WITH_ALSA_UTILS := true
#BOARD_USES_GENERIC_AUDIO := true  #!!!comment out.

mydroid/external/alsa-utils/android/aconfig.h
#define DATADIR "/system/usr/share/alsa"

#define rindex strrchr
#define open64 open

/*typedef int off64_t; !!!comment out!!! */

#undef __swab16
#define __swab16(x)  __arch__swab16((x))

#undef __swab32
#define __swab32(x)  __arch__swab32((x))


3.3.2 Battery patch

At the beginning, reboot happened over again even though Android logo appeared
on Beagleboard.
Result of investigation, we found that battery power was returned with 0 when boot..
Then, we changed to notify  full battery to Android by ignoring the information
under /sys/class/power_supply  so that to prevent the power down by low battery
mydroid/frameworks/base/services/jni/com_android_server_BatteryService.cpp

Note
  Currently, full battery status is always returned as a temporary measure
  because there is no device driver for power supply of Beagleboard.
  However we have a plan to improve it.

1)Change the battery service status as TRUE


static void setBooleanField(JNIEnv* env, jobject obj, const char* path, jfieldID fieldID)
{
    const int SIZE = 16;
    char buf[SIZE];
   
    jboolean value = true; /* change false -> true */
/*!!!comment out!!!
    if (readFromFile(path, buf, SIZE) > 0) {
        if (buf[0] == '1') {
            value = true;
        }
    }
*/

    env->SetBooleanField(obj, fieldID, value);
}


2)Change the volume, voltage and temperature of battery. Return 100%.


static void setIntField(JNIEnv* env, jobject obj, const char* path, jfieldID fieldID)
{
    const int SIZE = 128;
    char buf[SIZE];
   
    jint value = 100; /* change 0 -> 100 */
/*!!!comment out!!!
    if (readFromFile(path, buf, SIZE) > 0) {
        value = atoi(buf);
    }
*/

    env->SetIntField(obj, fieldID, value);
}



3)Change the battery charged status as full and deterioration status as fair.

static void android_server_BatteryService_update(JNIEnv* env, jobject obj)
{
    setBooleanField(env, obj, AC_ONLINE_PATH, gFieldIds.mAcOnline);
    setBooleanField(env, obj, USB_ONLINE_PATH, gFieldIds.mUsbOnline);
    setBooleanField(env, obj, BATTERY_PRESENT_PATH, gFieldIds.mBatteryPresent);
   
    setIntField(env, obj, BATTERY_CAPACITY_PATH, gFieldIds.mBatteryLevel);
    setIntField(env, obj, BATTERY_VOLTAGE_PATH, gFieldIds.mBatteryVoltage);
    setIntField(env, obj, BATTERY_TEMPERATURE_PATH, gFieldIds.mBatteryTemperature);

    env->SetIntField(obj, gFieldIds.mBatteryStatus, gConstants.statusFull);
    env->SetIntField(obj, gFieldIds.mBatteryHealth, gConstants.healthGood);

    env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF("1"));
/*!!!comment out!!!   
    const int SIZE = 128;
    char buf[SIZE];
   
    if (readFromFile(BATTERY_STATUS_PATH, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf));
   
    if (readFromFile(BATTERY_HEALTH_PATH, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf));

    if (readFromFile(BATTERY_TECHNOLOGY_PATH, buf, SIZE) > 0)
        env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf));
*/

}


4. Build

 4.1 Kernel environment build
Execute the following command to build kernel.

 $ cd mydroid/kernel
 $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- distclean
 $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- omap3_beagle_android_defconfig
 $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage
 $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- modules <- If using ADB.


 4.2 Android environment build


Execute the following command to build Android environment


 $ cd mydroid
 $ make



5. Making SD card for boot

 5.1 Steps to make


We refer to the information as per below:
http://wiki.davincidsp.com/index.php?title=MMC_Boot_Format
http://d.hatena.ne.jp/naka-3/20090128/1233125851 (only Japanese)


 5.2 Change init.rc

This is an initializing setting file for linux and android.
File system will be changed to use Beagleboard. According to that, initialization parameter
has been changed.
Also, load setting for ADB(debugger) module*1 and change of authority for ALSA driver
have been added.

  Note.
  **Please locate in the root on SD card ext3 partition.
  **Following is load setting for ADB module. If not necessary, please comment out.

init.rc
 ### Load some modules using ADB kernel module
    insmod /system/lib/modules/switch_class.ko
    insmod /system/lib/modules/switch_gpio.ko
    insmod /system/lib/modules/g_android.ko



6. ADB(debugger)

Some patches and changes have been done to debug by ADB.
You can skip if ADB is not necessary


 6.1 Installing kernel module


When using ADB(debugger), copy *.ko file which was generated under mydroid/kernel
by make under /system/lib/modules on ext3 partition of SD card.

  Note
    It will be found if enter the following command with current directory as mydroid/kernel


$ find -name "*.ko" -type f


 6.2 Change init.rc

Enable load setting of ADB(debugger) module in Ch. 5.2, then copy in root directory of
SD card ext3 partition.


 6.3 USB setting on PC

50-android.rules
Need to recognize ADB of Beagleboard on HOST PC.
This is USB setting file for that.

Copy this file in /etc/udev/rules.d of PC. Then, chmod with the following command.


$ sudo chmod a+rx /etc/udev/rules.d/50-android.rules



7. Photos


VGA display(Can you see logo on board?)
boot.JPG

In case
SBSH0002.JPGSBSH0003.JPG

LCD display
DSC_0090.jpg

DSC_0089.jpg



We really appreciate Ex. , they made hardware acceding to  our strong order to use Beagleboard W-SIM*2. Therefore, it looks bigger and ugly.

Next No. 2 handset should be smaller as we have learned a lot from No. 1.

Please e-mail us if you are interested in our handset.
Address: bs_handset@brilliantservice.co.jp

*1:Please refer to Ch. 6.
*2 : W-SIM modularizes a communication facility(Included Protocol,RF).
The maker can get the following merits.
** FCC approval is unnecessary.
       ** Reduction of development cost
       http://en.wikipedia.org/wiki/W-SIM

No comments:

Post a Comment