-
Notifications
You must be signed in to change notification settings - Fork 21
/
makeupdate.c
363 lines (303 loc) · 8.43 KB
/
makeupdate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#define BUFSIZE 1024*100
char oneconfig[8][32]={0};
int SUPPORT_ZINK =0;
char *getRoorDir()
{
static char curdir[128]={0};
memset(curdir,0,sizeof(curdir));
getcwd(curdir,sizeof(curdir));
return curdir;
}
/*
修改文件将关键字后面的start和end字符串中间的数据改成data
@name:文件名称
@keystr:关键字
@data:要修改的数据
*/
int Modifyfile(char *name,char *keystr,char *start,char *end,char *data)
{
char *buf = (char *)malloc(BUFSIZE);
char filename[128]={0};
char *ptr = NULL;
int readlen = 0;
if(buf==NULL)return -1;
int fd = -1;
printf("Modifyfile-----------{%s,%s}\n",name,data);
printf("##########################################\n");
printf("Modifyfile-----------{%s,%s,%s}\n",keystr,start,end);
printf("##########################################\n");
do
{
sprintf(filename,"%s/%s",getRoorDir(),name);
if((fd=open(filename,O_RDWR)) <=0)
{
printf("open filename[%s] file failed\n",filename);
break;
}
if((readlen=read(fd,buf,BUFSIZE))<=0)
{
printf("read filename:%s file failed\n",filename);
break;
}
if( (ptr=strstr(buf,keystr)) == NULL)
{
printf("find keystr:%s failed\n",keystr);
break;
}
ptr+=strlen(keystr);
char *pstart =strstr(ptr,start);
if(pstart ==NULL)break;
char *pend =strstr(pstart,end);
if(pend ==NULL)break;
ftruncate(fd, 0);
lseek(fd, 0, SEEK_SET);
int index = pstart-buf+strlen(start);
//printf("index:%d,%d,%d\n",index,strlen(start),strlen(data));
write(fd , buf, index);//写要修改字符串之前的数据
write(fd , data, strlen(data));//写修改的数据
index=readlen-(pend-buf);
write(fd ,pend,index);//写后面的数据
//printf("pend:%s\n",pend);
fsync(fd);
//printf("index:%d,len:%d\n",readlen-(pend-buf),readlen);
}
while(0);
if(fd>0)
{
close(fd);
}
if(buf!=NULL)
{
free(buf);
}
printf("修改成功!!!!!\n");
return 0;
}
int ComplieAndMakepacket()
{
/*清除并编译*/
char cmd[512]={0};
sprintf(cmd,"make clean;make all -j");
system(cmd);
printf("run cmd :%s\n",cmd);
/*创建版本目录*/
sprintf(cmd,"mkdir output/%s",oneconfig[5]);
system(cmd);
printf("run cmd :%s\n",cmd);
/*拷贝对应的xml到对应的flash目录*/
sprintf(cmd,"cp xml/%s flash/%s/versioninfo.xml",oneconfig[2],oneconfig[4]);
system(cmd);
printf("run cmd :%s\n",cmd);
#if 0
/*按需拷贝wifi相关文件到指定打包目录*/
if( strcmp(oneconfig[0],"H42SPOE_IPC")!=0&& strcmp(oneconfig[0],"SPOE_IPC")!=0)
{
sprintf(cmd,"cp -rf ./wifi/Zink/3518e/timeout ./AppReleaseDir/%s/",oneconfig[3]);
system(cmd);
printf("run cmd :%s\n",cmd);
sprintf(cmd,"cp -rf ./wifi/Zink/3518e/www ./AppReleaseDir/%s/",oneconfig[3]);
system(cmd);
printf("run cmd :%s\n",cmd);
sprintf(cmd,"cp -rf ./wifi/Zink/3518e/tools ./AppReleaseDir/%s/wifi/",oneconfig[3]);
system(cmd);
printf("run cmd :%s\n",cmd);
}
#endif
/*打包版本*/
sprintf(cmd,"make app appversion=%s",oneconfig[5]);
system(cmd);
printf("run cmd :%s\n",cmd);
/*将打包后的文件拷贝到对应版本目录*/
sprintf(cmd,"cp flash/%s/* output/%s/ -rf",oneconfig[4],oneconfig[5]);
system(cmd);
printf("run cmd :%s\n",cmd);
// ./flash/3518e_ipc/makeprogrammingflashimg ./flash/3518e_ipc/u-boot-ok.bin ./flash/3518e_ipc/config ./flash/3518e_ipc/root_cramfs.img ./flash/3518e_ipc/app.img
// ./makeprogrammingflashimg u-boot-ok.bin config root_cramfs.img app.img
/*制作烧片文件*/
sprintf(cmd,"./output/%s/makeprogrammingflashimg output/%s/u-boot-ok.bin output/%s/hikernel output/%s/rootfs_64k.squashfs output/%s/app.img output/%s/config",oneconfig[5],oneconfig[5],oneconfig[5],oneconfig[5],oneconfig[5],oneconfig[5]);
system(cmd);
printf("run cmd :%s\n",cmd);
/*移动烧片文件到指定目录*/
sprintf(cmd,"mv 3518E-SOFTWARE.bin output/%s/",oneconfig[5]);
system(cmd);
printf("run cmd :%s\n",cmd);
//删除不用的文件
sprintf(cmd,"output/%s/app.img",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/config",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/makeprogrammingflashimg",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/rootfs_64k.squashfs",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/hikernel",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/u-boot-ok.bin",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/updatefile",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
sprintf(cmd,"output/%s/versioninfo.xml",oneconfig[5]);
unlink(cmd);
printf("unlink :%s\n",cmd);
}
int ParserOneVersionInof(int description,char* buf)
{
char tmp[128]={0};
printf("========================start============================\n");
if(strlen(buf)>1023)
{
printf("ParserOneVersionInof error buf size!!!\n");
return -1;
}
if(description&& oneconfig[6][0]=='1' )
{
//修改xml 版本记录
sprintf(tmp,"xml/%s",oneconfig[2]);
printf("修改xml 版本记录\n");
Modifyfile(tmp,(char *)"</version>",(char *)"<description>",(char *)" </description>",buf);
printf("=========================end===========================\n");
ComplieAndMakepacket();
return 0;
}
char *ptr = strchr(buf,'[');
if(ptr == NULL)
{
//printf("ParserOneVersionInof error return!!!\n");
return -1;
}
char data[1024]={0};
char index=0;
strcpy(data,ptr+1);
printf("%s\n",data);
char *line;
char *outer_ptr = NULL;
line = strtok_r(data, ",", &outer_ptr);
if(line!=NULL)
{
printf("ParserOneVersionInof:%s\n",line);
strcpy(oneconfig[index++],line);
}
while (line != NULL)
{
line = strtok_r(NULL, ",", &outer_ptr);
if(line!=NULL)
{
printf("ParserOneVersionInof:%s\n",line);
strcpy(oneconfig[index++],line);
}
}
//CARD_IPC,AR9271_IPC,card_ipc.xml,card_ipc,3518e_ipc,V7.9.0.18
//char machine[32]={0};
//char macro[32]={0};
//char xml[32]={0};
//char apprel[32]={0};
//char appflash[32]={0};
//char appver[32]={0};
//char need[32]={0};
if(oneconfig[6][0]!='0')//需要发布此版本
{
printf("------------------------------------------------------need make %s app\n",oneconfig[0]);
}
else
{
printf("-------------------------------------------------------not need make %s\n",oneconfig[0]);
return -1;
}
//修改makefile
printf("修改makefile\n");
Modifyfile((char *)"Makefile",(char *)"MACHINE_TYPE_SWITCH",(char *)" = ",(char *)"\n",(char *)oneconfig[0]);
//修改common.h
printf("修改common.h\n");
char keystr[64]={"defined "};
strcat(keystr,oneconfig[1]);
Modifyfile((char *)"include/common.h",keystr,(char *)"SOFTWAREVERSION \"",(char *)"\"\r\n",(char *)oneconfig[5]);
//修改xml 版本号
sprintf(tmp,"xml/%s",oneconfig[2]);
printf("修改xml 版本号\n");
Modifyfile(tmp,(char *)"</rootfs>",(char *)"<app>",(char *)"</app>",(char *)oneconfig[5]);
printf("=========================end===========================\n");
return 0;
}
int ParserConfig(char* FileName)
{
char configfile[128]={0};
char buf[10240]={0};
sprintf(configfile,"%s/v200makeconfig",getRoorDir());
int configfd = -1;
do
{
if((configfd=open(configfile,O_RDONLY)) <=0)
{
break;
}
if(read(configfd,buf,10240)<=0)
{
break;
}
char *decripe = strchr(buf,'{');
if(decripe==NULL)
{
break;
}
int decripelen = strlen(decripe);
decripe[decripelen-1] = 0;
decripe[decripelen-2] = 0;
decripe++;
printf("@@@@@@@@@@@@@@%s@@@@@@@@@@@@@@\n",decripe);
char *line;
char *outer_ptr = NULL;
line = strtok_r(buf, "]", &outer_ptr);
if(line!=NULL)
{
if(ParserOneVersionInof(0,line)==0)
{
ParserOneVersionInof(1,decripe);
}
//ParserOneVersionInof(1,decripe);
}
while (line != NULL)
{
line = strtok_r(NULL, "]", &outer_ptr);
if(line!=NULL)
{
//printf("222###%s###\n",line);
if(ParserOneVersionInof(0,line)==0)
{
ParserOneVersionInof(1,decripe);
}
//ParserOneVersionInof(1,decripe);
}
}
}
while(0);
if(configfd>0)
{
close(configfd);
}
return 0;
}
int main()
{
//printf("==============[%s]\n",getRoorDir());
system("rm output -rf");
system("rm TmpRelease -rf");
mkdir("output",S_IRUSR | S_IWUSR | S_IXUSR|S_IRGRP | S_IWGRP | S_IXGRP|S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
mkdir("TmpRelease",S_IRUSR | S_IWUSR | S_IXUSR|S_IRGRP | S_IWGRP | S_IXGRP|S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
ParserConfig(NULL);
//Modifyfile((char *)"Makefile",(char *)"MACHINE_TYPE_SWITCH",(char *)" = ",(char *)"\n",(char *)"SP_IPC");
return 0;
}