Android driver development series 2

Source: Internet
Author: User

There have been too many trivial matters recently and there is no time to write a blog. Continue to write the android driver for development and debugging.

This chapter focuses on how to test the driver.

 

1. Simple driver test

In the previous article, we have finished adding the driver module and downloaded the driver to the board. The following describes how to test whether the driver works properly.

This TTT driver implements a read and write interface, so we can perform a simple test:

Start the board, enter the system, and then enter the command line (you can use the serial port or the ADB shell)

Go to the dev directory:

root@android:/ # cd /devroot@android:/dev #

 

Check whether the TTT device file exists:

root@android:/dev # ls -l tttcrw------- root     root     249,   0 2013-04-02 09:58 ttt

Enter the/proc directory to verify the input and output of the device:

root@android:/dev # cd /proc/root@android:/proc #

Get the value of the TTT device:

root@android:/proc # cat ttt0root@android:/proc #

Set the value of the TTT device:

root@android:/proc # echo '111' > tttroot@android:/proc # cat ttt111root@android:/proc #

The TTT device file is OK, and the input and output interfaces are correct.

Of course, there are other ways to verify the input and output, such:

Go to the/sys/class TTT Device directory:

root@android:/proc # cd /sys/class/ttt/ttt/root@android:/sys/class/ttt/ttt # lsdevpowersubsystemueventvalroot@android:/sys/class/ttt/ttt #

Access the Val property file to read and write TTT device values:

root@android:/sys/class/ttt/ttt # lsdevpowersubsystemueventvalroot@android:/sys/class/ttt/ttt # cat val111root@android:/sys/class/ttt/ttt # echo '123' > valroot@android:/sys/class/ttt/ttt # cat val123root@android:/sys/class/ttt/ttt #

 

2. Write a C program to test the driver's read/write operations.

Switch to the root permission and go to the external directory under the android source code directory:

root@brantyou-ubuntu:~# cd workspace/android-4.0.4_r1.2/external/root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external# lsandroid-mock    freetype                 libpng         safe-iopantlr           fsck_msdos               libvpx         skiaapache-harmony  genext2fs                libxml2        sonivoxapache-http     giflib                   libxslt        speexapache-xml      google-diff-match-patch  libyuv         sqliteastl            grub                     llvm           srecbison           gtest                    lohit-fonts    srtpblktrace        guava                    markdown       stlportbluetooth       harfbuzz                 mesa3d         stracebouncycastle    hyphenation              mksh           svoxbsdiff          icu4c                    mockwebserver  tagsoupbzip2           iproute2                 mtpd           tcpdumpchromium        ipsec-tools              netcat         tinyalsaclang           iptables                 netperf        tinyxmlcollada         javasqlite               neven          tremolodbus            javassist                nist-sip       v8dhcpcd          jdiff                    oauth          valgrinddnsmasq         jhead                    opencv         webkitdoclava         jpeg                     openssl        webpdropbear        jsilver                  oprofile       webrtce2fsprogs       jsr305                   pcre           wpa_supplicanteasymock        junit                    ping           wpa_supplicant_6elfutils        kernel-headers           ping6          wpa_supplicant_8embunit         libffi                   ppp            xmlwriteremma            libgsm                   proguard       yaffs2esd             liblzf                   protobuf       yappexpat           libnfc-nxp               qemu           zlibeyes-free       libnl-headers            qemu-pc-biosfdlibm          libpcap                  quakeflac            libphonenumber           replicaislandroot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external# 

Due to the large number of files in this directory, I created a new yapp directory to store related programs.

Go to the yapp directory and create the tttapp directory:

root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp# mkdir tttapproot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp# lshelloapp  helloworld  tttapp

 

Go to the tttapp directory and create the tttapp. c file:

root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp# cd tttapp/root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp/tttapp# gedit tttapp.c

The content of the tttapp. c file is as follows:

#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#defineDEVICE_NAME"/dev/ttt"int main(int argc, char** argv){int fd = -1;int val = 0;fd = open(DEVICE_NAME, O_RDWR);if(fd == -1){printf("Failed to open device %s.\n", DEVICE_NAME);return -1;}printf("Read original value:\n");read(fd, &val, sizeof(val));printf("%d.\n\n", val);val = 100;printf("Write value %d to %s.\n\n", val, DEVICE_NAME);write(fd, &val, sizeof(val));printf("Read the value again:\n");read(fd, &val, sizeof(val));printf("%d.\n\n", val);close(fd);return 0;}

 

 

Create the corresponding Android. mk configuration file:

root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2/external/yapp/tttapp# gedit Android.mk

The content of the android. mk file is as follows:

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_MODULE := tttappLOCAL_SRC_FILES := tttapp.cinclude $(BUILD_EXECUTABLE)

After the C program is compiled, compile it as follows:

Return to the android source code directory and execute envsetup. sh:

