Difference between revisions of "Android"
m (→Links) |
|||
Line 9: | Line 9: | ||
==Some readings before starting== | ==Some readings before starting== | ||
* http://developer.android.com/guide/basics/what-is-android.html | * http://developer.android.com/guide/basics/what-is-android.html | ||
+ | |||
+ | ==Prerequisites for Android installation== | ||
+ | ===Install needed software packages=== | ||
+ | * Install these package for build the kernel image and for format the mmc/µSD card | ||
+ | <pre class="host"> | ||
+ | $ sudo apt-get install uboot-mkimage mtd-utils | ||
+ | </pre> | ||
+ | * The Armadeus [[Toolchain]], only for Armadeus patches | ||
+ | |||
+ | ===Update the environment variables=== | ||
+ | Theses environment variables install the Android and Armadeus folder in our home directory, but of course, it can be placed anywhere! | ||
+ | <pre class="config"> | ||
+ | export ANDROID_SOURCE=~/apf27droid | ||
+ | export ANDROID_SDK=~/android-sdk-linux_x86-1.5_r3 | ||
+ | export ARMADEUS=~/armadeus-3.1 | ||
+ | export PATH=${PATH}:${ANDROID_SDK}/tools:${ANDROID_SOURCE}/bin | ||
+ | </pre> | ||
+ | |||
+ | ===Download Android source=== | ||
+ | The [http://source.android.com/download getting Android source] document describes how to set up our local work environment. | ||
+ | Follow theses instructions until '''Installing Repo''' chapter. | ||
+ | <pre class="host"> | ||
+ | $ mkdir ANDROID_SOURCE | ||
+ | $ cd $ANDROID_SOURCE | ||
+ | $ mkdir bin | ||
+ | $ curl http://android.git.kernel.org/repo >$ANDROID_SOURCE/bin/repo | ||
+ | $ chmod a+x $ANDROID_SOURCE/bin/repo | ||
+ | $ repo init -u git://android.git.kernel.org/platform/manifest.git -b android-sdk-1.5_r3 | ||
+ | $ repo sync | ||
+ | </pre> | ||
+ | |||
+ | Since android-sdk-1.5_r3 branch, the Linux kernel isn't with the Android source, | ||
+ | We can download it in a compress archive (tar.gz) file with this [http://android.git.kernel.org/?p=kernel/common.git;a=snapshot;h=refs/heads/android-2.6.29;sf=tgz android-kernel-2.6.29] (about (70Mib) or with git repository (more 300Mib) | ||
+ | <pre class="host"> | ||
+ | $ mkdir $ANDROID_SOURCE/kernel | ||
+ | $ cd $ANDROID_SOURCE/kernel | ||
+ | $ git clone git://android.git.kernel.org/kernel/common.git android-2.6.29 | ||
+ | </pre> | ||
+ | |||
+ | ==Linux Kernel 2.6.29== | ||
+ | ===Apply the Armadeus patchset=== | ||
+ | Before compiling the kernel, we patch the source with the Armadeus patches. In second time, I will give the URL to retrieve Linux 2.6.29.4 patch. | ||
+ | <pre class="host"> | ||
+ | $ $ARMADEUS/buildroot/toolchain/patch-kernel.sh $ANDROID_SOURCE/kernel $ARMADEUS/downloads patch-2.6.29.4.bz2 | ||
+ | $ $ARMADEUS/buildroot/toolchain/patch-kernel.sh $ANDROID_SOURCE/kernel $ARMADEUS/buildroot/target/device/armadeus/linux/kernel-patches/2.6.29.4 \*.patch{,.gz,.bz2} | ||
+ | $ mkdir $ANDROID_SOURCE/kernel/drivers/armadeus | ||
+ | $ cp -r $ARMADEUS/target/linux/modules/* $ANDROID_SOURCE/kernel/drivers/armadeus | ||
+ | $ cp $ARMADEUS/buildroot/target/device/armadeus/apf27/apf27-linux-2.6.29.config $ANDROID_SOURCE/kernel/arch/arm/configs/apf27_android_defconfig | ||
+ | </pre> | ||
+ | |||
+ | ===Android kernel configuration (2.6.29)=== | ||
+ | <pre class="host"> | ||
+ | $ cp $ARMADEUS/buildroot/target/device/armadeus/apf27/apf27-linux-2.6.29.config $ANDROID_SOURCE/kernel/arch/arm/configs/apf27_android_defconfig | ||
+ | $ cd $ANDROID_SOURCE/kernel | ||
+ | $ make ARCH=arm mrproper | ||
+ | $ make ARCH=arm apf27_android_defconfig | ||
+ | $ make ARCH=arm menuconfig | ||
+ | </pre> | ||
+ | |||
+ | Make sure your kernel boots normally on your board. Then enable some Android specific configuration and make sure that your kernel still boots (with your standard file system). | ||
+ | *Android pmem allocator | ||
+ | <pre class="config"> | ||
+ | Device Drivers ---> | ||
+ | [*] Misc devices ---> | ||
+ | [*] Android pmem allocator | ||
+ | </pre> | ||
+ | * Android drivers | ||
+ | <pre class="config"> | ||
+ | Device Drivers ---> | ||
+ | [*] Staging drivers ---> | ||
+ | [ ] Exclude Staging drivers from being built (NEW) | ||
+ | ... | ||
+ | Android ---> | ||
+ | [*] Android Drivers | ||
+ | [*] Android Binder IPC Driver | ||
+ | <*> Android log driver | ||
+ | [ ] Android RAM buffer console | ||
+ | [*] Timed output class driver (NEW) | ||
+ | < > Android timed gpio driver (NEW) | ||
+ | [*] Android Low Memory Killer | ||
+ | </pre> | ||
+ | * Anonymous Shared Memory Subsystem | ||
+ | <pre class="config"> | ||
+ | General setup ---> | ||
+ | [*] Enable the Anonymous Shared Memory Subsystem | ||
+ | </pre> | ||
+ | |||
+ | ===Build Android kernel=== | ||
+ | <pre class="host"> | ||
+ | $ make ARCH=arm CROSS_COMPILE=$ANDROID_SOURCE/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- uImage | ||
+ | $ cp $ANDROID_SOURCE/kernel/arch/arm/boot/uImage $TFTPBOOT/apf27-linux.bin | ||
+ | </pre> | ||
+ | |||
+ | ==Android== | ||
+ | ===Battery patch=== | ||
+ | At the beginning, reboot happened over again even though Android logo appeared on board. | ||
+ | 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 '''$ANDROID_SOURCE/frameworks/base/services/jni/com_android_server_BatteryService.cpp''' | ||
+ | *Change the battery service status as TRUE | ||
+ | <source lang="c"> | ||
+ | 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); | ||
+ | } | ||
+ | </source> | ||
+ | *Change the volume, voltage and temperature of battery. Return 100%. | ||
+ | <source lang="c"> | ||
+ | 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); | ||
+ | } | ||
+ | </source> | ||
+ | *Change the battery charged status as full and deterioration status as fair. | ||
+ | <source lang="c"> | ||
+ | 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); | ||
+ | |||
+ | /* Change */ | ||
+ | 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)); | ||
+ | */ | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | ===Audio=== | ||
+ | {{Note| To do!!!}} | ||
+ | |||
+ | ===Touchscreen=== | ||
+ | {{Note| To do!!!}} | ||
+ | |||
+ | ===Change init.rc=== | ||
+ | Open $ANDROID_SOURCE/system/core/rootdir, comment the 'mount roofs' in read only mode and 'mount yaffs2' lines like this: | ||
+ | <pre class="config"> | ||
+ | # mount rootfs rootfs / rw | ||
+ | ... | ||
+ | # mount mtd partitions | ||
+ | # Mount /system rw first to give the filesystem a chance to save a checkpoint | ||
+ | # mount yaffs2 mtd@system /system | ||
+ | # mount yaffs2 mtd@system /system ro remount | ||
+ | |||
+ | # We chown/chmod /data again so because mount is run as root + defaults | ||
+ | # mount yaffs2 mtd@userdata /data nosuid nodev | ||
+ | chown system system /data | ||
+ | chmod 0771 /data | ||
+ | |||
+ | # Same reason as /data above | ||
+ | # mount yaffs2 mtd@cache /cache nosuid nodev | ||
+ | chown system cache /cache | ||
+ | chmod 0770 /cache | ||
+ | |||
+ | # This may have been created by the recovery system with odd permissions | ||
+ | chown system system /cache/recovery | ||
+ | chmod 0770 /cache/recovery | ||
+ | </pre> | ||
+ | |||
+ | ===Compile=== | ||
+ | <pre class="host"> | ||
+ | $ cd $ANDROID_SOURCE | ||
+ | $ make | ||
+ | </pre> | ||
+ | ==Making RootFS== | ||
+ | ===Android Root File system=== | ||
+ | Android emulator has 3 basic images on tools/lib/images directory. | ||
+ | * '''ramdisk.img''' is gziped cpio archive. ramdisk.img is a small partition image that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature. It is made just for the Android and do special things to start up the Android system. | ||
+ | * '''system.img''' is a partition image that will be mounted as / and thus contains all system binaries. | ||
+ | * '''userdata.img''' is a partition image that can be mounted as /data and thus contains all application-specific and user-specific data. | ||
+ | |||
+ | ===Android root filesystem for apf27=== | ||
+ | Actually, Android should use a file system how support mmap function like yaffs2, ext2 or ubifs. Unfortunaly, U-Boot support only jffs2 or ext2. So we will use ext2 root file system on a µSD. | ||
+ | |||
+ | Android’s root file system is generated in $ANDROID_SOURCE/out/target/product/generic. We will create a folder containing all Android files images. | ||
+ | <pre class="host"> | ||
+ | $ sudo rm -rf $ANDROID_SOURCE/rootfs/ | ||
+ | $ cd $ANDROID_SOURCE/out/target/product/generic | ||
+ | $ mkdir $ANDROID_SOURCE/rootfs | ||
+ | $ cp -a root/* $ANDROID_SOURCE/rootfs/ | ||
+ | $ cp -a system/* $ANDROID_SOURCE/rootfs/system/ | ||
+ | $ cd $ANDROID_SOURCE/rootfs | ||
+ | $ sudo chown -R root.root . | ||
+ | $ sudo chmod -R a+rwX data system | ||
+ | </pre> | ||
+ | |||
+ | ===Formatting an MMC/µSD card=== | ||
+ | We will create two partitions on our mmc/µSD card, The first one will use for Android memory card, the second one will use for Android file system. | ||
+ | First connect your card reader to your workstation, with the mmc/µSD card inside. Type the '''dmesg''' command to see which device is used by your workstation. Let’s assume that this device is '''/dev/sdb''' | ||
+ | <pre class="host"> | ||
+ | $ dmesg | ||
+ | ... | ||
+ | [ 9145.613954] sdb: sdb1 sdb2 | ||
+ | [ 9145.615125] sd 10:0:0:0: [sdc] Attached SCSI removable disk | ||
+ | [ 9145.615258] sd 10:0:0:0: Attached scsi generic sg3 type 0 | ||
+ | </pre> | ||
+ | Type the mount command to check your currently mounted partitions. If MMC/SD partitions are mounted, unmount them.<br> | ||
+ | In a terminal edit partitions with fdisk: | ||
+ | <pre class="host"> | ||
+ | sudo fdisk /dev/sdb | ||
+ | </pre> | ||
+ | Delete any existing partition with the d command.<br> | ||
+ | Now, create the boot partition: | ||
+ | <pre class="host"> | ||
+ | Command (m for help): n | ||
+ | Command action | ||
+ | e extended | ||
+ | p primary partition (1-4) | ||
+ | p | ||
+ | Partition number (1-4): 1 | ||
+ | First cylinder (1-495, default 1): 1 | ||
+ | Last cylinder, +cylinders or +size{K,M,G} (1-239, default 239): +1G | ||
+ | </pre> | ||
+ | Change its type to FAT32: | ||
+ | <pre class="host"> | ||
+ | Command (m for help): t | ||
+ | Selected partition 1 | ||
+ | Hex code (type L to list codes): c | ||
+ | Changed system type of partition 1 to c (W95 FAT32 (LBA)) | ||
+ | </pre> | ||
+ | Using the n command again, create a second partition filling up the rest of your card (just accept default values).<br> | ||
+ | Now, format the partitions in your card: | ||
+ | <pre class="host"> | ||
+ | sudo mkfs.vfat -n MemoryCard -F 32 /dev/sdb1 | ||
+ | sudo mkfs.ext2 -L AndroidFS /dev/sdb2 | ||
+ | </pre> | ||
+ | Remove and insert your card again. Your new partitions should be mounted automatically.<br> | ||
+ | ===Copying data to the MMC/SD card=== | ||
+ | Now copy the Android root filesystem to the second partition. | ||
+ | <pre class="host"> | ||
+ | sudo rsync -a $ANDROID_SOURCE/rootfs/ /media/AndroidFS/ | ||
+ | </pre> | ||
+ | Finish by unmounting your mmc/µSD partitions: | ||
+ | <pre class="host"> | ||
+ | sudo umount /media/MemoryCard | ||
+ | sudo umount /media/AndroidFS | ||
+ | </pre> | ||
+ | ==Boot setup== | ||
+ | The last thing left to do is to specify how the board boots Linux.<br> | ||
+ | In the U-boot prompt, make the mmc boot is on second partition of the mmc/µSD card | ||
+ | <pre class="apf"> | ||
+ | # setenv mmcroot '/dev/mmcblk0p2 rw' | ||
+ | </pre> | ||
+ | Now set the kernel command line arguments | ||
+ | <pre class="apf"> | ||
+ | # setenv addmmcargs 'setenv bootargs ${bootargs} root=${mmcroot} rootfstype=${mmcrootfstype} init=\init androidboot.console=ttyS0' | ||
+ | # saveenv | ||
+ | </pre> | ||
+ | ==Start Android== | ||
+ | <pre class="apf"> | ||
+ | # run mmcboot | ||
+ | </pre> | ||
+ | |||
+ | [[Image:Apf27_android.JPG]] | ||
+ | |||
+ | ==Debug 'n Test== | ||
+ | ===Trace on the console=== | ||
+ | Trace with '''strace''' | ||
+ | <pre class="apf"> | ||
+ | # mount /dev/mmcblk0p2 /mnt/mmc | ||
+ | # strace chroot /mnt/mmc /init androidboot.console=ttyS0 | ||
+ | </pre> | ||
+ | Trave with '''logcat''' | ||
+ | <pre class="apf"> | ||
+ | # mount /dev/mmcblk0p2 /mnt/mmc | ||
+ | # chroot /mnt/mmc /init androidboot.console=ttyS0 & | ||
+ | # chroot /mnt/mmc /system/bin/logcat | ||
+ | </pre> | ||
+ | |||
+ | ===Test with Android emulator=== | ||
+ | Documentation on Android [http://developer.android.com/guide/developing/tools/emulator.html emulator] | ||
+ | <pre class="host"> | ||
+ | $ cd $ANDROID_SOURCE/kernel | ||
+ | $ make ARCH=arm goldfish_defconfig | ||
+ | $ make ARCH=arm CROSS_COMPILE=$ANDROID_SOURCE/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi | ||
+ | # Create AVD (Android Virtual Device) | ||
+ | $ $ANDROID_SDK/tools/android create avd -n APF27-H -t 2 -s 272x480 | ||
+ | $ $ANDROID_SDK/tools/android create avd -n APF27-L -t 2 -s 480x272 | ||
+ | $ $ANDROID_SOURCE/out/host/linux-x86/bin/emulator -avd APF27-H -sysdir $ANDROID_SOURCE/out/target/product/generic/ -kernel $ANDROID_SOURCE/kernel/arch/arm/boot/zImage -data $ANDROID_SOURCE/out/target/product/generic/userdata.img -ramdisk $ANDROID_SOURCE/out/target/product/generic/ramdisk.img -system $ANDROID_SOURCE/out/target/product/generic/system.img | ||
+ | </pre> | ||
==Links== | ==Links== |
Revision as of 14:07, 7 August 2009
Page under construction... Informations on this page are not guaranteed !!
This page will sumarize the efforts made to have Android running on the APF boards.
Note: Due to Android requirements (at least an ARM926 core), it is impossible to have it running on the APF9328 |
Contents
Some readings before starting
Prerequisites for Android installation
Install needed software packages
- Install these package for build the kernel image and for format the mmc/µSD card
$ sudo apt-get install uboot-mkimage mtd-utils
- The Armadeus Toolchain, only for Armadeus patches
Update the environment variables
Theses environment variables install the Android and Armadeus folder in our home directory, but of course, it can be placed anywhere!
export ANDROID_SOURCE=~/apf27droid export ANDROID_SDK=~/android-sdk-linux_x86-1.5_r3 export ARMADEUS=~/armadeus-3.1 export PATH=${PATH}:${ANDROID_SDK}/tools:${ANDROID_SOURCE}/bin
Download Android source
The getting Android source document describes how to set up our local work environment. Follow theses instructions until Installing Repo chapter.
$ mkdir ANDROID_SOURCE $ cd $ANDROID_SOURCE $ mkdir bin $ curl http://android.git.kernel.org/repo >$ANDROID_SOURCE/bin/repo $ chmod a+x $ANDROID_SOURCE/bin/repo $ repo init -u git://android.git.kernel.org/platform/manifest.git -b android-sdk-1.5_r3 $ repo sync
Since android-sdk-1.5_r3 branch, the Linux kernel isn't with the Android source, We can download it in a compress archive (tar.gz) file with this android-kernel-2.6.29 (about (70Mib) or with git repository (more 300Mib)
$ mkdir $ANDROID_SOURCE/kernel $ cd $ANDROID_SOURCE/kernel $ git clone git://android.git.kernel.org/kernel/common.git android-2.6.29
Linux Kernel 2.6.29
Apply the Armadeus patchset
Before compiling the kernel, we patch the source with the Armadeus patches. In second time, I will give the URL to retrieve Linux 2.6.29.4 patch.
$ $ARMADEUS/buildroot/toolchain/patch-kernel.sh $ANDROID_SOURCE/kernel $ARMADEUS/downloads patch-2.6.29.4.bz2 $ $ARMADEUS/buildroot/toolchain/patch-kernel.sh $ANDROID_SOURCE/kernel $ARMADEUS/buildroot/target/device/armadeus/linux/kernel-patches/2.6.29.4 \*.patch{,.gz,.bz2} $ mkdir $ANDROID_SOURCE/kernel/drivers/armadeus $ cp -r $ARMADEUS/target/linux/modules/* $ANDROID_SOURCE/kernel/drivers/armadeus $ cp $ARMADEUS/buildroot/target/device/armadeus/apf27/apf27-linux-2.6.29.config $ANDROID_SOURCE/kernel/arch/arm/configs/apf27_android_defconfig
Android kernel configuration (2.6.29)
$ cp $ARMADEUS/buildroot/target/device/armadeus/apf27/apf27-linux-2.6.29.config $ANDROID_SOURCE/kernel/arch/arm/configs/apf27_android_defconfig $ cd $ANDROID_SOURCE/kernel $ make ARCH=arm mrproper $ make ARCH=arm apf27_android_defconfig $ make ARCH=arm menuconfig
Make sure your kernel boots normally on your board. Then enable some Android specific configuration and make sure that your kernel still boots (with your standard file system).
- Android pmem allocator
Device Drivers ---> [*] Misc devices ---> [*] Android pmem allocator
- Android drivers
Device Drivers ---> [*] Staging drivers ---> [ ] Exclude Staging drivers from being built (NEW) ... Android ---> [*] Android Drivers [*] Android Binder IPC Driver <*> Android log driver [ ] Android RAM buffer console [*] Timed output class driver (NEW) < > Android timed gpio driver (NEW) [*] Android Low Memory Killer
- Anonymous Shared Memory Subsystem
General setup ---> [*] Enable the Anonymous Shared Memory Subsystem
Build Android kernel
$ make ARCH=arm CROSS_COMPILE=$ANDROID_SOURCE/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi- uImage $ cp $ANDROID_SOURCE/kernel/arch/arm/boot/uImage $TFTPBOOT/apf27-linux.bin
Android
Battery patch
At the beginning, reboot happened over again even though Android logo appeared on board. 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 $ANDROID_SOURCE/frameworks/base/services/jni/com_android_server_BatteryService.cpp
- 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);
}
- 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);
}
- 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);
/* Change */
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));
*/
}
Audio
Touchscreen
Change init.rc
Open $ANDROID_SOURCE/system/core/rootdir, comment the 'mount roofs' in read only mode and 'mount yaffs2' lines like this:
# mount rootfs rootfs / rw ... # mount mtd partitions # Mount /system rw first to give the filesystem a chance to save a checkpoint # mount yaffs2 mtd@system /system # mount yaffs2 mtd@system /system ro remount # We chown/chmod /data again so because mount is run as root + defaults # mount yaffs2 mtd@userdata /data nosuid nodev chown system system /data chmod 0771 /data # Same reason as /data above # mount yaffs2 mtd@cache /cache nosuid nodev chown system cache /cache chmod 0770 /cache # This may have been created by the recovery system with odd permissions chown system system /cache/recovery chmod 0770 /cache/recovery
Compile
$ cd $ANDROID_SOURCE $ make
Making RootFS
Android Root File system
Android emulator has 3 basic images on tools/lib/images directory.
- ramdisk.img is gziped cpio archive. ramdisk.img is a small partition image that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature. It is made just for the Android and do special things to start up the Android system.
- system.img is a partition image that will be mounted as / and thus contains all system binaries.
- userdata.img is a partition image that can be mounted as /data and thus contains all application-specific and user-specific data.
Android root filesystem for apf27
Actually, Android should use a file system how support mmap function like yaffs2, ext2 or ubifs. Unfortunaly, U-Boot support only jffs2 or ext2. So we will use ext2 root file system on a µSD.
Android’s root file system is generated in $ANDROID_SOURCE/out/target/product/generic. We will create a folder containing all Android files images.
$ sudo rm -rf $ANDROID_SOURCE/rootfs/ $ cd $ANDROID_SOURCE/out/target/product/generic $ mkdir $ANDROID_SOURCE/rootfs $ cp -a root/* $ANDROID_SOURCE/rootfs/ $ cp -a system/* $ANDROID_SOURCE/rootfs/system/ $ cd $ANDROID_SOURCE/rootfs $ sudo chown -R root.root . $ sudo chmod -R a+rwX data system
Formatting an MMC/µSD card
We will create two partitions on our mmc/µSD card, The first one will use for Android memory card, the second one will use for Android file system. First connect your card reader to your workstation, with the mmc/µSD card inside. Type the dmesg command to see which device is used by your workstation. Let’s assume that this device is /dev/sdb
$ dmesg ... [ 9145.613954] sdb: sdb1 sdb2 [ 9145.615125] sd 10:0:0:0: [sdc] Attached SCSI removable disk [ 9145.615258] sd 10:0:0:0: Attached scsi generic sg3 type 0
Type the mount command to check your currently mounted partitions. If MMC/SD partitions are mounted, unmount them.
In a terminal edit partitions with fdisk:
sudo fdisk /dev/sdb
Delete any existing partition with the d command.
Now, create the boot partition:
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-495, default 1): 1 Last cylinder, +cylinders or +size{K,M,G} (1-239, default 239): +1G
Change its type to FAT32:
Command (m for help): t Selected partition 1 Hex code (type L to list codes): c Changed system type of partition 1 to c (W95 FAT32 (LBA))
Using the n command again, create a second partition filling up the rest of your card (just accept default values).
Now, format the partitions in your card:
sudo mkfs.vfat -n MemoryCard -F 32 /dev/sdb1 sudo mkfs.ext2 -L AndroidFS /dev/sdb2
Remove and insert your card again. Your new partitions should be mounted automatically.
Copying data to the MMC/SD card
Now copy the Android root filesystem to the second partition.
sudo rsync -a $ANDROID_SOURCE/rootfs/ /media/AndroidFS/
Finish by unmounting your mmc/µSD partitions:
sudo umount /media/MemoryCard sudo umount /media/AndroidFS
Boot setup
The last thing left to do is to specify how the board boots Linux.
In the U-boot prompt, make the mmc boot is on second partition of the mmc/µSD card
# setenv mmcroot '/dev/mmcblk0p2 rw'
Now set the kernel command line arguments
# setenv addmmcargs 'setenv bootargs ${bootargs} root=${mmcroot} rootfstype=${mmcrootfstype} init=\init androidboot.console=ttyS0' # saveenv
Start Android
# run mmcboot
Debug 'n Test
Trace on the console
Trace with strace
# mount /dev/mmcblk0p2 /mnt/mmc # strace chroot /mnt/mmc /init androidboot.console=ttyS0
Trave with logcat
# mount /dev/mmcblk0p2 /mnt/mmc # chroot /mnt/mmc /init androidboot.console=ttyS0 & # chroot /mnt/mmc /system/bin/logcat
Test with Android emulator
Documentation on Android emulator
$ cd $ANDROID_SOURCE/kernel $ make ARCH=arm goldfish_defconfig $ make ARCH=arm CROSS_COMPILE=$ANDROID_SOURCE/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi # Create AVD (Android Virtual Device) $ $ANDROID_SDK/tools/android create avd -n APF27-H -t 2 -s 272x480 $ $ANDROID_SDK/tools/android create avd -n APF27-L -t 2 -s 480x272 $ $ANDROID_SOURCE/out/host/linux-x86/bin/emulator -avd APF27-H -sysdir $ANDROID_SOURCE/out/target/product/generic/ -kernel $ANDROID_SOURCE/kernel/arch/arm/boot/zImage -data $ANDROID_SOURCE/out/target/product/generic/userdata.img -ramdisk $ANDROID_SOURCE/out/target/product/generic/ramdisk.img -system $ANDROID_SOURCE/out/target/product/generic/system.img