#include #include #ifndef WIN32 #include #include #include #include #include #include #include #include #include #else #include #include "getopt.h" #include "printf.h" #include "buildno.h" #endif #include "hdlcio.h" #include "ptable.h" #include "flasher.h" #include "util.h" #define true 1 #define false 0 //*************************************************** //* Error code //*************************************************** int errcode; //*************************************************** //* Error code output command //*************************************************** void printerr() { if (errcode == -1) printf(" - Timeout\n"); else printf(" - Error Code %02x\n",errcode); } //*************************************************** // Send partition start command // // code - 32-bit partition code // size - full size of the writable partition // //* result: // false - error // true - command was accepted by the modem //*************************************************** int dload_start(uint32_t code,uint32_t size) { uint32_t iolen; uint8_t replybuf[4096]; #ifndef WIN32 static struct __attribute__ ((__packed__)) { #else #pragma pack(push,1) static struct { #endif uint8_t cmd; uint32_t code; uint32_t size; uint8_t pool[3]; } cmd_dload_init = {0x41,0,0,{0,0,0}}; #ifdef WIN32 #pragma pack(pop) #endif cmd_dload_init.code=htonl(code); cmd_dload_init.size=htonl(size); iolen=send_cmd((uint8_t*)&cmd_dload_init,sizeof(cmd_dload_init),replybuf); errcode=replybuf[3]; if ((iolen == 0) || (replybuf[1] != 2)) { if (iolen == 0) errcode=-1; return false; } else return true; } //*************************************************** // Sending a partition block // // blk - # of block // pimage - address of the partition image start in memory // //* result: // false - error // true - command was accepted by the modem //*************************************************** int dload_block(uint32_t part, uint32_t blk, uint8_t* pimage) { uint32_t res,blksize,iolen; uint8_t replybuf[4096]; #ifndef WIN32 static struct __attribute__ ((__packed__)) { #else #pragma pack(push,1) static struct { #endif uint8_t cmd; uint32_t blk; uint16_t bsize; uint8_t data[fblock]; } cmd_dload_block; #ifdef WIN32 #pragma pack(pop) #endif blksize=fblock; // initial block size value res=ptable[part].hd.psize-blk*fblock; // size of the remaining chunk to the end of the file if (res