From Linux drivers to apk (2)

Source: Internet
Author: User

The corresponding parameter values are modified by the C language for the corresponding node operation.

The process of implementing a Linux application access-to-use drive node is implemented on the basis of the corresponding kernel driver. Implementation process: Add the implementation file to use, add the compilation rule, compile the implementation

1. Add the implementation file to use

Choose the appropriate location to store the relevant source code, this time I stored in: Vendor\welcome directory, the new welcome.c

Tips: In the event of an undefined compilation, it is possible that there is no corresponding header file after the kernel upgrade, you can use the terminal man function name in Linux to see the function and the definition of the relevant header file, add can

#include <stdio.h>#include<stdlib.h>#include<fcntl.h>#include<unistd.h>//Drive node for kernel-generated nodes#defineDevice_name "/DEV/WELCOMF"intMain (intargcChar**argv) {    intFD =-1; intval =0; FD=open (DEVICE_NAME,O_RDWR); if(FD = =-1) {printf ("Failed to open device%s.%m\n", device_name); return-1; } printf ("Read Original value: \ n"); Read (FD,&val,sizeof(Val)); printf ("val =%d.\n", Val); Val=2; printf ("Write value%d to%s.\n", Val,device_name); Write (FD,&val,sizeof(Val)); printf ("Read value again: \ n"); Read (FD,&val,sizeof(Val)); printf ("val =%d.\n", Val); return 0;}

2. Add Compilation rule Add Android.mk in this directory

local_path:=$ (call My-dir)
Include $ (clear_vars)
Local_module_tags:=optional
Local_module:=welcomebin
local_src_files:=$ (call All-subdir-c-files)
Include $ (build_executable)

3, compile and implement the direct compilation module MMM vendor/welcome

Then package the download, or directly use the production bin file with ADB push to the System/bin directory----If you cannot use the Attention node permissions issue

The bin file can be run through ADB into the appropriate directory. Can correctly output log and result is complete code

From Linux drivers to apk (2)

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.