|
|
@@ -0,0 +1,622 @@
|
|
|
+#include <stdio.h>
|
|
|
+#include <windows.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include "Shlwapi.h"
|
|
|
+//#pragma comment(lib,"shlwapi.lib")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#define VS_DEBUG_F(fmt, x...) \
|
|
|
+do \
|
|
|
+{ \
|
|
|
+ printf("%s %s(Line %d): "fmt,__LINE__, ##x); \
|
|
|
+}while(0)
|
|
|
+
|
|
|
+
|
|
|
+#define uint8 unsigned char
|
|
|
+#define uint16 unsigned short
|
|
|
+#define uint32 unsigned int
|
|
|
+
|
|
|
+
|
|
|
+typedef unsigned char uint8_t;
|
|
|
+typedef unsigned short uint16_t;
|
|
|
+typedef unsigned int uint32_t;
|
|
|
+
|
|
|
+
|
|
|
+typedef struct
|
|
|
+{
|
|
|
+
|
|
|
+ char Frpath[256]={0};
|
|
|
+ char Fwpath[256]={0};
|
|
|
+ char Fwname[256]={0};
|
|
|
+ uint8 devType = 0;
|
|
|
+ uint8 FirmwareType = 0;
|
|
|
+ uint32 ver = 0;
|
|
|
+
|
|
|
+} sBinAdd_t;
|
|
|
+sBinAdd_t myStruct = {
|
|
|
+ "",
|
|
|
+ "",
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+///////////////////////////////////////////////////////////////
|
|
|
+int my_getFileDirFromPath(char *pf){
|
|
|
+ char *pos;
|
|
|
+ char ptemp[256]={0};
|
|
|
+ unsigned int offset=0;
|
|
|
+
|
|
|
+ if(pf ==NULL){
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ strcpy(ptemp,pf);
|
|
|
+
|
|
|
+ pos = strrchr(ptemp,'/');
|
|
|
+ if(pos ==NULL){
|
|
|
+ pos = strrchr(ptemp,'\\');
|
|
|
+ if(pos ==NULL){
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ offset = abs(pos - ptemp);
|
|
|
+ pf[offset] = 0;
|
|
|
+ return 0;
|
|
|
+ //strncpy(pf,ptemp,offset);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+int opterr = 1, /* if error message should be printed */
|
|
|
+ optind = 1, /* index into parent argv vector */
|
|
|
+ optopt, /* character checked for validity */
|
|
|
+ optreset; /* reset getopt */
|
|
|
+char *optarg; /* argument associated with option */
|
|
|
+
|
|
|
+#define BADCH (int)'?'
|
|
|
+#define BADARG (int)':'
|
|
|
+#define EMSG ""
|
|
|
+
|
|
|
+/*
|
|
|
+* getopt --
|
|
|
+* Parse argc/argv argument vector.
|
|
|
+*/
|
|
|
+int m_getopt( int nargc, char * const nargv[], const char *ostr )
|
|
|
+{
|
|
|
+ static char *place = EMSG;
|
|
|
+ /* option letter processing */
|
|
|
+ const char *oli;
|
|
|
+ /* option letter list index */
|
|
|
+ if ( optreset || !*place )
|
|
|
+ {
|
|
|
+ /* update scanning pointer */
|
|
|
+ optreset = 0;
|
|
|
+ if ( optind >= nargc || *(place = nargv[optind]) != '-' )
|
|
|
+ {
|
|
|
+ place = EMSG;
|
|
|
+ return(-1);
|
|
|
+ }
|
|
|
+ if ( place[1] && *++place == '-' )
|
|
|
+ {
|
|
|
+ /* found "--" */
|
|
|
+ ++optind;
|
|
|
+ place = EMSG;
|
|
|
+ return(-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* option letter okay? */
|
|
|
+ if ( (optopt = (int) *place++) == (int) ':' ||
|
|
|
+ !(oli = strchr( ostr, optopt ) ) )
|
|
|
+ {
|
|
|
+ /*
|
|
|
+ * if the user didn't specify '-' as an option,
|
|
|
+ * assume it means -1.
|
|
|
+ */
|
|
|
+ if ( optopt == (int) '-' )
|
|
|
+ return(-1);
|
|
|
+ if ( !*place )
|
|
|
+ ++optind;
|
|
|
+ if ( opterr && *ostr != ':' )
|
|
|
+ (void) printf( "illegal option -- %c\n", optopt );
|
|
|
+ return(BADCH);
|
|
|
+ }
|
|
|
+ if ( *++oli != ':' )
|
|
|
+ {
|
|
|
+ /* don't need argument */
|
|
|
+ optarg = NULL;
|
|
|
+ if ( !*place )
|
|
|
+ ++optind;
|
|
|
+ } else {
|
|
|
+ /* need an argument */
|
|
|
+ if ( *place )
|
|
|
+ /* no white space */
|
|
|
+ optarg = place;
|
|
|
+ else if ( nargc <= ++optind )
|
|
|
+ {
|
|
|
+ /* no arg */
|
|
|
+ place = EMSG;
|
|
|
+ if ( *ostr == ':' )
|
|
|
+ return(BADARG);
|
|
|
+ if ( opterr )
|
|
|
+ (void) printf( "option requires an argument -- %c\n", optopt );
|
|
|
+ return(BADCH);
|
|
|
+ } else
|
|
|
+ /* white space */
|
|
|
+ optarg = nargv[optind];
|
|
|
+ place = EMSG;
|
|
|
+ ++optind;
|
|
|
+ }
|
|
|
+ return(optopt);
|
|
|
+ /* dump back option letter */
|
|
|
+}
|
|
|
+
|
|
|
+///////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//STM32 CRC32 软件模拟
|
|
|
+uint32 crc32(uint32 *ptr, uint32 len)
|
|
|
+{
|
|
|
+ uint32 xbit;
|
|
|
+ uint32 data;
|
|
|
+ uint32 CRC32 = 0xFFFFFFFF;
|
|
|
+ uint32 bits;
|
|
|
+ const uint32 dwPolynomial = 0x04c11db7;
|
|
|
+ uint32 i;
|
|
|
+
|
|
|
+ for(i = 0;i < len;i ++)
|
|
|
+ {
|
|
|
+ xbit = 1 << 31;
|
|
|
+ data = ptr[i];
|
|
|
+ for (bits = 0; bits < 32; bits++)
|
|
|
+ {
|
|
|
+ if (CRC32 & 0x80000000) {
|
|
|
+ CRC32 <<= 1;
|
|
|
+ CRC32 ^= dwPolynomial;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ CRC32 <<= 1;
|
|
|
+ if (data & xbit)
|
|
|
+ CRC32 ^= dwPolynomial;
|
|
|
+
|
|
|
+ xbit >>= 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return CRC32;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int readBinFile_test(char *prpath,char *pwpath){
|
|
|
+ unsigned char *buf_8=NULL; /*缓冲区*/
|
|
|
+ unsigned int *buf_32=NULL; /*缓冲区*/
|
|
|
+ unsigned char *p_8=NULL; /*指针*/
|
|
|
+ unsigned int *p_32=NULL; /*指针*/
|
|
|
+ char pf_8[256]={0}; /*指针*/
|
|
|
+ uint32 uCRC_32 = 0;
|
|
|
+ uint32 uAdd[8];
|
|
|
+ unsigned int i = 0;
|
|
|
+ unsigned int fsize_8 = 0;
|
|
|
+ unsigned int fsize_32 = 0;
|
|
|
+ unsigned int uTemp_32 = 0;
|
|
|
+ unsigned int b_index = 0;
|
|
|
+ unsigned int a_index = 0;
|
|
|
+ char sout[256] = {0};
|
|
|
+ unsigned int lout = 0;
|
|
|
+ int res = 0;
|
|
|
+
|
|
|
+ FILE *Fr,*Fw; /*文件指针*/
|
|
|
+ int len; /*文件大小*/
|
|
|
+
|
|
|
+ if((Fr = fopen(prpath,"rb")) == NULL)
|
|
|
+ {
|
|
|
+ printf("line=%d,open file failed\n", __LINE__);
|
|
|
+ exit (1) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ fseek (Fr, 0, SEEK_END); //文件尾
|
|
|
+ fsize_8=ftell (Fr); //计算文件大小
|
|
|
+ //
|
|
|
+
|
|
|
+ printf("line=%d,file size = %ld bytes.\n",__LINE__,fsize_8);
|
|
|
+ if(fsize_8%4){
|
|
|
+ printf("line=%d,size%%4!=0", __LINE__);
|
|
|
+ fclose(Fr);
|
|
|
+ exit (1) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ fsize_32 = fsize_8 / 4;
|
|
|
+
|
|
|
+ buf_8 = (unsigned char*)malloc(fsize_8+64);
|
|
|
+
|
|
|
+ if(buf_8==NULL){
|
|
|
+ printf("line=%d,buf_8=NULL", __LINE__);
|
|
|
+ fclose(Fr);
|
|
|
+ exit (1) ;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ res=fseek (Fr, 0, SEEK_SET); //文件头
|
|
|
+ printf("line=%d,res=%d.\n",__LINE__,res);
|
|
|
+ //memory_dump(buf,32);
|
|
|
+ p_8 = buf_8;
|
|
|
+ i = 0;
|
|
|
+ do{ //读取文件
|
|
|
+ buf_8[i++] = fgetc(Fr);
|
|
|
+ if(feof(Fr))
|
|
|
+ break;
|
|
|
+ } while (1);
|
|
|
+
|
|
|
+ fclose(Fr);
|
|
|
+ //printf("\nline=%d,read size =%d \n", __LINE__,i);
|
|
|
+
|
|
|
+ //res=fread(buf_8, fsize_8, 1, Fr);
|
|
|
+ //memory_dump(buf,32);
|
|
|
+ //printf("line=%d,res=%d.\n",__LINE__,res);
|
|
|
+
|
|
|
+ //start printf file
|
|
|
+ printf("\nline=%d,开始打印文件=%s,按字节(Byte)输出\n", __LINE__,prpath);
|
|
|
+ if((fsize_8) <17)
|
|
|
+ for(i=0;i<(fsize_8);i++){
|
|
|
+ printf("line=%d,i=%04d,data=0x%02X\n", __LINE__,i,buf_8[i]);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for(i=0;i<16;i++){
|
|
|
+ printf("0x%02X ",buf_8[i]);
|
|
|
+ }
|
|
|
+ printf("\nline=%d,...\n", __LINE__);
|
|
|
+ for(i=(fsize_8)-16;i<(fsize_8);i++){
|
|
|
+ printf("0x%02X ",buf_8[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ buf_32 = (unsigned int *)buf_8;
|
|
|
+ fsize_32 = fsize_8 / 4;
|
|
|
+
|
|
|
+ printf("line=%d,file size = %ld words.\n",__LINE__,fsize_32);
|
|
|
+ //打印文件
|
|
|
+ printf("\nline=%d,开始打印文件=%s,按字(WORD)输出\n", __LINE__,prpath);
|
|
|
+ if((fsize_32) <6)
|
|
|
+ for(i=0;i<(fsize_32);i++){
|
|
|
+ printf("line=%d,i=%04d,data=0x%08X\n", __LINE__,i,buf_32[i]);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for(i=0;i<3;i++){
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X\n", __LINE__,i,buf_32[i]);
|
|
|
+ }
|
|
|
+ printf("line=%d,...\n", __LINE__);
|
|
|
+ for(i=(fsize_32)-6;i<(fsize_32);i++){
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X\n", __LINE__,i,buf_32[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fclose(Fr);
|
|
|
+
|
|
|
+ //生成写入文件名
|
|
|
+ if((myStruct.Fwpath==NULL)||(myStruct.Fwpath[0]=='\0')){
|
|
|
+ strcpy((char *)pf_8,prpath);
|
|
|
+ my_getFileDirFromPath(pf_8);
|
|
|
+ strcpy(pwpath,pf_8);
|
|
|
+ strcat(pwpath,"/");
|
|
|
+
|
|
|
+ switch(myStruct.FirmwareType){
|
|
|
+ case 0x00:
|
|
|
+ strcat(pwpath,"A");
|
|
|
+ break;
|
|
|
+ case 0x01:
|
|
|
+ strcat(pwpath,"B");
|
|
|
+ break;
|
|
|
+ case 0x02:
|
|
|
+ strcat(pwpath,"S");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ lout = sprintf(sout,"%08X.bin",myStruct.ver);
|
|
|
+ strcat(pwpath,sout);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ strcpy(pwpath,myStruct.Fwpath);
|
|
|
+ }
|
|
|
+ //打开写入的文件
|
|
|
+ printf("\nline=%d,开始写入文件=%s\n", __LINE__,pwpath);
|
|
|
+ if((Fw = fopen(pwpath,"wb")) == NULL)
|
|
|
+ {
|
|
|
+ printf("line=%d,open file failed!\n", __LINE__);
|
|
|
+ exit (1) ;
|
|
|
+ }
|
|
|
+ fseek (Fw, 0, SEEK_SET); //定位文件头
|
|
|
+ fwrite((char *)(buf_8), fsize_8, 1, Fw);
|
|
|
+
|
|
|
+ printf("line=%d,写入的字节数%d\n", __LINE__,fsize_8);
|
|
|
+
|
|
|
+
|
|
|
+ //crc校验
|
|
|
+ // uCRC_32 = crc32(buf_32,(1*1024));
|
|
|
+ // printf("line=%d,crc32(buf_32,(1*1024))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(2*1024));
|
|
|
+ // printf("line=%d,crc32(buf_32,(2*1024))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(4*1024));
|
|
|
+ // printf("line=%d,crc32(buf_32,(4*1024))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17898));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17898))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17899));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17899))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17900));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17900))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17901));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17901))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17902));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17902))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17903));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17903))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ // uCRC_32 = crc32(buf_32,(17904));
|
|
|
+ // printf("line=%d,crc32(buf_32,(17904))=0x%08X!\n", __LINE__,uCRC_32);
|
|
|
+ //return 1;
|
|
|
+ //already add,no process
|
|
|
+ uTemp_32 = buf_32[(fsize_32-2)];
|
|
|
+ if(buf_32[(fsize_32-2)]==0x5a4c4843){
|
|
|
+ printf("line=%d,already add,no process!\n", __LINE__);
|
|
|
+ fclose(Fw);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ ////////////////////////////////////////////////////计算附加信息
|
|
|
+ a_index = 0;
|
|
|
+ //固件大小(不含附加信息)
|
|
|
+ uAdd[a_index++] = fsize_8;
|
|
|
+ buf_32[fsize_32+a_index-1] = uAdd[a_index-1];
|
|
|
+
|
|
|
+
|
|
|
+ //#define DEV_TYPE 0x1 // 1,加油机网关; 2,液位仪网关; 3,采集器
|
|
|
+ //#define FIRM_WARE_TYPE 0x0 // 0,app; 1,bt; 2,set
|
|
|
+ //设备类型(2字节),固件类型(2字节)
|
|
|
+ uAdd[a_index++] = ((myStruct.devType<<16)&0xFFFF0000)|((myStruct.FirmwareType<<0)&0x0000FFFF);
|
|
|
+ buf_32[fsize_32+a_index-1] = uAdd[a_index-1];
|
|
|
+
|
|
|
+
|
|
|
+ //软件版本
|
|
|
+ uAdd[a_index++] = myStruct.ver;
|
|
|
+ buf_32[fsize_32+a_index-1] = uAdd[a_index-1];
|
|
|
+
|
|
|
+
|
|
|
+ //固定标记
|
|
|
+ uAdd[a_index++] = 0x5a4c4843;
|
|
|
+ buf_32[fsize_32+a_index-1] = uAdd[a_index-1];
|
|
|
+
|
|
|
+ //crc校验
|
|
|
+ // uCRC_32 = crc32(buf_32,(fsize_32+0));
|
|
|
+ // uCRC_32 = crc32(buf_32,(fsize_32+1));
|
|
|
+ // uCRC_32 = crc32(buf_32,(fsize_32+2));
|
|
|
+ // uCRC_32 = crc32(buf_32,(fsize_32+3));
|
|
|
+ // uCRC_32 = crc32(buf_32,(fsize_32+4));
|
|
|
+ // uCRC_32 = crc32(buf_32,(fsize_32+5));
|
|
|
+ uCRC_32 = crc32(buf_32,(fsize_32+a_index));
|
|
|
+ uAdd[a_index++] = uCRC_32;
|
|
|
+ buf_32[fsize_32+a_index-1] = uAdd[a_index-1];
|
|
|
+
|
|
|
+
|
|
|
+ // for(i=0;i<a_index;i++){
|
|
|
+ // buf_32[fsize_32+i] = uAdd[i];
|
|
|
+ // //printf("line=%d,i=%04d,data=0x%08X\n", __LINE__,fsize_32+i,uAdd[i]);
|
|
|
+ // }
|
|
|
+
|
|
|
+ fwrite((char *)(uAdd), a_index * 4, 1, Fw);
|
|
|
+
|
|
|
+ fflush(Fw);
|
|
|
+
|
|
|
+ i=0;
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X,原始bin文件字节长度.\n", __LINE__,fsize_32+i,uAdd[i]);
|
|
|
+ i++;
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X,设备类型(2字节)+固件类型(2字节).\n", __LINE__,fsize_32+i,uAdd[i]);
|
|
|
+ i++;
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X,固件版本(4字节).\n", __LINE__,fsize_32+i,uAdd[i]);
|
|
|
+ i++;
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X,固定标记(4字节),\"ZLHC\".\n", __LINE__,fsize_32+i,uAdd[i]);
|
|
|
+ i++;
|
|
|
+ printf("line=%d,i=%08d,data=0x%08X,STM32 CRC32校验(4字节)(此前所有字节,含原始bin文件和附加信息).\n", __LINE__,fsize_32+i,uAdd[i]);
|
|
|
+ i++;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ printf("line=%d,最终写入的字节数%d+%d=%d\n", __LINE__,fsize_8,a_index*4,fsize_8+a_index*4);
|
|
|
+
|
|
|
+ fclose(Fw);
|
|
|
+ //fclose(Fw);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+void printf_help(void){
|
|
|
+ printf("\n");
|
|
|
+
|
|
|
+ printf("************************************************************************************************\n");
|
|
|
+ printf("* file name binAdd.exe *\n");
|
|
|
+ printf("* Copy Right By:SCX 版本:V0.0.0.1 build time:%s-%s *\n",__DATE__,__TIME__);
|
|
|
+ printf("* *\n");
|
|
|
+ printf("* 将 binAdd.exe 放到fromelf.exe同路径下,例如 D:/Keil_v5/ARM/ARMCC/bin *\n");
|
|
|
+ printf("* *\n");
|
|
|
+ printf("* description:在bin文件末尾追加校验字符,防止升级固件错误 *\n");
|
|
|
+ printf("* 已经追加,则不处理 *\n");
|
|
|
+ printf("* 第0个字:设备类型固件长度(不含附加字) *\n");
|
|
|
+ printf("* 第1个字:设备类型2字节,固件类型2字节 *\n");
|
|
|
+ printf("* 第2个字:固件版本,如61010001 *\n");
|
|
|
+ printf("* 第3个字:标记字符固定0x5a4c4843 *\n");
|
|
|
+ printf("* 第4个字:固件CRC32校验(此字之前的所有字,含前4个附加字) *\n");
|
|
|
+ printf("* *\n");
|
|
|
+ printf("* usage: *\n");
|
|
|
+ printf("* binAdd.exe -d 1 -f 0 -v 61010001-r \"E:\\work\\rrrr.bin\" [-w writeFile] *\n");
|
|
|
+ printf("* *\n");
|
|
|
+ printf("* option: *\n");
|
|
|
+ printf("* -d devType: *\n");
|
|
|
+ printf("* 1: oil gateWay加油机网关; *\n");
|
|
|
+ printf("* 2: tank gateWay液位仪网关; *\n");
|
|
|
+ printf("* 3: collector采集器; *\n");
|
|
|
+ printf("* -f FirmwareType: *\n");
|
|
|
+ printf("* 0,app应用程序; *\n");
|
|
|
+ printf("* 1,bt引导程序; *\n");
|
|
|
+ printf("* 2,set配置信息; *\n");
|
|
|
+ printf("* -v ver:待处理bin文件版本.e.g.61010001 *\n");
|
|
|
+ printf("* -r readFile: read frome file path. e.g. -r \"E:\\work\\rrrr.bin\" *\n");
|
|
|
+ printf("* [-w writeFile](可选): write to file path. e.g. -w \"E:\\work\\wwww.bin\" *\n");
|
|
|
+ printf("* e.g. binAdd.exe -d 1 -f 0 -r \"E:\\work\\rrrr.bin\" [-w writeFile] *\n");
|
|
|
+ printf("************************************************************************************************\n");
|
|
|
+
|
|
|
+ printf("\n");
|
|
|
+
|
|
|
+}
|
|
|
+uint32 str2hex(char *s){
|
|
|
+ int i=0;
|
|
|
+ uint32 data_32=0;
|
|
|
+ char *p=s;
|
|
|
+
|
|
|
+ i=0;
|
|
|
+ while((*p!=0)&&(i<8)){
|
|
|
+
|
|
|
+ data_32 <<=4;
|
|
|
+ if((*p>='0')&&(*p<='9')){
|
|
|
+ data_32 |= ((*p - '0') & 0x0F);
|
|
|
+ }
|
|
|
+ else if((*p>='A')&&(*p<='F')){
|
|
|
+ data_32 |= ((*p - 'A' + 10) & 0x0F);
|
|
|
+ }
|
|
|
+ else if((*p>='a')&&(*p<='f')){
|
|
|
+ data_32 |= ((*p - 'a' + 10) & 0x0F);
|
|
|
+ }
|
|
|
+ p++;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return data_32;
|
|
|
+}
|
|
|
+/*
|
|
|
+binAdd.exe -d 1 -f 0 -v 61010001 -r E:\80_work\VS-Code-C\binAdd\S62010002.bin
|
|
|
+
|
|
|
+
|
|
|
+*/
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ uint32 data[8] = {0x2000B050,0x080202D5,0x08025041,0x08024B0D,0x0802503D,0x08023085,0x0802C5D5,0x00000000};
|
|
|
+ uint32 data2[8] = {0xE7044520,0x9453E29E,0x85CC9C70,0x5AD25446,0x9331C830,0x3F122B65,0x2D3CAE31,0x81E1E490};
|
|
|
+ uint32 uTemp_32 = 0;
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ int len = 0;
|
|
|
+ int opt=0;
|
|
|
+ int res=0;
|
|
|
+
|
|
|
+ //////////////////////////////
|
|
|
+ // printf("data\n");
|
|
|
+ // uTemp_32 = crc32((data),1);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),2);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),3);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),4);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),5);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),6);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),7);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+ // uTemp_32 = crc32((data),8);
|
|
|
+ // printf("CRC=0x%08X\n",uTemp_32);
|
|
|
+
|
|
|
+
|
|
|
+ printf("This APP Build time is:%s - %s\r\n",__DATE__,__TIME__);
|
|
|
+
|
|
|
+ if((argc!=9)&&(argc!=11)){
|
|
|
+ printf_help();
|
|
|
+ //system("pause");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ res = 0;
|
|
|
+ while((opt=m_getopt(argc,(char * *)argv,"d:f:v:r:w:?h"))!=-1)
|
|
|
+ {
|
|
|
+ switch(opt)
|
|
|
+ {
|
|
|
+ case '?':
|
|
|
+ case 'h':
|
|
|
+ res = 1;
|
|
|
+ break;
|
|
|
+ case 'd':
|
|
|
+ myStruct.devType = ((uint8)atoi(optarg) & 0xf);
|
|
|
+ break;
|
|
|
+ case 'f':
|
|
|
+ myStruct.FirmwareType = ((uint8)atoi(optarg) & 0xf);
|
|
|
+ break;
|
|
|
+ case 'v':
|
|
|
+ myStruct.ver = (uint32)str2hex(optarg);
|
|
|
+ break;
|
|
|
+ case 'r':
|
|
|
+ strcpy(myStruct.Frpath, optarg);
|
|
|
+ break;
|
|
|
+ case 'w':
|
|
|
+ strcpy(myStruct.Fwpath, optarg);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ res = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(res!=0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(res!=0){
|
|
|
+ printf_help();
|
|
|
+ //system("pause");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //打印参数
|
|
|
+ printf("line=%d,start print input parameter.\n",__LINE__);
|
|
|
+ printf("line=%d,devType\t=\t%d\n", __LINE__,myStruct.devType);
|
|
|
+ printf("line=%d,FirmwareType\t=\t%d\n", __LINE__,myStruct.FirmwareType);
|
|
|
+ printf("line=%d,ver\t\t=\t%08X(Hex)\n", __LINE__,myStruct.ver);
|
|
|
+ printf("line=%d,Frpath\t\t=\t%s\n", __LINE__,myStruct.Frpath);
|
|
|
+ printf("line=%d,Fwpath\t\t=\t%s\n", __LINE__,myStruct.Fwpath);
|
|
|
+
|
|
|
+
|
|
|
+ //return 1;
|
|
|
+
|
|
|
+
|
|
|
+ printf("\nline=%d,start process bin file\n",__LINE__);
|
|
|
+ readBinFile_test(myStruct.Frpath,myStruct.Fwpath);
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+//////////////////////////////
|
|
|
+ printf("txt file\n");
|
|
|
+ uTemp_32 = crc32(uData_32,index);
|
|
|
+ printf("txt file CRC=0x%08X\n",uTemp_32);
|
|
|
+*/
|
|
|
+printf("处理完成!\n");
|
|
|
+//system("pause");
|
|
|
+return 0;
|
|
|
+}
|