12static void ParseIHexLine(std::string line, std::vector <uint8_t> &data, uint32_t &upperAddr){
14 BUException::WIB_FLASH_IHEX_ERROR e;
15 e.Append(
"line is empty");
17 }
else if(line[0] !=
':'){
18 BUException::WIB_FLASH_IHEX_ERROR e;
19 e.Append(
"BAD Line in file - does not start with ':'");
25 BUException::WIB_FLASH_IHEX_ERROR e;
26 e.Append(
"BAD Line in file - incomplete intel hex format\n");
29 BUException::WIB_FLASH_IHEX_ERROR e;
30 e.Append(
"BAD Line in file - intel hex format not supported, contains too many characters\n");
32 }
else if (line.size()&1){
33 BUException::WIB_FLASH_IHEX_ERROR e;
34 e.Append(
"BAD Line in file - uneven number of characters\n");
37 char const *entry = line.c_str();
38 uint32_t line_sum = 0, byte_count = 0, address = 0, record_type = 0;
41 for(uint32_t iSum = 0; iSum < line.size(); iSum+=2){
42 sscanf(entry+iSum,
"%2x", &
byte);
49 line_sum = 0xFF & line_sum;
50 BUException::WIB_FLASH_IHEX_ERROR e;
51 e.Append(
"BAD Line in file - content inconsistent with checksum.\n");
57 sscanf(entry,
"%2x %4x %2x ", &byte_count, &address, &record_type);
60 sscanf(entry+8,
"%4x", &upperAddr);
61 upperAddr = upperAddr << 16;
62 }
else if(0 == record_type){
63 address = upperAddr+address;
64 if(data.size() < (address+byte_count)){
65 data.resize(address+byte_count,0xFF);
67 for(uint32_t iAddr = 0; iAddr < byte_count; iAddr++){
68 uint32_t tempData = 0;
69 sscanf(entry+(iAddr*2)+8,
"%02x",&tempData);
70 data[address+iAddr] = (uint8_t)tempData;
95 std::vector<uint8_t> rawData;
102 if((rawData.size()&0x3) != 0x0){
103 BUException::WIB_FLASH_IHEX_ERROR e;
104 e.Append(
"Flash data is not a multiple of 32bit words");
106 }
else if(0 == rawData.size()){
107 BUException::WIB_FLASH_IHEX_ERROR e;
108 e.Append(
"Flash data is empty");
113 std::vector<uint32_t> ret;
114 for(
size_t iRawData = 0; iRawData < rawData.size();iRawData+=4){
116 uint32_t tempData = (rawData[iRawData + 0] << 0 |
117 rawData[iRawData + 1] << 8 |
118 rawData[iRawData + 2] << 16 |
119 rawData[iRawData + 3] << 24 );
120 ret.push_back(tempData);
127 bool print_updates =
false;
128 if(update_percentage < 100){
129 print_updates =
true;
131 size_t update_delta = (update_percentage * float(16*1024*1024/4))/100;
132 size_t next_update = update_delta;
134 FILE * outFile = fopen(fileName.c_str(),
"w");
136 BUException::WIB_BAD_ARGS e;
137 e.Append(
"Failed to create: ");
143 fprintf(stderr,
" Reading flash\n");
144 fprintf(stderr,
" [");
145 for(
size_t i = 0; i < 100.0/update_percentage;i++){
148 fprintf(stderr,
"]\n [");
151 uint32_t address = 0;
154 size_t blockSize = 64;
158 for(
size_t iWord = 0; iWord < 16*1024*1024/4;){
169 for(
size_t iWordRead = 0;iWordRead < blockSize;iWordRead++){
170 fprintf(outFile,
"0x%06X 0x%08X\n",uint32_t(iWord),
ReadWithRetry(blockRegMapAddress+iWordRead));
175 address+=blockSize*4;
177 if(print_updates && (iWord > next_update)){
180 next_update += update_delta;
212 bool print_updates =
false;
213 if(update_percentage < 100){
214 print_updates =
true;
219 fprintf(stderr,
" Reading file: %s\n",fileName.c_str());
238 bool print_updates =
false;
239 if(update_percentage < 100){
240 print_updates =
true;
242 size_t update_delta = (update_percentage * float(flashData.size()))/100;
243 size_t next_update = update_delta;
245 fprintf(stderr,
" Programming flash\n");
246 fprintf(stderr,
" [");
247 for(
size_t i = 0; i < 100.0/update_percentage;i++){
250 fprintf(stderr,
"]\n [");
256 uint32_t flashAddress = 0;
258 for(
size_t currentBlockStartIndex = 0; currentBlockStartIndex < flashData.size();){
262 size_t blockSize = std::min(
size_t(64),flashData.size()-currentBlockStartIndex);
266 WriteWithRetry(
"FLASH.BYTE_COUNT",(blockSize*
sizeof(uint32_t))-1);
269 for(
size_t iBlockWord = 0; iBlockWord < blockSize;iBlockWord++){
273 flashData[currentBlockStartIndex + iBlockWord]);
277 currentBlockStartIndex += blockSize;
278 flashAddress += blockSize*
sizeof(uint32_t);
281 if(print_updates && (currentBlockStartIndex > next_update)){
283 next_update += update_delta;
288 fprintf(stderr,
"]\n");
289 fprintf(stderr,
" done\n");
295 bool print_updates =
false;
296 if(update_percentage < 100){
297 print_updates =
true;
299 size_t update_delta = (update_percentage * float(16*1024*1024/4))/100;
300 size_t next_update = update_delta;
303 fprintf(stderr,
" Checking flash\n");
304 fprintf(stderr,
" [");
305 for(
size_t i = 0; i < 100.0/update_percentage;i++){
308 fprintf(stderr,
"]\n [");
311 uint32_t flashAddress = 0;
314 for(
size_t currentBlockStartIndex = 0; currentBlockStartIndex < 16*1024*1024/4;){
318 size_t blockSize = std::min(
size_t(64),flashData.size()-currentBlockStartIndex);
322 WriteWithRetry(
"FLASH.BYTE_COUNT",(blockSize*
sizeof(uint32_t))-1);
329 for(
size_t iBlockWord = 0;iBlockWord < blockSize;iBlockWord++){
333 if((dataRead =
ReadWithRetry(blockRegMapAddress + iBlockWord)) !=
334 flashData[currentBlockStartIndex + iBlockWord]){
335 BUException::WIB_FLASH_ERROR e;
336 char errorbuffer[] =
"Error on index 0xXXXXXXXX: 0xXXXXXXXX != 0xXXXXXXXX";
337 snprintf(errorbuffer,
339 "Error on index 0x%08X: 0x%08X != 0x%08X",
342 flashData[currentBlockStartIndex + iBlockWord]);
343 e.Append(errorbuffer);
347 currentBlockStartIndex += blockSize;
348 flashAddress += blockSize*
sizeof(uint32_t);
350 if(print_updates && (currentBlockStartIndex > next_update)){
352 next_update += update_delta;
357 printf(
" Check passed\n");