root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# lsabi       build        device      hardware  out       systembionic    cts          docs        libcore   packages  v8.logbootable  dalvik       external    Makefile  prebuilt  vendorboot.img  development  frameworks  ndk       sdkroot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# . build/envsetup.sh including device/moto/stingray/vendorsetup.shincluding device/moto/wingray/vendorsetup.shincluding device/samsung/crespo4g/vendorsetup.shincluding device/samsung/crespo/vendorsetup.shincluding device/samsung/maguro/vendorsetup.shincluding device/samsung/smdkc110/vendorsetup.shincluding device/samsung/smdkv210/vendorsetup.shincluding device/samsung/torospr/vendorsetup.shincluding device/samsung/toro/vendorsetup.shincluding device/samsung/tuna/vendorsetup.shincluding device/ti/panda/vendorsetup.shincluding sdk/bash_completion/adb.bashroot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# 

 

Execute make tttapp to compile the tttapp program:

root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# make tttapp============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=4.0.4TARGET_PRODUCT=fullTARGET_BUILD_VARIANT=engTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armTARGET_ARCH_VARIANT=armv7-aHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD_ID=IMM76I============================================target thumb C: tttapp <= external/yapp/tttapp/tttapp.ctarget Executable: tttapp (out/target/product/generic/obj/EXECUTABLES/tttapp_intermediates/LINKED/tttapp)target Symbolic: tttapp (out/target/product/generic/symbols/system/bin/tttapp)target Strip: tttapp (out/target/product/generic/obj/EXECUTABLES/tttapp_intermediates/tttapp)Install: out/target/product/generic/system/bin/tttapproot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# 

This indicates that the compilation is successful. Let's see if the corresponding execution program has been generated:

root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# ls -l out/target/product/generic/system/bin/tttapp -rwxr-xr-x 1 root root 5524 2013-04-02 11:04 out/target/product/generic/system/bin/tttapproot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# 

In this way, the corresponding executable program is generated.

Now we copy the generated tttapp to the SD card and place it on the board for execution.

I put it on the USB flash drive and copied tttapp from the USB flash drive to the/data directory on the Board:

root@android:/mnt # ls usbD3GOther.exeEBOOT.binEBOOT.nb0IRDA_X.exeLOST.DIRMapTools.exeNK.BINNK_2G.binNK_3G.binNK_3G_y.BINNK_src.binRFIDForProduce.exeRFIDTest.exeRFID_X.exeSTEPLDR.binSTEPLDR.nb0SwitchTools.exeWINCE 6软件android-samsung-dev_20110830.tar.gzbarscan.exebbkhellohtcbjwdm.inftttappubuntu-11.10-desktop-i386.iso凯立德地图机身å·ç (MC60端).exeroot@android:/mnt #root@android:/mnt # lsasecext_sdobbsdcardsecureusbroot@android:/mnt # cd usb/root@android:/mnt/usb # lsD3GOther.exeEBOOT.binEBOOT.nb0IRDA_X.exeLOST.DIRMapTools.exeNK.BINNK_2G.binNK_3G.binNK_3G_y.BINNK_src.binRFIDForProduce.exeRFIDTest.exeRFID_X.exeSTEPLDR.binSTEPLDR.nb0SwitchTools.exeWINCE 6软件android-samsung-dev_20110830.tar.gzbarscan.exebbkhellohtcbjwdm.inftttappubuntu-11.10-desktop-i386.iso凯立德地图机身å·ç (MC60端).exeroot@android:/mnt/usb # ll tttapp----rwxr-x system   media_rw     5524 2013-04-02 11:08 tttapproot@android:/mnt/usb # chmod 777 tttapproot@android:/mnt/usb # ll tttapp----rwxr-x system   media_rw     5524 2013-04-02 11:08 tttapproot@android:/mnt/usb # cp tttapp /data/system/bin/sh: cp: not found127|root@android:/mnt/usb # mv tttapp /datafailed on 'tttapp' - Cross-device link255|root@android:/mnt/usb # mv tttapp /data/tttappfailed on 'tttapp' - Cross-device link255|root@android:/mnt/usb # cat tttapp > /data/tttapproot@android:/mnt/usb # ll /data/tttapp-rw-rw-rw- root     log          5524 2013-04-02 11:14 tttapproot@android:/mnt/usb # cd /dataroot@android:/data # ./tttapp/system/bin/sh: ./tttapp: cannot execute - Permission denied126|root@android:/data # chmod 777 tttapproot@android:/data # ./tttapp[ttt]: ttt_open().[ttt]: ttt_read().[ttt]: ttt_write().[ttt]: ttt_read().[ttt]: ttt_release().Read original value:123.Write value 100 to /dev/ttt.Read the value again:100.root@android:/data #

Some situations occur during the copy process. If the CP command is unavailable, you can use the cat command. From the last few statements above, we can see that the C program has succeeded. The test driver is OK.

 

 

At this point, the driver test is complete. The next article will introduce how to write the corresponding HAL Hardware Abstraction Layer to access the kernel driver.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.