@@ -21,28 +21,17 @@ static struct qdl_device qdl;
21
21
22
22
bool qdl_debug ;
23
23
24
- int qdl_read (struct qdl_device * qdl , void * buf , size_t len , unsigned int timeout )
25
- {
26
- return read (qdl -> fd , buf , len );
27
- }
28
-
29
- int qdl_write (struct qdl_device * qdl , const void * buf , size_t len )
30
- {
31
-
32
- return write (qdl -> fd , buf , len );
33
- }
34
-
35
24
static void print_usage (void )
36
25
{
37
26
extern const char * __progname ;
38
27
fprintf (stderr ,
39
- "%s -p < sahara dev_node> -s <id:file path> ...\n" ,
28
+ "%s [--debug] [--serial <NUM>] [--port < sahara dev_node>] -s <id:file path> ...\n" ,
40
29
__progname );
41
30
fprintf (stderr ,
42
31
" -p --port Sahara device node to use\n"
43
32
" -s <id:file path> --sahara <id:file path> Sahara protocol file mapping\n"
44
33
"\n"
45
- "One -p instance is required. One or more -s instances are required. \n"
34
+ "One or more -s instances are required\n"
46
35
"\n"
47
36
"Example: \n"
48
37
"ks -p /dev/mhi0_QAIC_SAHARA -s 1:/opt/qti-aic/firmware/fw1.bin -s 2:/opt/qti-aic/firmware/fw2.bin\n" );
@@ -52,6 +41,7 @@ int main(int argc, char **argv)
52
41
{
53
42
bool found_mapping = false;
54
43
char * dev_node = NULL ;
44
+ char * serial = NULL ;
55
45
long file_id ;
56
46
char * colon ;
57
47
int opt ;
@@ -62,6 +52,7 @@ int main(int argc, char **argv)
62
52
{"version" , no_argument , 0 , 'v' },
63
53
{"port" , required_argument , 0 , 'p' },
64
54
{"sahara" , required_argument , 0 , 's' },
55
+ {"serial" , required_argument , 0 , 'S' },
65
56
{0 , 0 , 0 , 0 }
66
57
};
67
58
@@ -80,49 +71,60 @@ int main(int argc, char **argv)
80
71
case 's' :
81
72
found_mapping = true;
82
73
file_id = strtol (optarg , NULL , 10 );
83
- if (file_id < 0 ) {
84
- print_usage ();
85
- return 1 ;
86
- }
87
- if (file_id >= MAPPING_SZ ) {
88
- fprintf (stderr ,
89
- "ID:%ld exceeds the max value of %d\n" ,
90
- file_id ,
91
- MAPPING_SZ - 1 );
92
- return 1 ;
93
- }
74
+ if (file_id < 0 || file_id >= MAPPING_SZ )
75
+ errx (1 , "ID:%ld has to be in range of 0 - %d\n" , file_id , MAPPING_SZ - 1 );
76
+
94
77
colon = strchr (optarg , ':' );
95
- if (!colon ) {
96
- print_usage ();
97
- return 1 ;
98
- }
78
+ if (!colon )
79
+ errx (1 , "Sahara mapping requires ID and file path to be divided by a colon" );
80
+
99
81
qdl .mappings [file_id ] = & optarg [colon - optarg + 1 ];
100
82
printf ("Created mapping ID:%ld File:%s\n" , file_id , qdl .mappings [file_id ]);
101
83
break ;
84
+ case 'S' :
85
+ serial = optarg ;
86
+ break ;
102
87
default :
103
88
print_usage ();
104
89
return 1 ;
105
90
}
106
91
}
107
92
108
- // -p and - s is required
109
- if (!dev_node || ! found_mapping ) {
93
+ // -s is required
94
+ if (!found_mapping ) {
110
95
print_usage ();
111
96
return 1 ;
112
97
}
113
98
114
99
if (qdl_debug )
115
100
print_version ();
116
101
117
- qdl .fd = open (dev_node , O_RDWR );
118
- if (qdl .fd < 0 ) {
119
- fprintf (stderr , "Unable to open %s\n" , dev_node );
120
- return 1 ;
102
+ if (dev_node ) {
103
+ qdl .fd = open (dev_node , O_RDWR );
104
+ if (qdl .fd < 0 ) {
105
+ ret = 0 ;
106
+ printf ("Unable to open %s\n" , dev_node );
107
+ goto out_cleanup ;
108
+ }
109
+ }
110
+ else {
111
+ ret = qdl_open (& qdl , serial );
112
+ if (ret ) {
113
+ printf ("Failed to find edl device\n" );
114
+ goto out_cleanup ;
115
+ }
121
116
}
122
117
118
+
123
119
ret = sahara_run (& qdl , qdl .mappings , false, NULL , NULL );
124
120
if (ret < 0 )
125
- return 1 ;
121
+ goto out_cleanup ;
122
+
123
+ out_cleanup :
124
+ if (dev_node )
125
+ close (qdl .fd );
126
+ else
127
+ qdl_close (& qdl );
126
128
127
- return 0 ;
129
+ return !! ret ;
128
130
}
0 commit comments