program to check and correct checksum for SMaL VGA firmware Sometimes the hardware guy takes a stab a writing software.
This program displays the PID, VID, Hardware Version, and checksum info for 0x800a byte long firmware found on the Logitech Pocket Digital and Oregon Scientific DS6618 and probably other SMaL based VGA cameras. Additionally, if the firmware file has been altered, it corrects the checksum stored in the firmware file.
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char **argv) {
FILE * pFile;
long fileSize;
unsigned int i;
unsigned char x;
unsigned short int PID, VID, HWVER, sumOffset, someVal, checksum, myChecksum;
if (argc < 2) {
printf("Usage: %s <filename>\\\\\\\\\\n",argv[0]);
printf("Where <filename> is the file to use.\\\\\\\\\\\n");
printf("Example: %s t0402-fw.pack\\\\\\\\\\\n",argv[0]);
exit(1);
}
pFile = fopen (argv[1], "r+b");
if (pFile==NULL) {
printf("Error opening file %s\\\\\\\\\\\n",argv[1]);
exit (1);
}
//check file size and exit if not 0x800a bytes
fseek (pFile,0,SEEK_END);
fileSize = ftell (pFile);
if (fileSize!=0x800a) {
printf("File size 0x%08lX not supported.\\\\\\\\\\\n",fileSize);
exit (1);
}
rewind (pFile);
myChecksum = 0;
fread (&PID,2,1,pFile);
fread (&VID,2,1,pFile);
fread (&HWVER,2,1,pFile);
fread (&sumOffset,2,1,pFile);
fread (&someVal,2,1,pFile);
//calculate checksum from start of code to checksum location
for (i=0; i<sumOffset; i++) {
fread (&x,1,1,pFile);
myChecksum += x;
}
fread (&checksum,2,1,pFile);
printf ("PID is 0x%04x\\\\\\\\\\\n",PID);
printf ("VID is 0x%04x\\\\\\\\\\\n",VID);
printf ("Hardware Version is 0x%04x\\\\\\\\\\\n",HWVER);
printf ("Checksum Offset is 0x%04x\\\\\\\\\\\n",sumOffset);
printf ("Checksum is 0x%04x\\\\\\\\\\\n",checksum);
printf ("Calculated Checksum is 0x%04x\\\\\\\\\\\n",myChecksum);
if (checksum!=myChecksum) {
//update checksum
fseek (pFile,-2,SEEK_CUR);
fwrite (&myChecksum,2,1,pFile);
//update copy of checksum
fseek (pFile,-2,SEEK_END);
fwrite (&myChecksum,2,1,pFile);
printf ("Firmware checksum corrected.\\\\\\\\\\\n");
}
fclose (pFile);
return 0;
}
SaturnNiGHTS- 04-17-2008
ahhh, you're taking my job! --grins--
zapped- 04-17-2008
ahhh, you're taking my job! --grins--
I'll be happy to let you add it to pv2tool along with the ability to upload the firmware and other functions on the VGA cameras.
While you are at it, you can update libgphoto.
SaturnNiGHTS- 04-17-2008
yeah, it's on my list. and will do, when that arises.
zapped- 04-18-2008
To upload firmware on DS6618:
send 26 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 to endpoint 0x01
then send the last 0x8000 bytes of the pack file to endpoint 0x01 (skip the first ten bytes sending from the beginning of code to the end of file)
To download firmware from the DS6618:
send 30 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 to endpoint 0x01
then get two 0x8000 byte packets. The firmware starts at byte 257 of the first packet and is of length 0x8000. To make it match the pack file, prepend the ten bytes that are two bytes from the end of the 0x8000 byte firmware to the beginning of the file making the length 0x800a.
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.