📄 stmflashloader.cpp
字号:
STBL_SetRts(FALSE);
}
else
{
write_debug_info("bad parameter [Set Rts line] should be Hi or Lo ", 0 ,0, 0,KO);
break;
}
}
else
{
if (arg_index < argc - 1) printf("bad parameter [%s] \n", argv[arg_index]);
break;
}
}
}
else if (strcmp(argv[arg_index],"-Dtr")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1) arg_index++;
else break;
if(Is_Option(argv[arg_index])) break;
else if(Is_SubOption(argv[arg_index]))
{
if (strcmp(argv[arg_index],"--Hi")==0)
{
write_debug_info("[Set Dtr line]", 0 ,0, 0,OK);
STBL_SetDtr(TRUE);
}
else if (strcmp(argv[arg_index],"--Lo")==0)
{
write_debug_info("[Set Dtr line]", 0 ,0, 0,OK);
STBL_SetDtr(FALSE);
}
else
{
write_debug_info("bad parameter [Set Dtr line] should be Hi or Lo ", 0 ,0, 0,KO);
break;
}
}
else
{
if (arg_index < argc - 1) printf("bad parameter [%s] \n", argv[arg_index]);
break;
}
}
}
else if (strcmp(argv[arg_index],"-e")==0)
{
while(arg_index < argc)
{
if (!WaitForMoreSubOpt) break;
if (arg_index< argc-1) arg_index++;
else break;
if(Is_Option(argv[arg_index])) break;
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc) arg_index++;
else break;
if (strcmp(argv[arg_index-1],"--all")==0)
{
WaitForMoreSubOpt = false;
Res = STBL_ERASE(0xFF, NULL);
if (Res != SUCCESS) write_debug_info("erasing all pages", 0 ,0, 0, KO);
else write_debug_info("erasing all pages", 0 ,0, 0, OK);
}
else if (strcmp(argv[arg_index-1],"--sec")==0)
{
WaitForMoreSubOpt = true;
nsec = atoi(argv[arg_index]);
LPBYTE sectors = (LPBYTE)malloc(nsec + 1);
sectors[0] = 0;
for(int i = 1; i<= nsec; i++)
{
sectors[0]++;
arg_index++;
sectors[sectors[0]] = atoi(argv[arg_index]);
}
WaitForMoreSubOpt = false;
Res = STBL_ERASE(nsec, sectors+1);
if (Res != SUCCESS)
{
write_debug_info("erasing", 0 ,0, 0, KO);
if(COM_is_Open()) COM_Close(); printf("\n Press any key to continue ..."); getchar(); return 0;
}
else write_debug_info("erasing", 0 ,0, 0, OK);
arg_index++;
}
}
else
{
if (arg_index < argc - 1) printf("bad parameter [%s] \n", argv[arg_index]);
break;
}
}
}
else if (strcmp(argv[arg_index],"-u")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1) arg_index++;
else break;
if(Is_Option(argv[arg_index])) break;
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc) arg_index++;
else break;
/*if (strcmp(argv[arg_index-1],"--a")==0)
{
address = _tcstoul(argv[arg_index], 0, 16) ;
}
else if (strcmp(argv[arg_index-1],"--s")==0)
{
size = _tcstoul(argv[arg_index], 0, 16) ;
}
else */if (strcmp(argv[arg_index-1],"--fn")==0)
{
filename = argv[arg_index];
}
}
else
{
if (arg_index< argc) if (arg_index < argc - 1) printf("bad parameter [%s] \n", argv[arg_index]);
break;
}
}
HANDLE Handle;
FILES_CreateImage(&Handle, 0);
FILES_CreateImageFromMapping(&Handle,pMapping);
DWORD NbElements = 0;
if (FILES_GetImageNbElement(Handle, &NbElements) == FILES_NOERROR)
{
if (NbElements > 0)
{
for(int i = 0; i< (int)NbElements; i++)
{
IMAGEELEMENT Element={0};
// Get element data size
if (FILES_GetImageElement(Handle, i, &Element) == FILES_NOERROR)
{
//Upload element data
Element.Data = (LPBYTE)malloc(Element.dwDataLength);
if (STBL_UPLOAD(Element.dwAddress, Element.Data, Element.dwDataLength) == SUCCESS)
{
//Insert elment in the Image
write_debug_info("Uploading", i ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, OK);
FILES_SetImageElement(Handle,i,FALSE,Element);
}
else
{
write_debug_info("Uploading", i ,Element.dwAddress, (float)Element.dwDataLength/(float)1024, KO);
if(COM_is_Open()) COM_Close(); printf("\n Press any key to continue ..."); getchar(); return 0;
}
}
}
}
}
if(!FileExist((LPCTSTR)filename))
{
printf( "file %s does not exist .. Cretaing file\n", filename);
FILE* fp = fopen((LPCTSTR)filename, "a+");
fclose(fp);
}
printf( "Writing data ...\n");
if (FILES_ImageToFile((LPSTR)(LPCSTR)filename,Handle) == SUCCESS)
{
printf( "cannot open file %s \n", filename);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ..."); getchar(); return 0;
}
}
else if (strcmp(argv[arg_index],"-i")==0)
{
if (arg_index< argc) arg_index++;
else break;
sprintf(devname,"%s.STmap", argv[arg_index]);
char Drive[3], Dir[256], Fname[256], Ext[256];
_splitpath(argv[0],Drive,Dir,Fname,Ext);
char MapFile[256];
sprintf(MapFile, "%s%s%s%s", Drive, Dir , "Map\\", devname);
pMapping = NULL;
WORD size = 0;
WORD PacketSize = 0;
pMapping = NULL;
WORD Size = 0;
char MapName[256];
// Get the number of sectors in the flash target: pMapping should be NULL
// number of sectors is returned in the Size value
BYTE PagePerSector = 0;
if (!FileExist((LPCTSTR)MapFile))
{
printf("This version is not intended to support the <%s> target\n", argv[arg_index]);
if(COM_is_Open())
COM_Close();
printf("\n Press any key to continue ..."); getchar();
return 0;
}
FILES_GetMemoryMapping((LPSTR)(LPCTSTR)MapFile, &Size, (LPSTR)MapName, &PacketSize, pMapping, &PagePerSector);
// Allocate the mapping structure memory
pMapping = (PMAPPING)malloc(sizeof(MAPPING));
pMapping->NbSectors = 0;
pMapping->pSectors = (PMAPPINGSECTOR) malloc((Size) * sizeof(MAPPINGSECTOR));
// Get the mapping info
FILES_GetMemoryMapping((LPSTR)(LPCTSTR)MapFile, &Size, (LPSTR)(LPCTSTR)MapName, &PacketSize, pMapping, &PagePerSector);
SetPaketSize(PacketSize);
if (arg_index< argc) arg_index++;
else break;
}
else if (strcmp(argv[arg_index],"-d")==0)
{
while(arg_index < argc)
{
if (arg_index< argc-1) arg_index++;
else break;
if(Is_Option(argv[arg_index])) break;
else if(Is_SubOption(argv[arg_index]))
{
if (arg_index< argc) arg_index++;
else break;
if (strcmp(argv[arg_index-1],"--a")==0)
{
address = _tcstoul(argv[arg_index], 0, 16) ;
}
else if (strcmp(argv[arg_index-1],"--v")==0)
{
Verify = true;
arg_index--;
}
else if (strcmp(argv[arg_index-1],"--o")==0)
{
optimize = TRUE;
arg_index--;
}
else if (strcmp(argv[arg_index-1],"--fn")==0)
{
filename = argv[arg_index];
_splitpath(filename,Drive,Dir,Fname,Ext);
ptr=strupr(Ext);
strcpy(Ext, ptr);
}
}
else
{
if (arg_index < argc - 1) printf("bad parameter [%s] \n", argv[arg_index]);
break;
}
}
PMAPPINGSECTOR pSector = pMapping->pSectors;
for(int i = 1; i<= (int)pMapping->NbSectors; i++)
{
if ((strcmp(Ext, ".BIN")!=0) && (i==0))
address = pSector->dwStartAddress;
pSector->UseForOperation = TRUE;
pSector++;
}
if(!FileExist((LPCTSTR)filename))
{
printf( "file does not exist %s \n", filename);
if(COM_is_Open()) COM_Close(); printf("\n Press any key to continue ..."); getchar(); return 0;
}
HANDLE Handle;
if (FILES_ImageFromFile((LPSTR)(LPCSTR)filename,&Handle, 1) == FILES_NOERROR)
{
FILES_SetImageName(Handle,(LPSTR)(LPCSTR)filename);
DWORD NbElements = 0;
if (FILES_GetImageNbElement(Handle, &NbElements) == FILES_NOERROR)
{
if ( NbElements > 0 )
{ // if binary file -> change the elemnts address
if (strcmp(Ext, ".BIN")==0)
{
for (int i=0;i< (int)NbElements;i++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Handle, i, &Element) == FILES_NOERROR)
{
Element.Data= (LPBYTE)malloc(Element.dwDataLength);
if (FILES_GetImageElement(Handle, i, &Element) == FILES_NOERROR)
{
Element.dwAddress = Element.dwAddress + address;
FILES_SetImageElement(Handle, i, FALSE, Element);
}
}
}
}
}
}
FILES_FilterImageForOperation(Handle, pMapping, OPERATION_UPLOAD, optimize);
}
else
{
printf("cannot open file %s \n", filename);
if(COM_is_Open()) COM_Close(); printf("\n Press any key to continue ..."); getchar(); return 0;
}
DWORD NbElements = 0;
if (FILES_GetImageNbElement(Handle, &NbElements) == FILES_NOERROR)
{
for (int el=0; el< (int)NbElements;el++)
{
IMAGEELEMENT Element={0};
if (FILES_GetImageElement(Handle, el, &Element) == FILES_NOERROR)
{
Element.Data= (LPBYTE)malloc(Element.dwDataLength);
if (FILES_GetImageElement(Handle, el, &Element) == FILES_NOERROR)
{
if ((strcmp(Ext, ".BIN")==0) && (el==0))
Element.dwAddress = address;
if (STBL_DNLOAD(Element.dwAddress, Element.Data, Element.dwDataLength, false /*Optimize*/) != SUCCESS)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -