On Wed, 28 Mar 2012, Scott Talbert wrote: > Well, I was just looking at the raw sizes of the binary parts (both were > compressed). After opening up the two zip files and diffing the contents, > they match except for the dump from the remote contains an extra directory > "platformconfig" of files that is not present in the file from the > website.
OK, well in any event, my patch for adding config dumping for usbnet is below. Basically, I use the READ_REGION set of commands to read the USER_CONFIG region. Since we don't know in advance how large the config is, I read the config during GetIdentity in order to get the size (so we can properly allocate memory to store it later). I went ahead and added documentation for the READ_REGION commands, too. Implement config dumping for usbnet remotes. Implemented the ReadFlash function and added a ReadRegion function which does the actual work. Signed-off-by: Scott Talbert <s...@techie.net> Index: libconcord/libconcord.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.cpp,v retrieving revision 1.42.2.20 diff -u -p -r1.42.2.20 libconcord.cpp --- libconcord/libconcord.cpp 28 Mar 2012 00:10:29 -0000 1.42.2.20 +++ libconcord/libconcord.cpp 30 Mar 2012 00:11:47 -0000 @@ -563,7 +563,7 @@ int _fix_magic_bytes(uint8_t *in, uint32 */ int is_config_dump_supported() { - return is_z_remote() ? LC_ERROR_UNSUPP: 0; + return (is_z_remote() && !is_usbnet_remote()) ? LC_ERROR_UNSUPP: 0; } int is_config_update_supported() Index: libconcord/remote.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote.h,v retrieving revision 1.20.2.10 diff -u -p -r1.20.2.10 remote.h --- libconcord/remote.h 28 Mar 2012 00:10:29 -0000 1.20.2.10 +++ libconcord/remote.h 30 Mar 2012 00:11:47 -0000 @@ -263,6 +263,8 @@ protected: virtual int ParseParams(uint32_t len, uint8_t *data, TParamList &pl)=0; virtual uint16_t GetWord(uint8_t *x)=0; + virtual int ReadRegion(uint8_t region, uint32_t &len, uint8_t *rd, + lc_callback cb, void *cb_arg, uint32_t cb_stage)=0; public: CRemoteZ_Base() {}; @@ -324,6 +326,8 @@ protected: virtual int ParseParams(uint32_t len, uint8_t *data, TParamList &pl); virtual uint16_t GetWord(uint8_t *x) { return x[1]<<8 | x[0]; }; + virtual int ReadRegion(uint8_t region, uint32_t &len, uint8_t *rd, + lc_callback cb, void *cb_arg, uint32_t cb_stage) {return 0;}; public: CRemoteZ_HID() {}; @@ -344,12 +348,19 @@ protected: virtual int ParseParams(uint32_t len, uint8_t *data, TParamList &pl); virtual uint16_t GetWord(uint8_t *x) { return x[0]<<8 | x[1]; }; + virtual uint32_t GetWord32(uint8_t *x) { return x[0]<<24 | x[1]<<16 + | x[2]<<8 | x[3]; }; + virtual int ReadRegion(uint8_t region, uint32_t &len, uint8_t *rd, + lc_callback cb, void *cb_arg, uint32_t cb_stage); public: CRemoteZ_USBNET() {}; virtual ~CRemoteZ_USBNET() {}; int UpdateConfig(const uint32_t len, const uint8_t *wr, lc_callback cb, void *cb_arg, uint32_t cb_stage); + int ReadFlash(uint32_t addr, const uint32_t len, uint8_t *rd, + unsigned int protocol, bool verify=false, + lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0); int GetTime(const TRemoteInfo &ri, THarmonyTime &ht); int SetTime(const TRemoteInfo &ri, const THarmonyTime &ht, lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0); Index: libconcord/remote_info.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote_info.h,v retrieving revision 1.12.2.2 diff -u -p -r1.12.2.2 remote_info.h --- libconcord/remote_info.h 22 Mar 2012 08:50:20 -0000 1.12.2.2 +++ libconcord/remote_info.h 30 Mar 2012 00:11:47 -0000 @@ -351,7 +351,7 @@ static const TArchInfo ArchList[]={ 0, // serial_address 0, // flash_base 0, // firmware_base - 0, // config_base + REGION_USER_CONFIG, // config_base 0, // firmware_update_base 0, // firmware_4847_offset 0x1, /* hack to make config test pass */ // cookie @@ -423,7 +423,7 @@ static const TArchInfo ArchList[]={ 0, // serial_address 0, // flash_base 0, // firmware_base - 0, // config_base + REGION_USER_CONFIG, // config_base 0, // firmware_update_base 0, // firmware_4847_offset 0x1, /* hack to make config test pass */ // cookie Index: libconcord/remote_z.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote_z.cpp,v retrieving revision 1.25.2.15 diff -u -p -r1.25.2.15 remote_z.cpp --- libconcord/remote_z.cpp 22 Mar 2012 08:50:20 -0000 1.25.2.15 +++ libconcord/remote_z.cpp 30 Mar 2012 00:11:47 -0000 @@ -577,6 +577,97 @@ int CRemoteZ_USBNET::SetTime(const TRemo return 0; } +int CRemoteZ_USBNET::ReadFlash(uint32_t addr, const uint32_t len, uint8_t *rd, + unsigned int protocol, bool verify, lc_callback cb, + void *cb_arg, uint32_t cb_stage) +{ + uint32_t tmp; + return ReadRegion(addr, tmp, rd, cb, cb_arg, cb_stage); +} + +int CRemoteZ_USBNET::ReadRegion(uint8_t region, uint32_t &rgn_len, uint8_t *rd, + lc_callback cb, void *cb_arg, uint32_t cb_stage) +{ + int err = 0; + int cb_count = 0; + uint8_t rsp[60]; + unsigned int rlen; + uint8_t status; + CRemoteZ_Base::TParamList pl; + + debug("READ_REGION"); + // 1 parameters, 1 byte, region to read. + uint8_t cmd[60] = { 0x01, 0x01, region }; + if ((err = Write(TYPE_REQUEST, COMMAND_READ_REGION, 3, cmd))) { + debug("Failed to write to remote"); + return LC_ERROR_WRITE; + } + if ((err = Read(status, rlen, rsp))) { + debug("Failed to read to remote"); + return LC_ERROR_READ; + } + if (rsp[2] != TYPE_RESPONSE || rsp[1] != COMMAND_READ_REGION || + rlen != 9 || rsp[4] != 0x04) { + debug("Incorrect response type from remote"); + return LC_ERROR_INVALID_DATA_FROM_REMOTE; + } + ParseParams(rlen, rsp, pl); + rgn_len = GetWord32(pl.p[0]); + + debug("READ_REGION_DATA"); + uint32_t pkt_len; + unsigned int data_to_read = rgn_len; + uint8_t *rd_ptr = rd; + uint8_t tmp_pkt[USBNET_MAX_PACKET_SIZE]; + cmd[0] = 0x01; // 1 parameter + cmd[1] = 0x01; // 1st parameter, 1 byte (region id) + cmd[2] = region; + + while (data_to_read) { + if ((err = Write(TYPE_REQUEST, COMMAND_READ_REGION_DATA, 3, + cmd))) { + debug("Failed to write to remote"); + return LC_ERROR_WRITE; + } + if ((err = Read(status, rlen, tmp_pkt))) { + debug("Failed to read to remote"); + return LC_ERROR_READ; + } + if (tmp_pkt[2] != TYPE_RESPONSE || + tmp_pkt[1] != COMMAND_READ_REGION_DATA) { + debug("Incorrect response type from remote"); + return LC_ERROR_INVALID_DATA_FROM_REMOTE; + } + ParseParams(rlen, tmp_pkt, pl); + pkt_len = GetWord32(pl.p[2]); + data_to_read -= pkt_len; + + if (rd) { + memcpy(rd_ptr, pl.p[1], pkt_len); + rd_ptr += pkt_len; + } + + debug("DATA %d, read %d bytes, %d bytes left", cb_count, + pkt_len, data_to_read); + + if (cb) { + cb(cb_stage, cb_count++, rgn_len - data_to_read, + rgn_len, LC_CB_COUNTER_TYPE_BYTES, cb_arg); + } + } + + debug("READ_REGION_DONE"); + // 1 parameter, 1 byte, region to read. + cmd[0] = 0x01; + cmd[1] = 0x01; + cmd[2] = region; + if ((err = TCPSendAndCheck(COMMAND_READ_REGION_DONE, 3, cmd))) { + return err; + } + + return 0; +} + int CRemoteZ_Base::Reset(uint8_t kind) { int err = 0; @@ -684,7 +775,16 @@ int CRemoteZ_Base::GetIdentity(TRemoteIn make_serial(pl.p[0], ri); - ri.config_bytes_used = 0; + if (IsUSBNet()) { + // Get the User Config Region to find the config bytes used. + if (err = ReadRegion(REGION_USER_CONFIG, ri.config_bytes_used, + NULL, NULL, NULL, 0)) { + return err; + } + } + else { + ri.config_bytes_used = 0; + } ri.max_config_size = 1; ri.valid_config = 1; Index: specs/protocol_z.txt =================================================================== RCS file: /cvsroot/concordance/concordance/specs/protocol_z.txt,v retrieving revision 1.6 diff -u -p -r1.6 protocol_z.txt --- specs/protocol_z.txt 1 Aug 2010 15:12:24 -0000 1.6 +++ specs/protocol_z.txt 30 Mar 2012 00:11:47 -0000 @@ -354,7 +354,42 @@ parameters: 12 (0x0c) message type: 0x01 parameters: 0 +COMMAND_READ_REGION 0x47 (71) +message type: 0x80 (128) +parameters: 1 + parameter 1: 1 byte (region ID) + sample values: 04 +message type: 0x01 (1) +parameters: 1 + parameter 1: 4 bytes (region size in bytes) + sample values: + 00 00 3e 88 + +COMMAND_READ_REGION_DATA 0x48 (72) +message type: 0x80 +parameters: 1 + parameter 1: 1 byte (region ID) + sample values: 04 + +message type: 0x01 +parameters: 3 + parameter 1: 1 byte (region ID) + sample values: 04 + parameter 2: 0x400 (1024) bytes (0xc2, 194/2 , 1100 0010) (data) + parameter 3: 4 bytes (length) + sample values: 00 00 04 00 +notes: + This is repeated for every 1K-byte chunk. + +COMMAND_READ_REGION_DONE 0x49 (73) +message type: 0x80 +parameters: 1 + parameter 1: 1 byte (region ID) + sample values: 04 + +message type: 0x01 +parameters: 0 # for vim vim:textwidth=80: ------------------------------------------------------------------------------ This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure _______________________________________________ concordance-devel mailing list concordance-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/concordance-devel