老罗android之旅补丁版之二

为我们刚刚生成的/dev/hello字符设备写访问程序

根据原版写下来没有任何问题 二. 在Android系统中增加C可执行程序来访问硬件驱动程序

贴上来,在external/建立hello文件夹,

1>hello.c文件

#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#define DEVICE_NAME "/dev/hello"

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 = 5;
    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;
}
显而易见,把字符设备当做普通文件打开/dev/hello,读取他的值,然后改变值写入

以测试是否可以访问成功


2>Makefile文件

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_EXECUTABLE)

3>进入/external/hello用mm部分编译

在这里,我觉得可以说一下部分编译的做法 。

①source ./build/envsetup.h

source./build/envsetup.sh,其实就是把当前目录下build下的envsetup.sh加载到环境中,下面来看envsetup.sh

其中包含了若干函数,其中有我们编译需要用到的mm,mmm,当然也包括lunch,即用来选择编译类型的命令


functionhmm() {

cat<<EOF

Invoke". build/envsetup.sh" from your shell to add the followingfunctions to your environment:

-lunch: lunch <product_name>-<build_variant>

-tapas: tapas [<App1> <App2> ...][arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]

-croot: Changes directory to the top of the tree.

-m: Makes from the top of the tree.

-mm: Builds all of the modules in the current directory, but nottheir dependencies.

-mmm: Builds all of the modules in the supplied directories, butnot their dependencies.

Tolimit the modules being built use the syntax: mmmdir/:target1,target2.

-mma: Builds all of the modules in the current directory, andtheir dependencies.

-mmma: Builds all of the modules in the supplied directories, andtheir dependencies.

-cgrep: Greps on all local C/C++ files.

-ggrep: Greps on all local Gradle files.

-jgrep: Greps on all local Java files.

-resgrep: Greps on all local res/*.xml files.

-sgrep: Greps on all local source files.

-godir: Go to the directory containing a file.


②下面来看lunch实现的一部分内容

lunch是用来让用户选择编译项,来定义product和编译过程中用到的全局变量

functionlunch()

{

localanswer


if[ "$1" ] ; then

answer=$1

else

print_lunch_menu

echo-n "Which would you like? [aosp_arm-eng] "

readanswer

fi


lunch不带参数时,便会调用print_lunch_menu列出菜单,显示Whichwould you like?并返回选择answer

在菜单中选择需要的编译选项,这里我选择build_eng

③顺便提一下./mkimage XXXX build_eng

./mkimage调用的是/device/asus/common/script/build/mkimage.sh

这是我现在这版本的code的mkimage.sh文件内容

echo"PRODUCT_NAME:"

echo" Z00L : ze550kl"

echo" Z00T : ze551kl"

echo"Actions:"

echo" build_eng : build eng mode image which saved in\"Image\" folder"

这也就是./mkimageZ00L build_eng命令的由来

部分编译成功后,把/out/target/product/Z00L/system/bin下生成的hello可执行程序push到手机/system/bin下

运行hello


结果so easy


这样呢,至少可以证明我们建好的字符设备正常,可读可写


Thanks~~~


购物商城项目采用PHP+mysql有以及html+css jq以及layer.js datatables bootstorap等插件等开发,采用了MVC模式,建立一个完善的电商系统,通过不同用户的不同需求,进行相应的调配和处理,提高对购买用户进行配置….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值