Finished download functionality, ready for testing.
This commit is contained in:
parent
bb4230aec9
commit
0e5ea85ddd
|
@ -113,6 +113,8 @@
|
|||
|
||||
#define CHUNKS_MAX 100
|
||||
|
||||
#define WRITESIZE_MAX 1024
|
||||
|
||||
/*================================================================*/
|
||||
/* Local Macros */
|
||||
|
||||
|
@ -234,9 +236,7 @@ UINT32 startaddr;
|
|||
|
||||
/* Load image chunks */
|
||||
UINT nfchunks;
|
||||
imgchunk_t fchunk[CHUNKS_MAX]; /* address of 0xffffffff indicates */
|
||||
UINT nrchunks;
|
||||
imgchunk_t rchunk[CHUNKS_MAX]; /* entry unused. */
|
||||
imgchunk_t fchunk[CHUNKS_MAX];
|
||||
|
||||
/* Note that for the following pdrec_t arrays, the len and code */
|
||||
/* fields are stored in HOST byte order. The mkpdrlist() function */
|
||||
|
@ -302,6 +302,11 @@ int pda_write(pda_t *pda);
|
|||
int plugimage( imgchunk_t *fchunk, UINT nfchunks,
|
||||
s3plugrec_t* s3plug, UINT ns3plug, pda_t *pda,
|
||||
char *fname);
|
||||
int crcimage( imgchunk_t *fchunk, UINT nfchunks,
|
||||
s3crcrec_t *s3crc, UINT ns3crc);
|
||||
int writeimage(imgchunk_t *fchunk, UINT nfchunks, int isflash);
|
||||
void free_chunks(imgchunk_t *fchunk, UINT* nfchunks);
|
||||
void free_srecs(void);
|
||||
|
||||
/*================================================================*/
|
||||
/* Function Definitions */
|
||||
|
@ -351,8 +356,6 @@ int main ( int argc, char **argv )
|
|||
|
||||
nfchunks = 0;
|
||||
memset( fchunk, sizeof(fchunk), 0);
|
||||
nrchunks = 0;
|
||||
memset( rchunk, sizeof(rchunk), 0);
|
||||
|
||||
/* clear the pda and add an initial END record */
|
||||
memset(&pda, 0, sizeof(pda));
|
||||
|
@ -565,27 +568,85 @@ int main ( int argc, char **argv )
|
|||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
/* Insert any CRCs */
|
||||
crcimage(fchunk, nfchunks, s3crc, ns3crc);
|
||||
#endif
|
||||
if (crcimage(fchunk, nfchunks, s3crc, ns3crc) ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to insert all CRCs for "
|
||||
"%s, exiting.\n",
|
||||
ffname[i]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Write the image */
|
||||
if ( opt_debug || !opt_nowrite ) continue;
|
||||
/* do the write */
|
||||
if ( opt_nowrite ) continue;
|
||||
result = writeimage(fchunk, nfchunks, 1);
|
||||
if ( result ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to flashwrite image data for "
|
||||
"%s, exiting.\n",
|
||||
ffname[i]);
|
||||
exit(1);
|
||||
}
|
||||
/* clear any allocated memory */
|
||||
free_chunks(fchunk, &nfchunks);
|
||||
free_srecs();
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the ram files */
|
||||
if ( opt_ramloadcnt ) {
|
||||
for ( i = 0; i < opt_ramloadcnt; i++) { /* For each file */
|
||||
/* Validate the identity and compat ranges */
|
||||
/* Read the S3 file */
|
||||
result = read_srecfile(rfname[i]);
|
||||
if ( result ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to read %s, exiting.\n",
|
||||
rfname[i]);
|
||||
exit(1);
|
||||
}
|
||||
/* Sort the S3 data records */
|
||||
qsort( s3data,
|
||||
ns3data,
|
||||
sizeof(s3datarec_t),
|
||||
s3datarec_compare);
|
||||
|
||||
/* TODO: Validate the identity and compat ranges */
|
||||
/* Make the image chunks */
|
||||
result = mkimage(fchunk, &nfchunks);
|
||||
|
||||
/* Do any plugging */
|
||||
result = plugimage(fchunk, nfchunks, s3plug, ns3plug,
|
||||
&pda, rfname[i]);
|
||||
if ( result ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to plug data for %s, exiting.\n",
|
||||
rfname[i]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Insert any CRCs */
|
||||
if (crcimage(fchunk, nfchunks, s3crc, ns3crc) ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to insert all CRCs for "
|
||||
"%s, exiting.\n",
|
||||
rfname[i]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Write the image */
|
||||
if ( opt_debug || !opt_nowrite ) continue;
|
||||
/* do the write */
|
||||
if ( opt_nowrite ) continue;
|
||||
result = writeimage(fchunk, nfchunks, 0);
|
||||
if ( result ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to ramwrite image data for "
|
||||
"%s, exiting.\n",
|
||||
rfname[i]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* clear any allocated memory */
|
||||
free_chunks(fchunk, &nfchunks);
|
||||
free_srecs();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,83 +657,76 @@ int main ( int argc, char **argv )
|
|||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* plugimage
|
||||
* crcimage
|
||||
*
|
||||
* Plugs the given image using the given plug records from the given
|
||||
* PDA and filename.
|
||||
* Adds a CRC16 in the two bytes prior to each block identified by
|
||||
* an S3 CRC record. Currently, we don't actually do a CRC we just
|
||||
* insert the value 0xC0DE in hfa384x order.
|
||||
*
|
||||
* Arguments:
|
||||
* fchunk Array of image chunks
|
||||
* nfchunks Number of image chunks
|
||||
* s3plug Array of plug records
|
||||
* ns3plug Number of plug records
|
||||
* pda Current pda data
|
||||
* fname File the image data was read from
|
||||
* s3crc Array of crc records
|
||||
* ns3crc Number of crc records
|
||||
*
|
||||
* Returns:
|
||||
* 0 success
|
||||
* ~0 failure
|
||||
----------------------------------------------------------------*/
|
||||
int plugimage( imgchunk_t *fchunk, UINT nfchunks,
|
||||
s3plugrec_t* s3plug, UINT ns3plug, pda_t *pda,
|
||||
char *fname)
|
||||
int crcimage(imgchunk_t *fchunk, UINT nfchunks, s3crcrec_t *s3crc, UINT ns3crc)
|
||||
{
|
||||
int result = 0;
|
||||
int i; /* plug index */
|
||||
int j; /* index of PDR or -1 if fname plug */
|
||||
int c; /* chunk index */
|
||||
UINT32 pstart;
|
||||
UINT32 pend;
|
||||
int i;
|
||||
int c;
|
||||
UINT32 crcstart;
|
||||
UINT32 crcend;
|
||||
UINT32 cstart;
|
||||
UINT32 cend;
|
||||
UINT8 *dest;
|
||||
UINT32 chunkoff;
|
||||
|
||||
/* for each plug record */
|
||||
for ( i = 0; i < ns3plug; i++) {
|
||||
pstart = s3plug[i].addr;
|
||||
pend = s3plug[i].addr + s3plug[i].len;
|
||||
/* find the matching PDR (or filename) */
|
||||
if ( s3plug[i].itemcode != 0xffffffffUL ) { /* not filename */
|
||||
for ( j = 0; j < pda->nrec; j++) {
|
||||
if ( s3plug[i].itemcode ==
|
||||
hfa384x2host_16(pda->rec[j]->code) ) break;
|
||||
}
|
||||
} else {
|
||||
j = -1;
|
||||
}
|
||||
if ( j >= pda->nrec && j != -1 ) { /* if no matching PDR, fail */
|
||||
fprintf(stderr, APPNAME
|
||||
": failed to find PDR for plugrec 0x%04lx, exiting.\n",
|
||||
s3plug[i].itemcode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Validate plug address against chunk data and identify chunk */
|
||||
for ( i = 0; i < ns3crc; i++ ) {
|
||||
if ( !s3crc[i].dowrite ) continue;
|
||||
crcstart = s3crc[i].addr;
|
||||
crcend = s3crc[i].addr + s3crc[i].len;
|
||||
/* Find chunk */
|
||||
for ( c = 0; c < nfchunks; c++) {
|
||||
cstart = fchunk[c].addr;
|
||||
cend = fchunk[c].addr + fchunk[c].len;
|
||||
if ( pstart >= cstart && pend <= cend ) break;
|
||||
/* the line below does an address & len match search */
|
||||
/* unfortunately, I've found that the len fields of */
|
||||
/* some crc records don't match with the length of */
|
||||
/* the actual data, so we're not checking right */
|
||||
/* now */
|
||||
/* if ( crcstart-2 >= cstart && crcend <= cend ) break;*/
|
||||
|
||||
/* note the -2 below, it's to make sure the chunk has */
|
||||
/* space for the CRC value */
|
||||
if ( crcstart-2 >= cstart && crcstart < cend ) break;
|
||||
}
|
||||
if ( c >= nfchunks ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": failed to find image chunk for "
|
||||
"plugrec 0x%04lx, exiting.\n",
|
||||
s3plug[i].itemcode);
|
||||
": Failed to find chunk for "
|
||||
"crcrec[%d], addr=0x%06lx len=%ld , "
|
||||
"aborting crc.\n",
|
||||
i, s3crc[i].addr, s3crc[i].len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Plug data */
|
||||
chunkoff = pstart - cstart;
|
||||
if ( j == -1 ) {
|
||||
|
||||
} else {
|
||||
|
||||
/* Insert crc */
|
||||
if (opt_verbose) {
|
||||
printf("Adding crc @ 0x%06lx\n", s3crc[i].addr-2);
|
||||
}
|
||||
chunkoff = crcstart - cstart - 2;
|
||||
dest = fchunk[c].data + chunkoff;
|
||||
*dest = 0xde;
|
||||
*(dest+1) = 0xc0;
|
||||
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* do_ioctl
|
||||
*
|
||||
|
@ -718,6 +772,60 @@ int do_ioctl( p80211msg_t *msg )
|
|||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* free_chunks
|
||||
*
|
||||
* Clears the chunklist data structures in preparation for a new file.
|
||||
*
|
||||
* Arguments:
|
||||
* none
|
||||
*
|
||||
* Returns:
|
||||
* nothing
|
||||
----------------------------------------------------------------*/
|
||||
void free_chunks(imgchunk_t *fchunk, UINT* nfchunks)
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i < *nfchunks; i++) {
|
||||
if ( fchunk[i].data != NULL ) {
|
||||
free(fchunk[i].data);
|
||||
}
|
||||
}
|
||||
*nfchunks = 0;
|
||||
memset( fchunk, sizeof(fchunk), 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* free_srecs
|
||||
*
|
||||
* Clears the srec data structures in preparation for a new file.
|
||||
*
|
||||
* Arguments:
|
||||
* none
|
||||
*
|
||||
* Returns:
|
||||
* nothing
|
||||
----------------------------------------------------------------*/
|
||||
void free_srecs(void)
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i < ns3data; i++) {
|
||||
free(s3data[i].data);
|
||||
}
|
||||
ns3data = 0;
|
||||
memset(s3data, 0, sizeof(s3data));
|
||||
ns3plug = 0;
|
||||
memset(s3plug, 0, sizeof(s3plug));
|
||||
ns3crc = 0;
|
||||
memset(s3crc, 0, sizeof(s3crc));
|
||||
ns3info = 0;
|
||||
memset(s3info, 0, sizeof(s3info));
|
||||
startaddr = 0;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* mkimage
|
||||
*
|
||||
|
@ -846,7 +954,6 @@ int mkpda_crc( pda_t *pda)
|
|||
lim = (UINT8*)(pda->rec[pda->nrec - 1]);
|
||||
lim += sizeof(UINT16) * 2; /* increase to include len&code fields */
|
||||
while (p < lim) {
|
||||
printf("%02x ", *p);
|
||||
crc = (crc >> 8 ) ^ crc16tab[(crc & 0xff) ^ *p++];
|
||||
}
|
||||
|
||||
|
@ -960,62 +1067,171 @@ int pda_write(pda_t *pda)
|
|||
/* Send flashdl_state(enable) */
|
||||
if (opt_verbose) printf("Sending dlflash_state(enable) message.\n");
|
||||
statemsg.enable.data = P80211ENUM_truth_true;
|
||||
result = do_ioctl((p80211msg_t*)&statemsg);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting pda download\n", result);
|
||||
return result;
|
||||
}
|
||||
if ( statemsg.resultcode.data != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->flashdl_state msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting pda download.\n",
|
||||
statemsg.resultcode.data);
|
||||
return 1;
|
||||
if ( !opt_debug ) {
|
||||
result = do_ioctl((p80211msg_t*)&statemsg);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting pda download\n", result);
|
||||
return result;
|
||||
}
|
||||
if ( statemsg.resultcode.data != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->flashdl_state msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting pda download.\n",
|
||||
statemsg.resultcode.data);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send flashdl_write(pda) */
|
||||
if (opt_verbose) printf("Sending dlflash_write message.\n");
|
||||
writemsg.addr.data = HFA384x_PDA_BASE;
|
||||
writemsg.len.data = (((UINT8*)(pda->rec[pda->nrec - 1])) - pda->buf + 6);
|
||||
memcpy(writemsg.data.data, pda->buf, writemsg.len.data);
|
||||
result = do_ioctl((p80211msg_t*)&writemsg);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting pda download\n", result);
|
||||
return result;
|
||||
if (opt_verbose) {
|
||||
printf("Sending dlflash_write, addr=%06lx len=%ld \n",
|
||||
writemsg.addr.data, writemsg.len.data);
|
||||
}
|
||||
if ( writemsg.resultcode.data != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->flashdl_write msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting pda download.\n",
|
||||
writemsg.resultcode.data);
|
||||
return 1;
|
||||
if ( !opt_debug ) {
|
||||
result = do_ioctl((p80211msg_t*)&writemsg);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting pda download\n", result);
|
||||
return result;
|
||||
}
|
||||
if ( writemsg.resultcode.data != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->flashdl_write msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting pda download.\n",
|
||||
writemsg.resultcode.data);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send flashdl_state(disable) */
|
||||
if (opt_verbose) printf("Sending dlflash_state(disable) message.\n");
|
||||
statemsg.enable.data = P80211ENUM_truth_false;
|
||||
result = do_ioctl((p80211msg_t*)&statemsg);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting pda download\n", result);
|
||||
return result;
|
||||
}
|
||||
if ( statemsg.resultcode.data != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->flashdl_state msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting pda download.\n",
|
||||
statemsg.resultcode.data);
|
||||
return 1;
|
||||
if ( !opt_debug ) {
|
||||
result = do_ioctl((p80211msg_t*)&statemsg);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting pda download\n", result);
|
||||
return result;
|
||||
}
|
||||
if ( statemsg.resultcode.data != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": pda_write()->flashdl_state msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting pda download.\n",
|
||||
statemsg.resultcode.data);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* plugimage
|
||||
*
|
||||
* Plugs the given image using the given plug records from the given
|
||||
* PDA and filename.
|
||||
*
|
||||
* Arguments:
|
||||
* fchunk Array of image chunks
|
||||
* nfchunks Number of image chunks
|
||||
* s3plug Array of plug records
|
||||
* ns3plug Number of plug records
|
||||
* pda Current pda data
|
||||
* fname File the image data was read from
|
||||
*
|
||||
* Returns:
|
||||
* 0 success
|
||||
* ~0 failure
|
||||
----------------------------------------------------------------*/
|
||||
int plugimage( imgchunk_t *fchunk, UINT nfchunks,
|
||||
s3plugrec_t* s3plug, UINT ns3plug, pda_t *pda,
|
||||
char *fname)
|
||||
{
|
||||
int result = 0;
|
||||
int i; /* plug index */
|
||||
int j; /* index of PDR or -1 if fname plug */
|
||||
int c; /* chunk index */
|
||||
UINT32 pstart;
|
||||
UINT32 pend;
|
||||
UINT32 cstart;
|
||||
UINT32 cend;
|
||||
UINT32 chunkoff;
|
||||
UINT8 *src;
|
||||
UINT8 *dest;
|
||||
|
||||
/* for each plug record */
|
||||
for ( i = 0; i < ns3plug; i++) {
|
||||
pstart = s3plug[i].addr;
|
||||
pend = s3plug[i].addr + s3plug[i].len;
|
||||
/* find the matching PDR (or filename) */
|
||||
if ( s3plug[i].itemcode != 0xffffffffUL ) { /* not filename */
|
||||
for ( j = 0; j < pda->nrec; j++) {
|
||||
if ( s3plug[i].itemcode ==
|
||||
hfa384x2host_16(pda->rec[j]->code) ) break;
|
||||
}
|
||||
} else {
|
||||
j = -1;
|
||||
}
|
||||
if ( j >= pda->nrec && j != -1 ) { /* if no matching PDR, fail */
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to find PDR for plugrec 0x%04lx, abort plugging.\n",
|
||||
s3plug[i].itemcode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Validate plug len against PDR len */
|
||||
if ( j != -1 &&
|
||||
s3plug[i].len < hfa384x2host_16(pda->rec[j]->len) ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Plug vs. PDR len mismatch for "
|
||||
"plugrec 0x%04lx, abort plugging.\n",
|
||||
s3plug[i].itemcode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Validate plug address against chunk data and identify chunk */
|
||||
for ( c = 0; c < nfchunks; c++) {
|
||||
cstart = fchunk[c].addr;
|
||||
cend = fchunk[c].addr + fchunk[c].len;
|
||||
if ( pstart >= cstart && pend <= cend ) break;
|
||||
}
|
||||
if ( c >= nfchunks ) {
|
||||
fprintf(stderr, APPNAME
|
||||
": Failed to find image chunk for "
|
||||
"plugrec 0x%04lx, abort plugging.\n",
|
||||
s3plug[i].itemcode);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Plug data */
|
||||
chunkoff = pstart - cstart;
|
||||
dest = fchunk[c].data + chunkoff;
|
||||
if (opt_verbose) {
|
||||
printf("Plugging item 0x%04lx @ 0x%06lx, len=%ld, "
|
||||
"cnum=%d coff=0x%06lx\n",
|
||||
s3plug[i].itemcode, pstart, s3plug[i].len,
|
||||
c, chunkoff);
|
||||
}
|
||||
if ( j == -1 ) { /* plug the filename */
|
||||
src = strrchr(fname, '/');
|
||||
src = (src == NULL) ? (UINT8*)fname : src + 1;
|
||||
memset(dest, 0, s3plug[i].len);
|
||||
strncpy(dest, src, s3plug[i].len - 1);
|
||||
} else { /* plug a PDR */
|
||||
memcpy( dest, &(pda->rec[j]->data), s3plug[i].len);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* print_all_pdrs
|
||||
*
|
||||
|
@ -1078,7 +1294,7 @@ void print_all_pdrs(pda_t *pda)
|
|||
printf(" ");
|
||||
for ( i = 0; i < end; i++ ) {
|
||||
printf("%04x ", datap[i]);
|
||||
if ( i % 8 == 7 ) {
|
||||
if ( (i % 16) == 15 ) {
|
||||
printf("\n ");
|
||||
}
|
||||
}
|
||||
|
@ -1266,7 +1482,7 @@ int read_filepda(pda_t *pda, char *pdrfname)
|
|||
(pdrlen + 1)*sizeof(UINT16));
|
||||
} else {
|
||||
fprintf( stderr, APPNAME
|
||||
": replacing pdrs where newlen!=oldlen not "
|
||||
": Replacing pdrs where (newlen!=oldlen) not "
|
||||
"supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1496,7 +1712,7 @@ int read_srecfile(char *fname)
|
|||
s3data[ns3data].data = malloc(tmprec.len);
|
||||
for ( i = 0; i < tmprec.len; i++) {
|
||||
memcpy(tmpbuf, buf+S3DATA_TXTOFFSET+(i*2), 2);
|
||||
tmpbuf[3] = '\0';
|
||||
tmpbuf[2] = '\0';
|
||||
s3data[ns3data].data[i] = strtoul(tmpbuf, NULL, 16);
|
||||
}
|
||||
ns3data++;
|
||||
|
@ -1585,31 +1801,34 @@ void usage(void)
|
|||
printf(" where valid options are:\n\n"
|
||||
" options: (pnemonics in parentheses)\n"
|
||||
" GENERAL OPTIONS:\n"
|
||||
" -v (verbose) Show more status info during operation.\n"
|
||||
" -V (Version) Show version and exit\n"
|
||||
" -n (nowrite) Do all processing, including card PDA read, \n"
|
||||
" but do not write to card.\n"
|
||||
" -d (debug) Do all processing, excluding card PDA read, \n"
|
||||
" but do not write to card. A valid interface \n"
|
||||
" name is _not_ required for this mode.\n"
|
||||
" -s (status) Show CIS, PDA from card and exit\n"
|
||||
" -v (verbose) Show more status info during operation.\n"
|
||||
" -V (Version) Show version and exit\n"
|
||||
" -n (nowrite) Do all processing, including card PDA read, \n"
|
||||
" but do not write to card.\n"
|
||||
" -d (debug) Do all processing, excluding card PDA read, \n"
|
||||
" but do not write to card. A valid interface \n"
|
||||
" name is _not_ required for this mode.\n"
|
||||
" -s (status) Show CIS, PDA from card and exit\n"
|
||||
" -g (generate) Show the PDA in a format readable by this \n"
|
||||
" program. Useful for saving the existing PDA\n"
|
||||
" from a card.\n"
|
||||
"\n"
|
||||
" IMAGEFILE OPTIONS:\n"
|
||||
" -r <file> (ram) Load SREC file to card RAM. This option may\n"
|
||||
" be specified multiple times.\n"
|
||||
" -f <file> (flash) Load SREC file to card FLASH. This option may\n"
|
||||
" be specified multiple times.\n"
|
||||
" -r <file> (ram) Load SREC file to card RAM. This option may\n"
|
||||
" be specified multiple times.\n"
|
||||
" -f <file> (flash) Load SREC file to card FLASH. This option may\n"
|
||||
" be specified multiple times.\n"
|
||||
"\n"
|
||||
" PDA OPTIONS:\n"
|
||||
" -a <file> (addpdr) Add the PDRs from file to the PDA from card. This\n"
|
||||
" option may be specified multiple times.\n"
|
||||
" -p <file> (pda) Replace the card PDA with the contents of file.\n"
|
||||
" -m <addr> (macaddr) Overwrite the MAC address PDR with the given \n"
|
||||
" value. <addr> ::= xx:xx:xx:xx:xx:xx, where \n"
|
||||
" xx is a two digit hex number.\n"
|
||||
" -S <str> (Sernum) Overwrite the serial number PDR with the given\n"
|
||||
" string. String must be <= 12 characters, any\n"
|
||||
" extra will be truncated.\n"
|
||||
" -a <file> (addpdr) Add the PDRs from file to the PDA from card. This\n"
|
||||
" option may be specified multiple times.\n"
|
||||
" -p <file> (pda) Replace the card PDA with the contents of file.\n"
|
||||
" -m <addr> (macaddr) Overwrite the MAC address PDR with the given \n"
|
||||
" value. <addr> ::= xx:xx:xx:xx:xx:xx, where \n"
|
||||
" xx is a two digit hex number.\n"
|
||||
" -S <str> (Sernum) Overwrite the serial number PDR with the given\n"
|
||||
" string. String must be <= 12 characters, any\n"
|
||||
" extra will be truncated.\n"
|
||||
"\n"
|
||||
" argument:\n"
|
||||
" devname Linux device name (e.g. eth0, wlan0)\n"
|
||||
|
@ -1644,4 +1863,229 @@ void usage(void)
|
|||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* writeimage
|
||||
*
|
||||
* Takes the chunks, builds p80211 messages and sends them down
|
||||
* to the driver for writing to the card.
|
||||
*
|
||||
* Arguments:
|
||||
* fchunk Array of image chunks
|
||||
* nfchunks Number of image chunks
|
||||
* isflash boolean indicating whether this is a
|
||||
* flash write or a ram write.
|
||||
*
|
||||
* Returns:
|
||||
* 0 success
|
||||
* ~0 failure
|
||||
----------------------------------------------------------------*/
|
||||
int writeimage(imgchunk_t *fchunk, UINT nfchunks, int isflash)
|
||||
{
|
||||
int result = 0;
|
||||
p80211msg_p2req_flashdl_state_t fstatemsg;
|
||||
p80211msg_p2req_flashdl_write_t fwritemsg;
|
||||
p80211msg_p2req_ramdl_state_t rstatemsg;
|
||||
p80211msg_p2req_ramdl_write_t rwritemsg;
|
||||
p80211msg_t *msgp;
|
||||
UINT32 resultcode;
|
||||
int i;
|
||||
int j;
|
||||
UINT nwrites;
|
||||
UINT32 curroff;
|
||||
UINT32 currlen;
|
||||
UINT32 currdaddr;
|
||||
|
||||
/* Initialize the messages */
|
||||
memset(&fstatemsg, 0, sizeof(fstatemsg));
|
||||
strcpy(fstatemsg.devname, devname);
|
||||
fstatemsg.msgcode = DIDmsg_p2req_flashdl_state;
|
||||
fstatemsg.msglen = sizeof(fstatemsg);
|
||||
fstatemsg.enable.did = DIDmsg_p2req_flashdl_state_enable;
|
||||
fstatemsg.resultcode.did = DIDmsg_p2req_flashdl_state_resultcode;
|
||||
fstatemsg.enable.status = P80211ENUM_msgitem_status_data_ok;
|
||||
fstatemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
|
||||
fstatemsg.enable.len = sizeof(UINT32);
|
||||
fstatemsg.resultcode.len = sizeof(UINT32);
|
||||
|
||||
memset(&fwritemsg, 0, sizeof(fwritemsg));
|
||||
strcpy(fwritemsg.devname, devname);
|
||||
fwritemsg.msgcode = DIDmsg_p2req_flashdl_write;
|
||||
fwritemsg.msglen = sizeof(fwritemsg);
|
||||
fwritemsg.addr.did = DIDmsg_p2req_flashdl_write_addr;
|
||||
fwritemsg.len.did = DIDmsg_p2req_flashdl_write_len;
|
||||
fwritemsg.data.did = DIDmsg_p2req_flashdl_write_data;
|
||||
fwritemsg.resultcode.did = DIDmsg_p2req_flashdl_write_resultcode;
|
||||
fwritemsg.addr.status = P80211ENUM_msgitem_status_data_ok;
|
||||
fwritemsg.len.status = P80211ENUM_msgitem_status_data_ok;
|
||||
fwritemsg.data.status = P80211ENUM_msgitem_status_data_ok;
|
||||
fwritemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
|
||||
fwritemsg.addr.len = sizeof(UINT32);
|
||||
fwritemsg.len.len = sizeof(UINT32);
|
||||
fwritemsg.data.len = 1024;
|
||||
fwritemsg.resultcode.len = sizeof(UINT32);
|
||||
|
||||
memset(&rstatemsg, 0, sizeof(rstatemsg));
|
||||
strcpy(rstatemsg.devname, devname);
|
||||
rstatemsg.msgcode = DIDmsg_p2req_ramdl_state;
|
||||
rstatemsg.msglen = sizeof(rstatemsg);
|
||||
rstatemsg.enable.did = DIDmsg_p2req_ramdl_state_enable;
|
||||
rstatemsg.exeaddr.did = DIDmsg_p2req_ramdl_state_exeaddr;
|
||||
rstatemsg.resultcode.did = DIDmsg_p2req_ramdl_state_resultcode;
|
||||
rstatemsg.enable.status = P80211ENUM_msgitem_status_data_ok;
|
||||
rstatemsg.exeaddr.status = P80211ENUM_msgitem_status_data_ok;
|
||||
rstatemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
|
||||
rstatemsg.enable.len = sizeof(UINT32);
|
||||
rstatemsg.exeaddr.len = sizeof(UINT32);
|
||||
rstatemsg.resultcode.len = sizeof(UINT32);
|
||||
|
||||
memset(&rwritemsg, 0, sizeof(rwritemsg));
|
||||
strcpy(rwritemsg.devname, devname);
|
||||
rwritemsg.msgcode = DIDmsg_p2req_ramdl_write;
|
||||
rwritemsg.msglen = sizeof(rwritemsg);
|
||||
rwritemsg.addr.did = DIDmsg_p2req_ramdl_write_addr;
|
||||
rwritemsg.len.did = DIDmsg_p2req_ramdl_write_len;
|
||||
rwritemsg.data.did = DIDmsg_p2req_ramdl_write_data;
|
||||
rwritemsg.resultcode.did = DIDmsg_p2req_ramdl_write_resultcode;
|
||||
rwritemsg.addr.status = P80211ENUM_msgitem_status_data_ok;
|
||||
rwritemsg.len.status = P80211ENUM_msgitem_status_data_ok;
|
||||
rwritemsg.data.status = P80211ENUM_msgitem_status_data_ok;
|
||||
rwritemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
|
||||
rwritemsg.addr.len = sizeof(UINT32);
|
||||
rwritemsg.len.len = sizeof(UINT32);
|
||||
rwritemsg.data.len = 1024;
|
||||
rwritemsg.resultcode.len = sizeof(UINT32);
|
||||
|
||||
/* Send xxx_state(enable) */
|
||||
if (opt_verbose) printf("Sending dl_state(enable) message.\n");
|
||||
if ( isflash ) {
|
||||
fstatemsg.enable.data = P80211ENUM_truth_true;
|
||||
} else {
|
||||
rstatemsg.enable.data = P80211ENUM_truth_true;
|
||||
rstatemsg.exeaddr.data = startaddr;
|
||||
}
|
||||
if ( !opt_debug ) {
|
||||
msgp = isflash ? (p80211msg_t*)&fstatemsg : (p80211msg_t*)&rstatemsg;
|
||||
result = do_ioctl(msgp);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": writeimage()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting download\n", result);
|
||||
return result;
|
||||
}
|
||||
resultcode = isflash ?
|
||||
fstatemsg.resultcode.data : rstatemsg.resultcode.data;
|
||||
if ( resultcode != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": writeimage()->xxxdl_state msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting download.\n",
|
||||
resultcode);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now, loop through the data chunks and send WRITESIZE_MAX data */
|
||||
for ( i = 0; i < nfchunks; i++) {
|
||||
#if 0
|
||||
FILE *fp;
|
||||
char fname[80];
|
||||
#endif
|
||||
nwrites = fchunk[i].len / WRITESIZE_MAX;
|
||||
nwrites += (fchunk[i].len % WRITESIZE_MAX) ? 1 : 0;
|
||||
curroff = 0;
|
||||
#if 0
|
||||
sprintf(fname, "d%06lx.dat", fchunk[i].addr);
|
||||
fp = fopen( fname, "w");
|
||||
#endif
|
||||
for ( j = 0; j < nwrites; j++) {
|
||||
currlen =
|
||||
(fchunk[i].len - (WRITESIZE_MAX * j)) > WRITESIZE_MAX ?
|
||||
WRITESIZE_MAX :
|
||||
(fchunk[i].len - (WRITESIZE_MAX * j));
|
||||
curroff = j * WRITESIZE_MAX;
|
||||
currdaddr = fchunk[i].addr + curroff;
|
||||
/* Setup the message */
|
||||
if ( isflash ) {
|
||||
fwritemsg.addr.data = currdaddr;
|
||||
fwritemsg.len.data = currlen;
|
||||
memcpy(fwritemsg.data.data,
|
||||
fchunk[i].data + curroff,
|
||||
currlen);
|
||||
#if 0
|
||||
fwrite(fwritemsg.data.data, 1, currlen, fp);
|
||||
#endif
|
||||
} else {
|
||||
rwritemsg.addr.data = currdaddr;
|
||||
rwritemsg.len.data = currlen;
|
||||
memcpy(rwritemsg.data.data,
|
||||
fchunk[i].data + curroff,
|
||||
currlen);
|
||||
#if 0
|
||||
fwrite(rwritemsg.data.data, 1, currlen, fp);
|
||||
#endif
|
||||
}
|
||||
/* Send flashdl_write(pda) */
|
||||
if (opt_verbose) {
|
||||
printf("Sending xxxdl_write message addr=%06lx len=%ld.\n",
|
||||
currdaddr, currlen);
|
||||
}
|
||||
|
||||
if ( opt_debug ) continue;
|
||||
|
||||
msgp = isflash ? (p80211msg_t*)&fwritemsg : (p80211msg_t*)&rwritemsg;
|
||||
result = do_ioctl(msgp);
|
||||
|
||||
/* Check the results */
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": writeimage()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting download\n", result);
|
||||
return result;
|
||||
}
|
||||
resultcode = isflash ?
|
||||
fstatemsg.resultcode.data : rstatemsg.resultcode.data;
|
||||
if ( resultcode != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": writeimage()->xxxdl_write msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting download.\n",
|
||||
resultcode);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
fclose(fp);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Send xxx_state(disable) */
|
||||
if (opt_verbose) printf("Sending dl_state(disable) message.\n");
|
||||
if ( isflash ) {
|
||||
fstatemsg.enable.data = P80211ENUM_truth_false;
|
||||
} else {
|
||||
rstatemsg.enable.data = P80211ENUM_truth_false;
|
||||
rstatemsg.exeaddr.data = 0;
|
||||
}
|
||||
|
||||
if ( opt_debug ) return result;
|
||||
|
||||
msgp = isflash ? (p80211msg_t*)&fstatemsg : (p80211msg_t*)&rstatemsg;
|
||||
result = do_ioctl(msgp);
|
||||
if ( result ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": writeimage()->do_ioctl() failed w/ result=%d, "
|
||||
"aborting download\n", result);
|
||||
return result;
|
||||
}
|
||||
resultcode = isflash ?
|
||||
fstatemsg.resultcode.data : rstatemsg.resultcode.data;
|
||||
if ( resultcode != P80211ENUM_resultcode_success ) {
|
||||
fprintf(stderr,APPNAME
|
||||
": writeimage()->xxxdl_state msg indicates failure, "
|
||||
"w/ resultcode=%ld, aborting download.\n",
|
||||
resultcode);
|
||||
return 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue