Revision d54d2f07
Host/Source/SerialBoot/main.c | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
|
... | ... | |
42 | 42 |
#include "xcpmaster.h" /* XCP master protocol module */ |
43 | 43 |
#include "srecord.h" /* S-record file handling */ |
44 | 44 |
#include "timeutil.h" /* time utility module */ |
45 |
#include "stdlib.h" /* ascii to integral conversion */ |
|
45 | 46 |
|
46 | 47 |
|
47 | 48 |
/**************************************************************************************** |
... | ... | |
95 | 96 |
* Local data declarations |
96 | 97 |
****************************************************************************************/ |
97 | 98 |
/** \brief Name of the serial device, such as COM4 or /dev/ttyUSB0. */ |
98 |
static sb_char serialDeviceName[32];
|
|
99 |
static sb_char serialDeviceName[32]; |
|
99 | 100 |
|
100 | 101 |
/** \brief Id of the bluetooth device, such as 01:23:45:67:89:AB. */ |
101 |
static sb_char bluetoothID[18];
|
|
102 |
static sb_char bluetoothID[18]; |
|
102 | 103 |
|
103 | 104 |
/** \brief Serial communication speed in bits per second. */ |
104 |
static sb_uint32 serialBaudrate;
|
|
105 |
static sb_uint32 serialBaudrate; |
|
105 | 106 |
|
106 | 107 |
/** \brief Name of the S-record file. */ |
107 |
static sb_char *srecordFileName;
|
|
108 |
static sb_char *srecordFileName; |
|
108 | 109 |
|
109 | 110 |
/* program status */ |
110 | 111 |
static sb_uint8 prog_state = 1; |
111 | 112 |
|
112 | 113 |
/* id of flashing target */ |
113 |
static sb_uint8 flashingTargetID = 0;
|
|
114 |
static sb_uint32 flashingTargetID = 0;
|
|
114 | 115 |
|
115 | 116 |
/* list of program names */ |
116 | 117 |
static sb_char *srecordFileNames[MAX_COUNT_FLASHING_PROGRAMS]; |
117 | 118 |
|
118 | 119 |
/* list of target ids */ |
119 |
static sb_uint8 flashingTargetIDs[MAX_COUNT_FLASHING_PROGRAMS];
|
|
120 |
static sb_uint32 flashingTargetIDs[MAX_COUNT_FLASHING_PROGRAMS];
|
|
120 | 121 |
|
121 | 122 |
/* list of errors */ |
122 | 123 |
static sb_uint8 errors[MAX_COUNT_FLASHING_PROGRAMS]; |
... | ... | |
181 | 182 |
errorDetected = ERROR_NO; |
182 | 183 |
flashingTargetID = flashingTargetIDs[flashIdx]; |
183 | 184 |
srecordFileName = srecordFileNames[flashIdx]; |
184 |
printf("\nFlash %i: Flashing %s on device %i\n\n", flashIdx+1, srecordFileName, flashingTargetID); |
|
185 |
printf("\nFlash %i: Flashing %s on device 0x%08X\n\n", flashIdx+1, srecordFileName, flashingTargetID); |
|
186 |
|
|
185 | 187 |
if (flashProgram() == PROG_RESULT_ERROR) { |
186 | 188 |
closeSerialPort(); |
187 | 189 |
openSerialPortConnect(0); |
... | ... | |
278 | 280 |
printf("Programming will start immediately in following order:\n"); |
279 | 281 |
sb_uint8 idx; |
280 | 282 |
for (idx=0; idx<countFlashingPrograms; idx++) { |
281 |
printf(" %i) device %i: %s\n", idx+1, flashingTargetIDs[idx], srecordFileNames[idx]);
|
|
283 |
printf(" %i) device 0x%08X: %s\n", idx+1, flashingTargetIDs[idx], srecordFileNames[idx]);
|
|
282 | 284 |
} |
283 | 285 |
} |
284 | 286 |
|
285 | 287 |
|
286 | 288 |
/************************************************************************************//** |
287 | 289 |
** \brief Parses the command line arguments. A fixed amount of arguments is expected. |
288 |
** The program should be called as:
|
|
290 |
** The program should be called as: |
|
289 | 291 |
** SerialBoot -d[device] -b[baudrate] [s-record file] |
290 | 292 |
** \param argc Number of program parameters. |
291 | 293 |
** \param argv array to program parameter strings. |
... | ... | |
330 | 332 |
printf("The bluetooth ID %s has not the format xx:xx:xx:xx:xx:xx\n", &argv[paramIdx][2]); |
331 | 333 |
return SB_FALSE; |
332 | 334 |
} |
333 |
// copy the bluetooth id and set flag that this parameter was found
|
|
335 |
// copy the bluetooth id and set flag that this parameter was found |
|
334 | 336 |
strcpy(serialDeviceName, &argv[paramIdx][2]); |
335 | 337 |
paramAfound = SB_TRUE; |
336 | 338 |
comIsUart = SB_FALSE; |
... | ... | |
359 | 361 |
} |
360 | 362 |
if (registerRTSvalue > 1 || registerRTSvalue < 0 || setValue[1] != 0x0) { |
361 | 363 |
registerRTSvalue = 0; |
362 |
printf("Not allowed value for RTS register. RTS=[0,1]\n");
|
|
364 |
printf("Not allowed value for RTS register. RTS=[0,1]\n");
|
|
363 | 365 |
return SB_FALSE; |
364 | 366 |
} |
365 | 367 |
paramRTSfound = SB_TRUE; |
... | ... | |
414 | 416 |
srecordfound = SB_TRUE; |
415 | 417 |
} |
416 | 418 |
} |
417 |
|
|
419 |
|
|
418 | 420 |
/* verify if all parameters were found */ |
419 | 421 |
if ( ( ((paramDfound == SB_FALSE) || (paramBfound == SB_FALSE)) && (paramAfound == SB_FALSE)) || (srecordfound == SB_FALSE) ) |
420 | 422 |
{ |
... | ... | |
445 | 447 |
printf("\n%i ERRORs detected!\nOnly in the following %i cases SerialBoot updated the firmware:\n", detected, countFlashingPrograms-detected); |
446 | 448 |
for (errorIdx=0; errorIdx<countFlashingPrograms; errorIdx++) { |
447 | 449 |
if (errors[errorIdx] == ERROR_NO) { |
448 |
printf(" * Flash %i: %s on device %i\n", errorIdx+1, srecordFileNames[errorIdx], flashingTargetIDs[errorIdx]);
|
|
450 |
printf(" * Flash %i: %s on device 0x%08X\n", errorIdx+1, srecordFileNames[errorIdx], flashingTargetIDs[errorIdx]);
|
|
449 | 451 |
} |
450 | 452 |
} |
451 | 453 |
printf("In the following %i cases SerialBoot could not update the firmware:\n", detected); |
... | ... | |
459 | 461 |
case ERROR_FILE: |
460 | 462 |
printf("The file %s couldn't be read!\n", srecordFileNames[errorIdx]); break; |
461 | 463 |
case ERROR_DEVICE: |
462 |
printf("No connection to device %i!\n", flashingTargetIDs[errorIdx]); break;
|
|
464 |
printf("No connection to device 0x%08X!\n", flashingTargetIDs[errorIdx]); break;
|
|
463 | 465 |
default: |
464 | 466 |
printf("Couldn't specify the error. Please check output above!\n"); break; |
465 | 467 |
} |
... | ... | |
504 | 506 |
tSrecordLineParseResults lineParseResults; |
505 | 507 |
|
506 | 508 |
/* -------------------- start the firmware update procedure ------------------------ */ |
507 |
printf("Starting firmware update for \"%s\" on device %i (0x", srecordFileName, flashingTargetID); |
|
508 |
if (flashingTargetID < 16) |
|
509 |
{ |
|
510 |
printf("0"); |
|
511 |
} |
|
512 |
printf("%X)\nUsing %s @ %u bits/s\n", flashingTargetID, serialDeviceName, serialBaudrate); |
|
509 |
printf("Starting firmware update for \"%s\" on device 0x%08X\n", srecordFileName, flashingTargetID); |
|
510 |
printf("Using %s @ %u bits/s\n", serialDeviceName, serialBaudrate); |
|
513 | 511 |
|
514 | 512 |
/* -------------------- prepare programming session -------------------------------- */ |
515 | 513 |
if (prepareProgrammingSession(&hSrecord, &fileParseResults) == PROG_RESULT_ERROR) { |
... | ... | |
707 | 705 |
} else if (flashingTargetID == 0) { |
708 | 706 |
printf("Try to connect to device..."); |
709 | 707 |
} else { |
710 |
printf("Try to connect to device 0x"); |
|
711 |
if (flashingTargetID < 16) { |
|
712 |
printf("0"); |
|
713 |
} |
|
714 |
printf("%X...", flashingTargetID); |
|
708 |
printf("Try to connect to device 0x%08X...", flashingTargetID); |
|
715 | 709 |
} |
716 | 710 |
} |
717 | 711 |
/* now keep retrying until we get a response */ |
Host/Source/SerialBoot/xcpmaster.c | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
|
... | ... | |
91 | 91 |
/**************************************************************************************** |
92 | 92 |
* Function prototypes |
93 | 93 |
****************************************************************************************/ |
94 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID);
|
|
94 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint32 flashingTargetID);
|
|
95 | 95 |
static sb_uint8 XcpMasterSendCmdSetMta(sb_uint32 address); |
96 | 96 |
static sb_uint8 XcpMasterSendCmdUpload(sb_uint8 data[], sb_uint8 length); |
97 | 97 |
static sb_uint8 XcpMasterSendCmdProgramStart(void); |
... | ... | |
155 | 155 |
** \return SB_TRUE is successfull, SB_FALSE otherwise. |
156 | 156 |
** |
157 | 157 |
****************************************************************************************/ |
158 |
sb_uint8 XcpMasterConnect(sb_uint8 flashingTargetID)
|
|
158 |
sb_uint8 XcpMasterConnect(sb_uint32 flashingTargetID)
|
|
159 | 159 |
{ |
160 | 160 |
sb_uint8 cnt; |
161 | 161 |
sb_uint8 retries = 1; |
162 | 162 |
if (flashingTargetID <= 0) { |
163 | 163 |
retries = XCP_MASTER_CONNECT_RETRIES; |
164 | 164 |
} |
165 |
|
|
165 |
|
|
166 | 166 |
/* try to connect with a finite amount of retries */ |
167 | 167 |
for (cnt=0; cnt<retries; cnt++) |
168 | 168 |
{ |
... | ... | |
357 | 357 |
** \return SB_TRUE is successfull, SB_FALSE otherwise. |
358 | 358 |
** |
359 | 359 |
****************************************************************************************/ |
360 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID)
|
|
360 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint32 flashingTargetID)
|
|
361 | 361 |
{ |
362 |
sb_uint8 packetData[2];
|
|
362 |
sb_uint8 packetData[1+4];
|
|
363 | 363 |
tXcpTransportResponsePacket *responsePacketPtr; |
364 |
|
|
364 |
|
|
365 | 365 |
/* prepare the command packet */ |
366 | 366 |
packetData[0] = XCP_MASTER_CMD_CONNECT; |
367 |
packetData[1] = flashingTargetID; /* normal mode */ |
|
368 |
|
|
369 |
/* send the packet */ |
|
370 |
if (XcpTransportSendPacket(packetData, 2, XCP_MASTER_CONNECT_TIMEOUT_MS) == SB_FALSE) |
|
367 |
packetData[1] = (sb_uint8)(0xFF & flashingTargetID >> 0); |
|
368 |
packetData[2] = (sb_uint8)(0xFF & flashingTargetID >> 8); |
|
369 |
packetData[3] = (sb_uint8)(0xFF & flashingTargetID >> 16); |
|
370 |
packetData[4] = (sb_uint8)(0xFF & flashingTargetID >> 24); |
|
371 |
|
|
372 |
/* send the packet |
|
373 |
* NOTE: For legacy support the following code depends on the MSB if the flashingTargetID. |
|
374 |
* If the MSB (packData[4]) is zero (i.e. 0x00??????) the system switches to legacy mode. |
|
375 |
* In legacy mode, the flashingTargetID was only one byte - the LSB (packingData[1]). |
|
376 |
*/ |
|
377 |
if (XcpTransportSendPacket(packetData, 1 + ((packetData[4] != 0) ? 4 : 1), XCP_MASTER_CONNECT_TIMEOUT_MS) == SB_FALSE) |
|
371 | 378 |
{ |
372 | 379 |
/* cound not set packet or receive response within the specified timeout */ |
373 | 380 |
return SB_FALSE; |
374 | 381 |
} |
375 | 382 |
/* still here so a response was received */ |
376 | 383 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
377 |
|
|
384 |
|
|
378 | 385 |
/* check if the reponse was valid */ |
379 | 386 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
380 | 387 |
{ |
381 | 388 |
/* not a valid or positive response */ |
382 | 389 |
return SB_FALSE; |
383 | 390 |
} |
384 |
|
|
391 |
|
|
385 | 392 |
/* process response data */ |
386 | 393 |
if ((responsePacketPtr->data[2] & 0x01) == 0) |
387 | 394 |
{ |
... | ... | |
400 | 407 |
{ |
401 | 408 |
xcpMaxDto = responsePacketPtr->data[5] + (responsePacketPtr->data[4] << 8); |
402 | 409 |
} |
403 |
|
|
410 |
|
|
404 | 411 |
/* double check size configuration of the master */ |
405 | 412 |
assert(XCP_MASTER_TX_MAX_DATA >= xcpMaxCto); |
406 | 413 |
assert(XCP_MASTER_RX_MAX_DATA >= xcpMaxDto); |
407 |
|
|
408 |
/* still here so all went well */
|
|
414 |
|
|
415 |
/* still here so all went well */ |
|
409 | 416 |
return SB_TRUE; |
410 | 417 |
} /*** end of XcpMasterSendCmdConnect ***/ |
411 | 418 |
|
... | ... | |
420 | 427 |
{ |
421 | 428 |
sb_uint8 packetData[8]; |
422 | 429 |
tXcpTransportResponsePacket *responsePacketPtr; |
423 |
|
|
430 |
|
|
424 | 431 |
/* prepare the command packet */ |
425 | 432 |
packetData[0] = XCP_MASTER_CMD_SET_MTA; |
426 | 433 |
packetData[1] = 0; /* reserved */ |
427 | 434 |
packetData[2] = 0; /* reserved */ |
428 | 435 |
packetData[3] = 0; /* address extension not supported */ |
429 |
|
|
436 |
|
|
430 | 437 |
/* set the address taking into account byte ordering */ |
431 | 438 |
XcpMasterSetOrderedLong(address, &packetData[4]); |
432 |
|
|
439 |
|
|
433 | 440 |
/* send the packet */ |
434 | 441 |
if (XcpTransportSendPacket(packetData, 8, XCP_MASTER_TIMEOUT_T4_MS) == SB_FALSE) //XCP_MASTER_TIMEOUT_T1_MS |
435 | 442 |
{ |
... | ... | |
439 | 446 |
} |
440 | 447 |
/* still here so a response was received */ |
441 | 448 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
442 |
|
|
449 |
|
|
443 | 450 |
/* check if the reponse was valid */ |
444 | 451 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
445 | 452 |
{ |
... | ... | |
452 | 459 |
printf(" (set MTA)\n"); |
453 | 460 |
return SB_FALSE; |
454 | 461 |
} |
455 |
|
|
456 |
/* still here so all went well */
|
|
462 |
|
|
463 |
/* still here so all went well */ |
|
457 | 464 |
return SB_TRUE; |
458 | 465 |
} /*** end of XcpMasterSendCmdSetMta ***/ |
459 | 466 |
|
... | ... | |
470 | 477 |
sb_uint8 packetData[2]; |
471 | 478 |
tXcpTransportResponsePacket *responsePacketPtr; |
472 | 479 |
sb_uint8 data_index; |
473 |
|
|
480 |
|
|
474 | 481 |
/* cannot request more data then the max rx data - 1 */ |
475 | 482 |
assert(length < XCP_MASTER_RX_MAX_DATA); |
476 |
|
|
483 |
|
|
477 | 484 |
/* prepare the command packet */ |
478 | 485 |
packetData[0] = XCP_MASTER_CMD_UPLOAD; |
479 | 486 |
packetData[1] = length; |
... | ... | |
487 | 494 |
} |
488 | 495 |
/* still here so a response was received */ |
489 | 496 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
490 |
|
|
497 |
|
|
491 | 498 |
/* check if the reponse was valid */ |
492 | 499 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
493 | 500 |
{ |
... | ... | |
500 | 507 |
printf(" (upload)\n"); |
501 | 508 |
return SB_FALSE; |
502 | 509 |
} |
503 |
|
|
510 |
|
|
504 | 511 |
/* now store the uploaded data */ |
505 | 512 |
for (data_index=0; data_index<length; data_index++) |
506 | 513 |
{ |
507 | 514 |
data[data_index] = responsePacketPtr->data[data_index+1]; |
508 | 515 |
} |
509 |
|
|
510 |
/* still here so all went well */
|
|
516 |
|
|
517 |
/* still here so all went well */ |
|
511 | 518 |
return SB_TRUE; |
512 | 519 |
} /*** end of XcpMasterSendCmdUpload ***/ |
513 | 520 |
|
... | ... | |
534 | 541 |
} |
535 | 542 |
/* still here so a response was received */ |
536 | 543 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
537 |
|
|
544 |
|
|
538 | 545 |
/* check if the reponse was valid */ |
539 | 546 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
540 | 547 |
{ |
... | ... | |
547 | 554 |
printf(" (program start)\n"); |
548 | 555 |
return SB_FALSE; |
549 | 556 |
} |
550 |
|
|
557 |
|
|
551 | 558 |
/* store max number of bytes the slave allows for master->slave packets during the |
552 | 559 |
* programming session |
553 | 560 |
*/ |
554 | 561 |
xcpMaxProgCto = responsePacketPtr->data[3]; |
555 |
|
|
556 |
/* still here so all went well */
|
|
562 |
|
|
563 |
/* still here so all went well */ |
|
557 | 564 |
return SB_TRUE; |
558 | 565 |
} /*** end of XcpMasterSendCmdProgramStart ***/ |
559 | 566 |
|
... | ... | |
579 | 586 |
} |
580 | 587 |
/* still here so a response was received */ |
581 | 588 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
582 |
|
|
589 |
|
|
583 | 590 |
/* check if the reponse was valid */ |
584 | 591 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
585 | 592 |
{ |
586 | 593 |
/* not a valid or positive response */ |
587 | 594 |
return SB_FALSE; |
588 | 595 |
} |
589 |
|
|
590 |
/* still here so all went well */
|
|
596 |
|
|
597 |
/* still here so all went well */ |
|
591 | 598 |
return SB_TRUE; |
592 | 599 |
} /*** end of XcpMasterSendCmdProgramStart ***/ |
593 | 600 |
|
594 | 601 |
|
595 | 602 |
/************************************************************************************//** |
596 |
** \brief Sends the XCP PROGRAM RESET command. Note that this command is a bit
|
|
603 |
** \brief Sends the XCP PROGRAM RESET command. Note that this command is a bit |
|
597 | 604 |
** different as in it does not require a response. |
598 | 605 |
** \return SB_TRUE is successfull, SB_FALSE otherwise. |
599 | 606 |
** |
... | ... | |
626 | 633 |
|
627 | 634 |
// /* still here so a response was received */ |
628 | 635 |
// responsePacketPtr = XcpTransportReadResponsePacket(); |
629 |
//
|
|
636 |
// |
|
630 | 637 |
// /* check if the reponse was valid */ |
631 | 638 |
// printf("response not valid\nlength: %u\nresponse: %i", responsePacketPtr->len, *(responsePacketPtr->data)); |
632 | 639 |
// if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
... | ... | |
635 | 642 |
// return SB_FALSE; |
636 | 643 |
// } |
637 | 644 |
|
638 |
|
|
639 |
/* still here so all went well */
|
|
645 |
|
|
646 |
/* still here so all went well */ |
|
640 | 647 |
return SB_TRUE; |
641 | 648 |
} /*** end of XcpMasterSendCmdProgramReset ***/ |
642 | 649 |
|
... | ... | |
653 | 660 |
sb_uint8 packetData[XCP_MASTER_TX_MAX_DATA]; |
654 | 661 |
tXcpTransportResponsePacket *responsePacketPtr; |
655 | 662 |
sb_uint8 cnt; |
656 |
|
|
663 |
|
|
657 | 664 |
/* verify that this number of bytes actually first in this command */ |
658 | 665 |
assert(length <= (xcpMaxProgCto-2) && (xcpMaxProgCto <= XCP_MASTER_TX_MAX_DATA)); |
659 |
|
|
666 |
|
|
660 | 667 |
/* prepare the command packet */ |
661 | 668 |
packetData[0] = XCP_MASTER_CMD_PROGRAM; |
662 | 669 |
packetData[1] = length; |
... | ... | |
674 | 681 |
} |
675 | 682 |
/* still here so a response was received */ |
676 | 683 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
677 |
|
|
684 |
|
|
678 | 685 |
/* check if the reponse was valid */ |
679 | 686 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
680 | 687 |
{ |
... | ... | |
687 | 694 |
printf(" (program)\n"); |
688 | 695 |
return SB_FALSE; |
689 | 696 |
} |
690 |
|
|
691 |
/* still here so all went well */
|
|
697 |
|
|
698 |
/* still here so all went well */ |
|
692 | 699 |
return SB_TRUE; |
693 | 700 |
} /*** end of XcpMasterSendCmdProgram ***/ |
694 | 701 |
|
... | ... | |
704 | 711 |
sb_uint8 packetData[XCP_MASTER_TX_MAX_DATA]; |
705 | 712 |
tXcpTransportResponsePacket *responsePacketPtr; |
706 | 713 |
sb_uint8 cnt; |
707 |
|
|
714 |
|
|
708 | 715 |
/* verify that this number of bytes actually first in this command */ |
709 | 716 |
assert(xcpMaxProgCto <= XCP_MASTER_TX_MAX_DATA); |
710 |
|
|
717 |
|
|
711 | 718 |
/* prepare the command packet */ |
712 | 719 |
packetData[0] = XCP_MASTER_CMD_PROGRAM_MAX; |
713 | 720 |
for (cnt=0; cnt<(xcpMaxProgCto-1); cnt++) |
... | ... | |
724 | 731 |
} |
725 | 732 |
/* still here so a response was received */ |
726 | 733 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
727 |
|
|
734 |
|
|
728 | 735 |
/* check if the reponse was valid */ |
729 | 736 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
730 | 737 |
{ |
... | ... | |
737 | 744 |
printf(" (program max)\n"); |
738 | 745 |
return SB_FALSE; |
739 | 746 |
} |
740 |
|
|
741 |
/* still here so all went well */
|
|
747 |
|
|
748 |
/* still here so all went well */ |
|
742 | 749 |
return SB_TRUE; |
743 | 750 |
} /*** end of XcpMasterSendCmdProgramMax ***/ |
744 | 751 |
|
... | ... | |
772 | 779 |
} |
773 | 780 |
/* still here so a response was received */ |
774 | 781 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
775 |
|
|
782 |
|
|
776 | 783 |
/* check if the reponse was valid */ |
777 | 784 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
778 | 785 |
{ |
... | ... | |
785 | 792 |
printf(" (program clear)\n"); |
786 | 793 |
return SB_FALSE; |
787 | 794 |
} |
788 |
|
|
789 |
/* still here so all went well */
|
|
795 |
|
|
796 |
/* still here so all went well */ |
|
790 | 797 |
return SB_TRUE; |
791 | 798 |
} /*** end of XcpMasterSendCmdProgramClear ***/ |
792 | 799 |
|
Host/Source/SerialBoot/xcpmaster.h | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
#ifndef XCPMASTER_H |
... | ... | |
58 | 58 |
****************************************************************************************/ |
59 | 59 |
sb_uint8 XcpMasterInit(sb_char *device, sb_uint32 baudrate, sb_uint8 comIsUart); |
60 | 60 |
void XcpMasterDeinit(void); |
61 |
sb_uint8 XcpMasterConnect(sb_uint8 flashingTargetID);
|
|
61 |
sb_uint8 XcpMasterConnect(sb_uint32 flashingTargetID);
|
|
62 | 62 |
sb_uint8 XcpMasterDisconnect(void); |
63 | 63 |
sb_uint8 XcpMasterProgramReset(void); |
64 | 64 |
sb_uint8 XcpMasterStartProgrammingSession(void); |
Target/Modules/DiWheelDrive_1-1/Boot/blt_conf.h | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
#ifndef BLT_CONF_H |
... | ... | |
37 | 37 |
* C P U D R I V E R C O N F I G U R A T I O N |
38 | 38 |
****************************************************************************************/ |
39 | 39 |
/* To properly initialize the baudrate clocks of the communication interface, typically |
40 |
* the speed of the crystal oscillator and/or the speed at which the system runs is
|
|
40 |
* the speed of the crystal oscillator and/or the speed at which the system runs is |
|
41 | 41 |
* needed. Set these through configurables BOOT_CPU_XTAL_SPEED_KHZ and |
42 | 42 |
* BOOT_CPU_SYSTEM_SPEED_KHZ, respectively. To enable data exchange with the host that is |
43 |
* not dependent on the targets architecture, the byte ordering needs to be known.
|
|
44 |
* Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects
|
|
43 |
* not dependent on the targets architecture, the byte ordering needs to be known. |
|
44 |
* Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects |
|
45 | 45 |
* big endian mode. |
46 |
*
|
|
46 |
* |
|
47 | 47 |
* Set BOOT_CPU_USER_PROGRAM_START_HOOK to 1 if you would like a hook function to be |
48 | 48 |
* called the moment the user program is about to be started. This could be used to |
49 | 49 |
* de-initialize application specific parts, for example to stop blinking an LED, etc. |
50 |
*/
|
|
50 |
*/ |
|
51 | 51 |
/** \brief Frequency of the external crystal oscillator. */ |
52 | 52 |
#define BOOT_CPU_XTAL_SPEED_KHZ (8000) |
53 | 53 |
/** \brief Desired system speed. */ |
... | ... | |
66 | 66 |
* have to be controlled by this bootloader. Additionally the bootloader should be able |
67 | 67 |
* to send program code of user programs for other devices. |
68 | 68 |
* Make sure that one of the communication interfaces is the gateway! |
69 |
*/
|
|
69 |
*/ |
|
70 | 70 |
/** \brief Bootloader of main device. */ |
71 | 71 |
#define BOOTLOADER_OF_MAIN_DEVICE (1) |
72 | 72 |
|
... | ... | |
74 | 74 |
/**************************************************************************************** |
75 | 75 |
* C O M M U N I C A T I O N I N T E R F A C E C O N F I G U R A T I O N |
76 | 76 |
****************************************************************************************/ |
77 |
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE
|
|
77 |
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE |
|
78 | 78 |
* configurable to 1. Configurable BOOT_COM_CAN_BAUDRATE selects the communication speed |
79 |
* in bits/second. Two CAN messages are reserved for communication with the host. The
|
|
79 |
* in bits/second. Two CAN messages are reserved for communication with the host. The |
|
80 | 80 |
* message identifier for sending data from the target to the host is configured with |
81 | 81 |
* BOOT_COM_CAN_TXMSG_ID. The one for receiving data from the host is configured with |
82 |
* BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data
|
|
83 |
* transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and
|
|
82 |
* BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data |
|
83 |
* transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and |
|
84 | 84 |
* BOOT_COM_CAN_RX_MAX_DATA, respectively. It is common for a microcontroller to have more |
85 | 85 |
* than 1 CAN controller on board. The zero-based BOOT_COM_CAN_CHANNEL_INDEX selects the |
86 | 86 |
* CAN controller channel. |
87 |
*
|
|
87 |
* |
|
88 | 88 |
*/ |
89 | 89 |
/** \brief Enable/disable CAN transport layer. */ |
90 | 90 |
#define BOOT_GATE_CAN_ENABLE (1) |
91 | 91 |
/** \brief Configure the desired CAN baudrate. */ |
92 |
#define BOOT_COM_CAN_BAUDRATE (500000)
|
|
92 |
#define BOOT_COM_CAN_BAUDRATE (1000000)
|
|
93 | 93 |
/** \brief Configure CAN message ID target->host. */ |
94 |
#define BOOT_COM_CAN_TX_MSG_ID (0x700) //(0x7E1)
|
|
94 |
#define BOOT_COM_CAN_TX_MSG_ID (0x700) |
|
95 | 95 |
/** \brief Configure number of bytes in the target->host CAN message. */ |
96 | 96 |
#define BOOT_COM_CAN_TX_MAX_DATA (255) |
97 | 97 |
/** \brief Configure CAN message ID host->target. */ |
98 |
#define BOOT_COM_CAN_RX_MSG_ID (0x600) //(0x667)
|
|
98 |
#define BOOT_COM_CAN_RX_MSG_ID (0x600) |
|
99 | 99 |
/** \brief Configure number of bytes in the host->target CAN message. */ |
100 | 100 |
#define BOOT_COM_CAN_RX_MAX_DATA (255) |
101 | 101 |
/** \brief Select the desired CAN peripheral as a zero based index. */ |
102 | 102 |
#define BOOT_COM_CAN_CHANNEL_INDEX (0) |
103 |
/** \brief Configure CAN message acknowledgement ID addition (ORed with original ID). */ |
|
104 |
#define BOOT_COM_CAN_MSG_ACK (0x001) |
|
105 |
/** \brief Configure CAN message ID addition for continuous messages (ORed with original ID). */ |
|
106 |
#define BOOT_COM_CAN_MSG_SUBSEQUENT (0x002) |
|
103 | 107 |
|
104 |
/** \brief Configure device ID for communication (start with 1). */ |
|
105 |
#define BOOT_COM_DEVICE_ID (0x1) |
|
108 |
/** |
|
109 |
* \brief Configure device ID for communication (start with 1). |
|
110 |
* \details The device ID is a 32 bit integer, which can be interpreted bytewise: |
|
111 |
* <AMiRo_revision>:<moduleID>:<moduleVersion_major>:<moduleVersion_minor> |
|
112 |
* For this module the according values are |
|
113 |
* 1:0:1:1 = 0x01000101 |
|
114 |
*/ |
|
115 |
#define BOOT_COM_DEVICE_ID (0x01000101) |
|
116 |
/** \brief Configure legacy device ID. */ |
|
117 |
#define BOOT_COM_DEVICE_LEGACY_ID (0x1) |
|
106 | 118 |
|
107 |
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE
|
|
119 |
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE |
|
108 | 120 |
* configurable to 1. Configurable BOOT_COM_UART_BAUDRATE selects the communication speed |
109 |
* in bits/second. The maximum amount of data bytes in a message for data transmission
|
|
110 |
* and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA,
|
|
121 |
* in bits/second. The maximum amount of data bytes in a message for data transmission |
|
122 |
* and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA, |
|
111 | 123 |
* respectively. It is common for a microcontroller to have more than 1 UART interface |
112 | 124 |
* on board. The zero-based BOOT_COM_UART_CHANNEL_INDEX selects the UART interface. |
113 |
*
|
|
125 |
* |
|
114 | 126 |
*/ |
115 | 127 |
/** \brief Enable/disable UART transport layer. */ |
116 | 128 |
#define BOOT_COM_UART_ENABLE (1) |
117 | 129 |
/** \brief Configure the desired communication speed. */ |
118 |
#define BOOT_COM_UART_BAUDRATE (115200) //(57600)
|
|
130 |
#define BOOT_COM_UART_BAUDRATE (115200) |
|
119 | 131 |
/** \brief Configure number of bytes in the target->host data packet. */ |
120 |
#define BOOT_COM_UART_TX_MAX_DATA (255) //(64)
|
|
132 |
#define BOOT_COM_UART_TX_MAX_DATA (255) |
|
121 | 133 |
/** \brief Configure number of bytes in the host->target data packet. */ |
122 |
#define BOOT_COM_UART_RX_MAX_DATA (255) //(64)
|
|
134 |
#define BOOT_COM_UART_RX_MAX_DATA (255) |
|
123 | 135 |
/** \brief Select the desired UART peripheral as a zero based index. */ |
124 | 136 |
#define BOOT_COM_UART_CHANNEL_INDEX (0) |
125 | 137 |
/* Activate debugging with UART2 */ |
... | ... | |
130 | 142 |
* F I L E S Y S T E M I N T E R F A C E C O N F I G U R A T I O N |
131 | 143 |
****************************************************************************************/ |
132 | 144 |
/* The file system interface is selected by setting the BOOT_FILE_SYS_ENABLE configurable |
133 |
* to 1. This enables support for firmware updates from a file stored on a locally
|
|
134 |
* attached file system such as an SD-card. Note that this interface can be enabled
|
|
145 |
* to 1. This enables support for firmware updates from a file stored on a locally |
|
146 |
* attached file system such as an SD-card. Note that this interface can be enabled |
|
135 | 147 |
* together with one of the remote communication interfaces such as UART, CAN or USB. |
136 | 148 |
* |
137 | 149 |
* Set BOOT_FILE_LOGGING_ENABLE to 1 if you would like log messages to be created during |
... | ... | |
145 | 157 |
* additional information on the error cause. |
146 | 158 |
* |
147 | 159 |
* Set BOOT_FILE_STARTED_HOOK_ENABLE to 1 if you would like to be informed when a new |
148 |
* firmware update is started by the bootloader.
|
|
160 |
* firmware update is started by the bootloader. |
|
149 | 161 |
* |
150 | 162 |
* Set BOOT_FILE_COMPLETED_HOOK_ENABLE to 1 if you would like to be informed when a |
151 |
* firmware update is completed by the bootloader.
|
|
163 |
* firmware update is completed by the bootloader. |
|
152 | 164 |
*/ |
153 | 165 |
/** \brief Enable/disable support for firmware updates from a locally attached storage.*/ |
154 | 166 |
#define BOOT_FILE_SYS_ENABLE (0) |
155 | 167 |
/** \brief Enable/disable logging messages during firmware updates. */ |
156 | 168 |
#define BOOT_FILE_LOGGING_ENABLE (1) |
157 | 169 |
/** \brief Enable/disable a hook function that is called upon detection of an error. */ |
158 |
#define BOOT_FILE_ERROR_HOOK_ENABLE (1)
|
|
170 |
#define BOOT_FILE_ERROR_HOOK_ENABLE (1) |
|
159 | 171 |
/** \brief Enable/disable a hook function that is called at the start of the update. */ |
160 |
#define BOOT_FILE_STARTED_HOOK_ENABLE (1)
|
|
172 |
#define BOOT_FILE_STARTED_HOOK_ENABLE (1) |
|
161 | 173 |
/** \brief Enable/disable a hook function that is called at the end of the update. */ |
162 |
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1) |
|
174 |
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1) |
|
175 |
|
|
163 | 176 |
|
164 |
|
|
165 | 177 |
/**************************************************************************************** |
166 | 178 |
* B A C K D O O R E N T R Y C O N F I G U R A T I O N |
167 | 179 |
****************************************************************************************/ |
168 | 180 |
/* It is possible to implement an application specific method to force the bootloader to |
169 | 181 |
* stay active after a reset. Such a backdoor entry into the bootloader is desired in |
170 |
* situations where the user program does not run properly and therefore cannot
|
|
182 |
* situations where the user program does not run properly and therefore cannot |
|
171 | 183 |
* reactivate the bootloader. By enabling these hook functions, the application can |
172 | 184 |
* implement the backdoor, which overrides the default backdoor entry that is programmed |
173 | 185 |
* into the bootloader. When desired for security purposes, these hook functions can |
... | ... | |
213 | 225 |
* S E E D / K E Y S E C U R I T Y C O N F I G U R A T I O N |
214 | 226 |
****************************************************************************************/ |
215 | 227 |
/* A security mechanism can be enabled in the bootloader's XCP module by setting configu- |
216 |
* rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming
|
|
217 |
* operations can be performed, access to this resource need to be unlocked.
|
|
218 |
* In the Microboot settings on tab "XCP Protection" you need to specify a DLL that
|
|
219 |
* implements the unlocking algorithm. The demo programs are configured for the (simple)
|
|
220 |
* algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be
|
|
221 |
* customized to your needs.
|
|
228 |
* rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming |
|
229 |
* operations can be performed, access to this resource need to be unlocked. |
|
230 |
* In the Microboot settings on tab "XCP Protection" you need to specify a DLL that |
|
231 |
* implements the unlocking algorithm. The demo programs are configured for the (simple) |
|
232 |
* algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be |
|
233 |
* customized to your needs. |
|
222 | 234 |
* During the unlock sequence, Microboot requests a seed from the bootloader, which is in |
223 |
* the format of a byte array. Using this seed the unlock algorithm in the DLL computes
|
|
224 |
* a key, which is also a byte array, and sends this back to the bootloader. The
|
|
235 |
* the format of a byte array. Using this seed the unlock algorithm in the DLL computes |
|
236 |
* a key, which is also a byte array, and sends this back to the bootloader. The |
|
225 | 237 |
* bootloader then verifies this key to determine if programming and erase operations are |
226 | 238 |
* permitted. |
227 | 239 |
* After enabling this feature the hook functions XcpGetSeedHook() and XcpVerifyKeyHook() |
Target/Modules/DiWheelDrive_1-1/Boot/main.c | ||
---|---|---|
42 | 42 |
#include "AMiRo/amiroblt.h" |
43 | 43 |
#include "AMiRo/helper.h" |
44 | 44 |
|
45 |
|
|
46 | 45 |
/**************************************************************************************** |
47 | 46 |
* Defines |
48 | 47 |
****************************************************************************************/ |
... | ... | |
170 | 169 |
|
171 | 170 |
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = { |
172 | 171 |
.magicNumber = BL_MAGIC_NUMBER, |
173 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Release, BL_VERSION_MAJOR, BL_VERSION_MINOR, 1},
|
|
172 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Release, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
|
|
174 | 173 |
.vSSSP = {BL_VERSION_ID_SSSP, SSSP_VERSION_MAJOR, SSSP_VERSION_MINOR, 0}, |
175 | 174 |
.vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__}, // currently only GCC is supported |
176 | 175 |
.cbShutdownHibernate = blCallbackShutdownHibernate, |
... | ... | |
797 | 796 |
uint32_t currentTime = loopStartTime; |
798 | 797 |
while (1) |
799 | 798 |
{ |
800 |
/* make the LED "double-blink" */ |
|
801 |
saTimerUpdate(¤tTime); |
|
802 |
if (currentTime < loopStartTime + 50) { |
|
803 |
setLed(BLT_TRUE); |
|
804 |
} else if (currentTime < loopStartTime + 50+100) { |
|
805 |
setLed(BLT_FALSE); |
|
806 |
} else if (currentTime < loopStartTime + 50+100+50) { |
|
807 |
setLed(BLT_TRUE); |
|
808 |
} else if ( currentTime < loopStartTime + 50+100+50+300) { |
|
809 |
setLed(BLT_FALSE); |
|
810 |
} else { |
|
811 |
loopStartTime = currentTime; |
|
812 |
} |
|
799 |
// /* make the LED "double-blink" */
|
|
800 |
// saTimerUpdate(¤tTime);
|
|
801 |
// if (currentTime < loopStartTime + 50) {
|
|
802 |
// setLed(BLT_TRUE);
|
|
803 |
// } else if (currentTime < loopStartTime + 50+100) {
|
|
804 |
// setLed(BLT_FALSE);
|
|
805 |
// } else if (currentTime < loopStartTime + 50+100+50) {
|
|
806 |
// setLed(BLT_TRUE);
|
|
807 |
// } else if ( currentTime < loopStartTime + 50+100+50+300) {
|
|
808 |
// setLed(BLT_FALSE);
|
|
809 |
// } else {
|
|
810 |
// loopStartTime = currentTime;
|
|
811 |
// }
|
|
813 | 812 |
|
814 | 813 |
/* run the bootloader task */ |
815 | 814 |
BootTask(); |
Target/Modules/LightRing_1-0/Boot/blt_conf.h | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
#ifndef BLT_CONF_H |
... | ... | |
37 | 37 |
* C P U D R I V E R C O N F I G U R A T I O N |
38 | 38 |
****************************************************************************************/ |
39 | 39 |
/* To properly initialize the baudrate clocks of the communication interface, typically |
40 |
* the speed of the crystal oscillator and/or the speed at which the system runs is
|
|
40 |
* the speed of the crystal oscillator and/or the speed at which the system runs is |
|
41 | 41 |
* needed. Set these through configurables BOOT_CPU_XTAL_SPEED_KHZ and |
42 | 42 |
* BOOT_CPU_SYSTEM_SPEED_KHZ, respectively. To enable data exchange with the host that is |
43 |
* not dependent on the targets architecture, the byte ordering needs to be known.
|
|
44 |
* Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects
|
|
43 |
* not dependent on the targets architecture, the byte ordering needs to be known. |
|
44 |
* Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects |
|
45 | 45 |
* big endian mode. |
46 |
*
|
|
46 |
* |
|
47 | 47 |
* Set BOOT_CPU_USER_PROGRAM_START_HOOK to 1 if you would like a hook function to be |
48 | 48 |
* called the moment the user program is about to be started. This could be used to |
49 | 49 |
* de-initialize application specific parts, for example to stop blinking an LED, etc. |
50 |
*/
|
|
50 |
*/ |
|
51 | 51 |
/** \brief Frequency of the external crystal oscillator. */ |
52 | 52 |
#define BOOT_CPU_XTAL_SPEED_KHZ (8000) |
53 | 53 |
/** \brief Desired system speed. */ |
... | ... | |
66 | 66 |
* have to be controlled by this bootloader. Additionally the bootloader should be able |
67 | 67 |
* to send program code of user programs for other devices. |
68 | 68 |
* Make sure that one of the communication interfaces is the gateway! |
69 |
*/
|
|
69 |
*/ |
|
70 | 70 |
/** \brief Bootloader of main device. */ |
71 | 71 |
#define BOOTLOADER_OF_MAIN_DEVICE (0) |
72 | 72 |
|
... | ... | |
74 | 74 |
/**************************************************************************************** |
75 | 75 |
* C O M M U N I C A T I O N I N T E R F A C E C O N F I G U R A T I O N |
76 | 76 |
****************************************************************************************/ |
77 |
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE
|
|
77 |
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE |
|
78 | 78 |
* configurable to 1. Configurable BOOT_COM_CAN_BAUDRATE selects the communication speed |
79 |
* in bits/second. Two CAN messages are reserved for communication with the host. The
|
|
79 |
* in bits/second. Two CAN messages are reserved for communication with the host. The |
|
80 | 80 |
* message identifier for sending data from the target to the host is configured with |
81 | 81 |
* BOOT_COM_CAN_TXMSG_ID. The one for receiving data from the host is configured with |
82 |
* BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data
|
|
83 |
* transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and
|
|
82 |
* BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data |
|
83 |
* transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and |
|
84 | 84 |
* BOOT_COM_CAN_RX_MAX_DATA, respectively. It is common for a microcontroller to have more |
85 | 85 |
* than 1 CAN controller on board. The zero-based BOOT_COM_CAN_CHANNEL_INDEX selects the |
86 | 86 |
* CAN controller channel. |
87 |
*
|
|
87 |
* |
|
88 | 88 |
*/ |
89 | 89 |
/** \brief Enable/disable CAN transport layer. */ |
90 | 90 |
#define BOOT_COM_CAN_ENABLE (1) |
91 | 91 |
/** \brief Configure the desired CAN baudrate. */ |
92 |
#define BOOT_COM_CAN_BAUDRATE (500000)
|
|
92 |
#define BOOT_COM_CAN_BAUDRATE (1000000)
|
|
93 | 93 |
/** \brief Configure CAN message ID target->host. */ |
94 |
#define BOOT_COM_CAN_TX_MSG_ID (0x700) //(0x667) //(0x7E1)
|
|
94 |
#define BOOT_COM_CAN_TX_MSG_ID (0x700) |
|
95 | 95 |
/** \brief Configure number of bytes in the target->host CAN message. */ |
96 | 96 |
#define BOOT_COM_CAN_TX_MAX_DATA (255) |
97 | 97 |
/** \brief Configure CAN message ID host->target. */ |
98 |
#define BOOT_COM_CAN_RX_MSG_ID (0x600) //(0x7E1) //(0x667)
|
|
98 |
#define BOOT_COM_CAN_RX_MSG_ID (0x600) |
|
99 | 99 |
/** \brief Configure number of bytes in the host->target CAN message. */ |
100 | 100 |
#define BOOT_COM_CAN_RX_MAX_DATA (255) |
101 | 101 |
/** \brief Select the desired CAN peripheral as a zero based index. */ |
102 | 102 |
#define BOOT_COM_CAN_CHANNEL_INDEX (0) |
103 |
/** \brief Configure CAN message acknowledgement ID addition (ORed with original ID). */ |
|
104 |
#define BOOT_COM_CAN_MSG_ACK (0x001) |
|
105 |
/** \brief Configure CAN message ID addition for continuous messages (ORed with original ID). */ |
|
106 |
#define BOOT_COM_CAN_MSG_SUBSEQUENT (0x002) |
|
107 |
|
|
108 |
/** |
|
109 |
* \brief Configure device ID for communication (start with 1). |
|
110 |
* \details The device ID is a 32 bit integer, which can be interpreted bytewise: |
|
111 |
* <AMiRo_revision>:<moduleID>:<moduleVersion_major>:<moduleVersion_minor> |
|
112 |
* For this module the according values are |
|
113 |
* 1:127:1:0 = 0x017F0100 |
|
114 |
*/ |
|
115 |
#define BOOT_COM_DEVICE_ID (0x017F0100) |
|
116 |
/** \brief Configure legacy device ID. */ |
|
117 |
#define BOOT_COM_DEVICE_LEGACY_ID (0x3) |
|
103 | 118 |
|
104 |
/** \brief Configure device ID for communication (start with 1). */ |
|
105 |
#define BOOT_COM_DEVICE_ID (0x3) |
|
106 | 119 |
|
107 |
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE
|
|
120 |
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE |
|
108 | 121 |
* configurable to 1. Configurable BOOT_COM_UART_BAUDRATE selects the communication speed |
109 |
* in bits/second. The maximum amount of data bytes in a message for data transmission
|
|
110 |
* and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA,
|
|
122 |
* in bits/second. The maximum amount of data bytes in a message for data transmission |
|
123 |
* and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA, |
|
111 | 124 |
* respectively. It is common for a microcontroller to have more than 1 UART interface |
112 | 125 |
* on board. The zero-based BOOT_COM_UART_CHANNEL_INDEX selects the UART interface. |
113 |
*
|
|
126 |
* |
|
114 | 127 |
*/ |
115 | 128 |
/** \brief Enable/disable UART transport layer. */ |
116 | 129 |
#define BOOT_COM_UART_ENABLE (1) |
117 | 130 |
/** \brief Configure the desired communication speed. */ |
118 |
#define BOOT_COM_UART_BAUDRATE (115200) //(57600)
|
|
131 |
#define BOOT_COM_UART_BAUDRATE (115200) |
|
119 | 132 |
/** \brief Configure number of bytes in the target->host data packet. */ |
120 | 133 |
#define BOOT_COM_UART_TX_MAX_DATA (255) |
121 | 134 |
/** \brief Configure number of bytes in the host->target data packet. */ |
... | ... | |
130 | 143 |
* F I L E S Y S T E M I N T E R F A C E C O N F I G U R A T I O N |
131 | 144 |
****************************************************************************************/ |
132 | 145 |
/* The file system interface is selected by setting the BOOT_FILE_SYS_ENABLE configurable |
133 |
* to 1. This enables support for firmware updates from a file stored on a locally
|
|
134 |
* attached file system such as an SD-card. Note that this interface can be enabled
|
|
146 |
* to 1. This enables support for firmware updates from a file stored on a locally |
|
147 |
* attached file system such as an SD-card. Note that this interface can be enabled |
|
135 | 148 |
* together with one of the remote communication interfaces such as UART, CAN or USB. |
136 | 149 |
* |
137 | 150 |
* Set BOOT_FILE_LOGGING_ENABLE to 1 if you would like log messages to be created during |
... | ... | |
145 | 158 |
* additional information on the error cause. |
146 | 159 |
* |
147 | 160 |
* Set BOOT_FILE_STARTED_HOOK_ENABLE to 1 if you would like to be informed when a new |
148 |
* firmware update is started by the bootloader.
|
|
161 |
* firmware update is started by the bootloader. |
|
149 | 162 |
* |
150 | 163 |
* Set BOOT_FILE_COMPLETED_HOOK_ENABLE to 1 if you would like to be informed when a |
151 |
* firmware update is completed by the bootloader.
|
|
164 |
* firmware update is completed by the bootloader. |
|
152 | 165 |
*/ |
153 | 166 |
/** \brief Enable/disable support for firmware updates from a locally attached storage.*/ |
154 | 167 |
#define BOOT_FILE_SYS_ENABLE (0) |
155 | 168 |
/** \brief Enable/disable logging messages during firmware updates. */ |
156 | 169 |
#define BOOT_FILE_LOGGING_ENABLE (1) |
157 | 170 |
/** \brief Enable/disable a hook function that is called upon detection of an error. */ |
158 |
#define BOOT_FILE_ERROR_HOOK_ENABLE (1)
|
|
171 |
#define BOOT_FILE_ERROR_HOOK_ENABLE (1) |
|
159 | 172 |
/** \brief Enable/disable a hook function that is called at the start of the update. */ |
160 |
#define BOOT_FILE_STARTED_HOOK_ENABLE (1)
|
|
173 |
#define BOOT_FILE_STARTED_HOOK_ENABLE (1) |
|
161 | 174 |
/** \brief Enable/disable a hook function that is called at the end of the update. */ |
162 |
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1) |
|
175 |
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1) |
|
176 |
|
|
163 | 177 |
|
164 |
|
|
165 | 178 |
/**************************************************************************************** |
166 | 179 |
* B A C K D O O R E N T R Y C O N F I G U R A T I O N |
167 | 180 |
****************************************************************************************/ |
168 | 181 |
/* It is possible to implement an application specific method to force the bootloader to |
169 | 182 |
* stay active after a reset. Such a backdoor entry into the bootloader is desired in |
170 |
* situations where the user program does not run properly and therefore cannot
|
|
183 |
* situations where the user program does not run properly and therefore cannot |
|
171 | 184 |
* reactivate the bootloader. By enabling these hook functions, the application can |
172 | 185 |
* implement the backdoor, which overrides the default backdoor entry that is programmed |
173 | 186 |
* into the bootloader. When desired for security purposes, these hook functions can |
... | ... | |
213 | 226 |
* S E E D / K E Y S E C U R I T Y C O N F I G U R A T I O N |
214 | 227 |
****************************************************************************************/ |
215 | 228 |
/* A security mechanism can be enabled in the bootloader's XCP module by setting configu- |
216 |
* rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming
|
|
217 |
* operations can be performed, access to this resource need to be unlocked.
|
|
218 |
* In the Microboot settings on tab "XCP Protection" you need to specify a DLL that
|
|
219 |
* implements the unlocking algorithm. The demo programs are configured for the (simple)
|
|
220 |
* algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be
|
|
221 |
* customized to your needs.
|
|
229 |
* rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming |
|
230 |
* operations can be performed, access to this resource need to be unlocked. |
|
231 |
* In the Microboot settings on tab "XCP Protection" you need to specify a DLL that |
|
232 |
* implements the unlocking algorithm. The demo programs are configured for the (simple) |
|
233 |
* algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be |
|
234 |
* customized to your needs. |
|
222 | 235 |
* During the unlock sequence, Microboot requests a seed from the bootloader, which is in |
223 |
* the format of a byte array. Using this seed the unlock algorithm in the DLL computes
|
|
224 |
* a key, which is also a byte array, and sends this back to the bootloader. The
|
|
236 |
* the format of a byte array. Using this seed the unlock algorithm in the DLL computes |
|
237 |
* a key, which is also a byte array, and sends this back to the bootloader. The |
|
225 | 238 |
* bootloader then verifies this key to determine if programming and erase operations are |
226 | 239 |
* permitted. |
227 | 240 |
* After enabling this feature the hook functions XcpGetSeedHook() and XcpVerifyKeyHook() |
Target/Modules/LightRing_1-0/Boot/main.c | ||
---|---|---|
42 | 42 |
#include "AMiRo/amiroblt.h" |
43 | 43 |
#include "AMiRo/helper.h" |
44 | 44 |
|
45 |
|
|
46 | 45 |
/**************************************************************************************** |
47 | 46 |
* Defines |
48 | 47 |
****************************************************************************************/ |
... | ... | |
140 | 139 |
|
141 | 140 |
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = { |
142 | 141 |
.magicNumber = BL_MAGIC_NUMBER, |
143 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Release, BL_VERSION_MAJOR, BL_VERSION_MINOR, 1},
|
|
142 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Release, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
|
|
144 | 143 |
.vSSSP = {BL_VERSION_ID_SSSP, SSSP_VERSION_MAJOR, SSSP_VERSION_MINOR, 0}, |
145 | 144 |
.vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__}, // currently only GCC is supported |
146 | 145 |
.cbShutdownHibernate = blCallbackShutdownHibernate, |
... | ... | |
659 | 658 |
uint32_t currentTime = loopStartTime; |
660 | 659 |
while (1) |
661 | 660 |
{ |
662 |
/* make the pseudo LED "double-blink" */ |
|
663 |
saTimerUpdate(¤tTime); |
|
664 |
if (currentTime < loopStartTime + 50) { |
|
665 |
setLed(BLT_TRUE); |
|
666 |
} else if (currentTime < loopStartTime + 50+100) { |
|
667 |
setLed(BLT_FALSE); |
|
668 |
} else if (currentTime < loopStartTime + 50+100+50) { |
|
669 |
setLed(BLT_TRUE); |
|
670 |
} else if ( currentTime < loopStartTime + 50+100+50+300) { |
|
671 |
setLed(BLT_FALSE); |
|
672 |
} else { |
|
673 |
loopStartTime = currentTime; |
|
674 |
} |
|
661 |
// /* make the pseudo LED "double-blink" */
|
|
662 |
// saTimerUpdate(¤tTime);
|
|
663 |
// if (currentTime < loopStartTime + 50) {
|
|
664 |
// setLed(BLT_TRUE);
|
|
665 |
// } else if (currentTime < loopStartTime + 50+100) {
|
|
666 |
// setLed(BLT_FALSE);
|
|
667 |
// } else if (currentTime < loopStartTime + 50+100+50) {
|
|
668 |
// setLed(BLT_TRUE);
|
|
669 |
// } else if ( currentTime < loopStartTime + 50+100+50+300) {
|
|
670 |
// setLed(BLT_FALSE);
|
|
671 |
// } else {
|
|
672 |
// loopStartTime = currentTime;
|
|
673 |
// }
|
|
675 | 674 |
|
676 | 675 |
/* run the bootloader task */ |
677 | 676 |
BootTask(); |
Target/Modules/PowerManagement_1-1/Boot/blt_conf.h | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
#ifndef BLT_CONF_H |
... | ... | |
37 | 37 |
* C P U D R I V E R C O N F I G U R A T I O N |
38 | 38 |
****************************************************************************************/ |
39 | 39 |
/* To properly initialize the baudrate clocks of the communication interface, typically |
40 |
* the speed of the crystal oscillator and/or the speed at which the system runs is
|
|
40 |
* the speed of the crystal oscillator and/or the speed at which the system runs is |
|
41 | 41 |
* needed. Set these through configurables BOOT_CPU_XTAL_SPEED_KHZ and |
42 | 42 |
* BOOT_CPU_SYSTEM_SPEED_KHZ, respectively. To enable data exchange with the host that is |
43 |
* not dependent on the targets architecture, the byte ordering needs to be known.
|
|
44 |
* Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects
|
|
43 |
* not dependent on the targets architecture, the byte ordering needs to be known. |
|
44 |
* Setting BOOT_CPU_BYTE_ORDER_MOTOROLA to 1 selects little endian mode and 0 selects |
|
45 | 45 |
* big endian mode. |
46 |
*
|
|
46 |
* |
|
47 | 47 |
* Set BOOT_CPU_USER_PROGRAM_START_HOOK to 1 if you would like a hook function to be |
48 | 48 |
* called the moment the user program is about to be started. This could be used to |
49 | 49 |
* de-initialize application specific parts, for example to stop blinking an LED, etc. |
50 |
*/
|
|
50 |
*/ |
|
51 | 51 |
/** \brief Frequency of the external crystal oscillator. */ |
52 | 52 |
#define BOOT_CPU_XTAL_SPEED_KHZ (8000) |
53 | 53 |
/** \brief Desired system speed. */ |
... | ... | |
66 | 66 |
* have to be controlled by this bootloader. Additionally the bootloader should be able |
67 | 67 |
* to send program code of user programs for other devices. |
68 | 68 |
* Make sure that one of the communication interfaces is the gateway! |
69 |
*/
|
|
69 |
*/ |
|
70 | 70 |
/** \brief Bootloader of main device. */ |
71 | 71 |
#define BOOTLOADER_OF_MAIN_DEVICE (1) |
72 | 72 |
|
... | ... | |
74 | 74 |
/**************************************************************************************** |
75 | 75 |
* C O M M U N I C A T I O N I N T E R F A C E C O N F I G U R A T I O N |
76 | 76 |
****************************************************************************************/ |
77 |
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE
|
|
77 |
/* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE |
|
78 | 78 |
* configurable to 1. Configurable BOOT_COM_CAN_BAUDRATE selects the communication speed |
79 |
* in bits/second. Two CAN messages are reserved for communication with the host. The
|
|
79 |
* in bits/second. Two CAN messages are reserved for communication with the host. The |
|
80 | 80 |
* message identifier for sending data from the target to the host is configured with |
81 | 81 |
* BOOT_COM_CAN_TXMSG_ID. The one for receiving data from the host is configured with |
82 |
* BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data
|
|
83 |
* transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and
|
|
82 |
* BOOT_COM_CAN_RXMSG_ID. The maximum amount of data bytes in a message for data |
|
83 |
* transmission and reception is set through BOOT_COM_CAN_TX_MAX_DATA and |
|
84 | 84 |
* BOOT_COM_CAN_RX_MAX_DATA, respectively. It is common for a microcontroller to have more |
85 | 85 |
* than 1 CAN controller on board. The zero-based BOOT_COM_CAN_CHANNEL_INDEX selects the |
86 | 86 |
* CAN controller channel. |
87 |
*
|
|
87 |
* |
|
88 | 88 |
*/ |
89 | 89 |
/** \brief Enable/disable CAN transport layer. */ |
90 | 90 |
#define BOOT_GATE_CAN_ENABLE (1) |
91 | 91 |
/** \brief Configure the desired CAN baudrate. */ |
92 |
#define BOOT_COM_CAN_BAUDRATE (500000)
|
|
92 |
#define BOOT_COM_CAN_BAUDRATE (1000000)
|
|
93 | 93 |
/** \brief Configure CAN message ID target->host. */ |
94 | 94 |
#define BOOT_COM_CAN_TX_MSG_ID (0x700) |
95 | 95 |
/** \brief Configure number of bytes in the target->host CAN message. */ |
... | ... | |
100 | 100 |
#define BOOT_COM_CAN_RX_MAX_DATA (255) |
101 | 101 |
/** \brief Select the desired CAN peripheral as a zero based index. */ |
102 | 102 |
#define BOOT_COM_CAN_CHANNEL_INDEX (0) |
103 |
/** \brief Configure CAN message acknowledgement ID addition (ORed with original ID). */ |
|
104 |
#define BOOT_COM_CAN_MSG_ACK (0x001) |
|
105 |
/** \brief Configure CAN message ID addition for continuous messages (ORed with original ID). */ |
|
106 |
#define BOOT_COM_CAN_MSG_SUBSEQUENT (0x002) |
|
107 |
|
|
108 |
/** |
|
109 |
* \brief Configure device ID for communication (start with 1). |
|
110 |
* \details The device ID is a 32 bit integer, which can be interpreted bytewise: |
|
111 |
* <AMiRo_revision>:<moduleID>:<moduleVersion_major>:<moduleVersion_minor> |
|
112 |
* For this module the according values are |
|
113 |
* 1:1:1:1 = 0x01010101 |
|
114 |
*/ |
|
115 |
#define BOOT_COM_DEVICE_ID (0x01010101) |
|
116 |
/** \brief Configure legacy device ID. */ |
|
117 |
#define BOOT_COM_DEVICE_LEGACY_ID (0x2) |
|
103 | 118 |
|
104 |
/** \brief Configure device ID for communication (start with 1). */ |
|
105 |
#define BOOT_COM_DEVICE_ID (0x2) |
|
106 | 119 |
|
107 |
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE
|
|
120 |
/* The UART communication interface is selected by setting the BOOT_COM_UART_ENABLE |
|
108 | 121 |
* configurable to 1. Configurable BOOT_COM_UART_BAUDRATE selects the communication speed |
109 |
* in bits/second. The maximum amount of data bytes in a message for data transmission
|
|
110 |
* and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA,
|
|
122 |
* in bits/second. The maximum amount of data bytes in a message for data transmission |
|
123 |
* and reception is set through BOOT_COM_UART_TX_MAX_DATA and BOOT_COM_UART_RX_MAX_DATA, |
|
111 | 124 |
* respectively. It is common for a microcontroller to have more than 1 UART interface |
112 | 125 |
* on board. The zero-based BOOT_COM_UART_CHANNEL_INDEX selects the UART interface. |
113 |
*
|
|
126 |
* |
|
114 | 127 |
*/ |
115 | 128 |
/** \brief Enable/disable UART transport layer. */ |
116 | 129 |
#define BOOT_COM_UART_ENABLE (1) |
... | ... | |
129 | 142 |
|
130 | 143 |
|
131 | 144 |
/* The NET communication interface for firmware updates via TCP/IP is selected by setting |
132 |
* the BOOT_COM_NET_ENABLE configurable to 1. The maximum amount of data bytes in a
|
|
133 |
* message for data transmission and reception is set through BOOT_COM_NET_TX_MAX_DATA
|
|
134 |
* and BOOT_COM_NET_RX_MAX_DATA, respectively. The default IP address is configured
|
|
145 |
* the BOOT_COM_NET_ENABLE configurable to 1. The maximum amount of data bytes in a |
|
146 |
* message for data transmission and reception is set through BOOT_COM_NET_TX_MAX_DATA |
|
147 |
* and BOOT_COM_NET_RX_MAX_DATA, respectively. The default IP address is configured |
|
135 | 148 |
* with the macros BOOT_COM_NET_IPADDRx. The default netmask is configued with the macros |
136 | 149 |
* BOOT_COM_NET_NETMASKx. The default gateway is configured with the macros |
137 | 150 |
* BOOT_COM_NET_GATEWAYx. The bootloader acts and a TCP/IP server. The port the server |
... | ... | |
177 | 190 |
* to be set. This allows a dynamic override of the BOOT_COM_NET_NETMASKx values. |
178 | 191 |
*/ |
179 | 192 |
#define BOOT_COM_NET_NETMASK_HOOK_ENABLE (0) |
180 |
/** \brief Enable/disable a hook function that is called when the gateway address is
|
|
181 |
* about to be set. This allows a dynamic override of the BOOT_COM_NET_GATEWAYx
|
|
193 |
/** \brief Enable/disable a hook function that is called when the gateway address is |
|
194 |
* about to be set. This allows a dynamic override of the BOOT_COM_NET_GATEWAYx |
|
182 | 195 |
* values. |
183 | 196 |
*/ |
184 | 197 |
#define BOOT_COM_NET_GATEWAY_HOOK_ENABLE (0) |
... | ... | |
190 | 203 |
#if (BOOT_COM_NET_ENABLE > 0) |
191 | 204 |
/* Override the default time that the backdoor is open if firmware updates via TCP/IP |
192 | 205 |
* are supported. in this case a reactivation of the bootloader results in a re- |
193 |
* initialization of the ethernet MAC. when directly connected to the ethernet port of
|
|
194 |
* a PC this will go relatively fast (depending on what MS Windows is being used), but
|
|
206 |
* initialization of the ethernet MAC. when directly connected to the ethernet port of |
|
207 |
* a PC this will go relatively fast (depending on what MS Windows is being used), but |
|
195 | 208 |
* when connected to the network via a router this can take several seconds. feel free to |
196 |
* shorten/lengthen this time for finetuning. the only downside of a long backdoor open
|
|
209 |
* shorten/lengthen this time for finetuning. the only downside of a long backdoor open |
|
197 | 210 |
* time is that the starting of the user program will also be delayed for this time. |
198 | 211 |
* |
199 |
* Also note that when the target is directly connected to the ethernet port of a PC,
|
|
200 |
* the checkbox "Automatically retry socket connection" should be checked in the
|
|
212 |
* Also note that when the target is directly connected to the ethernet port of a PC, |
|
213 |
* the checkbox "Automatically retry socket connection" should be checked in the |
|
201 | 214 |
* Microboot settings. if connecting via a router the uncheck this checkbox. |
202 | 215 |
*/ |
203 | 216 |
#define BACKDOOR_ENTRY_TIMEOUT_MS (10000) |
... | ... | |
208 | 221 |
* F I L E S Y S T E M I N T E R F A C E C O N F I G U R A T I O N |
209 | 222 |
****************************************************************************************/ |
210 | 223 |
/* The file system interface is selected by setting the BOOT_FILE_SYS_ENABLE configurable |
211 |
* to 1. This enables support for firmware updates from a file stored on a locally
|
|
212 |
* attached file system such as an SD-card. Note that this interface can be enabled
|
|
224 |
* to 1. This enables support for firmware updates from a file stored on a locally |
|
225 |
* attached file system such as an SD-card. Note that this interface can be enabled |
|
213 | 226 |
* together with one of the remote communication interfaces such as UART, CAN or USB. |
214 | 227 |
* |
215 | 228 |
* Set BOOT_FILE_LOGGING_ENABLE to 1 if you would like log messages to be created during |
... | ... | |
223 | 236 |
* additional information on the error cause. |
224 | 237 |
* |
225 | 238 |
* Set BOOT_FILE_STARTED_HOOK_ENABLE to 1 if you would like to be informed when a new |
226 |
* firmware update is started by the bootloader.
|
|
239 |
* firmware update is started by the bootloader. |
|
227 | 240 |
* |
228 | 241 |
* Set BOOT_FILE_COMPLETED_HOOK_ENABLE to 1 if you would like to be informed when a |
229 |
* firmware update is completed by the bootloader.
|
|
242 |
* firmware update is completed by the bootloader. |
|
230 | 243 |
*/ |
231 | 244 |
/** \brief Enable/disable support for firmware updates from a locally attached storage.*/ |
232 | 245 |
#define BOOT_FILE_SYS_ENABLE (0) |
233 | 246 |
/** \brief Enable/disable logging messages during firmware updates. */ |
234 | 247 |
#define BOOT_FILE_LOGGING_ENABLE (1) |
235 | 248 |
/** \brief Enable/disable a hook function that is called upon detection of an error. */ |
236 |
#define BOOT_FILE_ERROR_HOOK_ENABLE (1)
|
|
249 |
#define BOOT_FILE_ERROR_HOOK_ENABLE (1) |
|
237 | 250 |
/** \brief Enable/disable a hook function that is called at the start of the update. */ |
238 |
#define BOOT_FILE_STARTED_HOOK_ENABLE (1)
|
|
251 |
#define BOOT_FILE_STARTED_HOOK_ENABLE (1) |
|
239 | 252 |
/** \brief Enable/disable a hook function that is called at the end of the update. */ |
240 |
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1) |
|
253 |
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1) |
|
254 |
|
|
241 | 255 |
|
242 |
|
|
243 | 256 |
/**************************************************************************************** |
244 | 257 |
* B A C K D O O R E N T R Y C O N F I G U R A T I O N |
245 | 258 |
****************************************************************************************/ |
246 | 259 |
/* It is possible to implement an application specific method to force the bootloader to |
247 | 260 |
* stay active after a reset. Such a backdoor entry into the bootloader is desired in |
248 |
* situations where the user program does not run properly and therefore cannot
|
|
261 |
* situations where the user program does not run properly and therefore cannot |
|
249 | 262 |
* reactivate the bootloader. By enabling these hook functions, the application can |
250 | 263 |
* implement the backdoor, which overrides the default backdoor entry that is programmed |
251 | 264 |
* into the bootloader. When desired for security purposes, these hook functions can |
... | ... | |
291 | 304 |
* S E E D / K E Y S E C U R I T Y C O N F I G U R A T I O N |
292 | 305 |
****************************************************************************************/ |
293 | 306 |
/* A security mechanism can be enabled in the bootloader's XCP module by setting configu- |
294 |
* rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming
|
|
295 |
* operations can be performed, access to this resource need to be unlocked.
|
|
296 |
* In the Microboot settings on tab "XCP Protection" you need to specify a DLL that
|
|
297 |
* implements the unlocking algorithm. The demo programs are configured for the (simple)
|
|
298 |
* algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be
|
|
299 |
* customized to your needs.
|
|
307 |
* rable BOOT_XCP_SEED_KEY_ENABLE to 1. Before any memory erase or programming |
|
308 |
* operations can be performed, access to this resource need to be unlocked. |
|
309 |
* In the Microboot settings on tab "XCP Protection" you need to specify a DLL that |
|
310 |
* implements the unlocking algorithm. The demo programs are configured for the (simple) |
|
311 |
* algorithm in "FeaserKey.dll". The source code for this DLL is available so it can be |
|
312 |
* customized to your needs. |
|
300 | 313 |
* During the unlock sequence, Microboot requests a seed from the bootloader, which is in |
301 |
* the format of a byte array. Using this seed the unlock algorithm in the DLL computes
|
|
302 |
* a key, which is also a byte array, and sends this back to the bootloader. The
|
|
314 |
* the format of a byte array. Using this seed the unlock algorithm in the DLL computes |
|
315 |
* a key, which is also a byte array, and sends this back to the bootloader. The |
|
303 | 316 |
* bootloader then verifies this key to determine if programming and erase operations are |
304 | 317 |
* permitted. |
305 | 318 |
* After enabling this feature the hook functions XcpGetSeedHook() and XcpVerifyKeyHook() |
Target/Modules/PowerManagement_1-1/Boot/main.c | ||
---|---|---|
193 | 193 |
|
194 | 194 |
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = { |
195 | 195 |
.magicNumber = BL_MAGIC_NUMBER, |
196 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Release, BL_VERSION_MAJOR, BL_VERSION_MINOR, 1},
|
|
196 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Release, BL_VERSION_MAJOR, BL_VERSION_MINOR, 0},
|
|
197 | 197 |
.vSSSP = {BL_VERSION_ID_SSSP, SSSP_VERSION_MAJOR, SSSP_VERSION_MINOR, 0}, |
198 | 198 |
.vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__}, // currently only GCC is supported |
199 | 199 |
.cbShutdownHibernate = blCallbackShutdownHibernate, |
... | ... | |
893 | 893 |
uint32_t currentTime = loopStartTime; |
894 | 894 |
while (1) |
895 | 895 |
{ |
896 |
/* make the LED "double-blink" */ |
|
897 |
saTimerUpdate(¤tTime); |
|
898 |
if (currentTime < loopStartTime + 50) { |
|
899 |
setLed(BLT_TRUE); |
|
900 |
} else if (currentTime < loopStartTime + 50+100) { |
|
901 |
setLed(BLT_FALSE); |
|
902 |
} else if (currentTime < loopStartTime + 50+100+50) { |
|
903 |
setLed(BLT_TRUE); |
|
904 |
} else if (currentTime < loopStartTime + 50+100+50+300) { |
|
905 |
setLed(BLT_FALSE); |
|
906 |
} else { |
|
907 |
loopStartTime = currentTime; |
|
908 |
} |
|
896 |
// /* make the LED "double-blink" */
|
|
897 |
// saTimerUpdate(¤tTime);
|
|
898 |
// if (currentTime < loopStartTime + 50) {
|
|
899 |
// setLed(BLT_TRUE);
|
|
900 |
// } else if (currentTime < loopStartTime + 50+100) {
|
|
901 |
// setLed(BLT_FALSE);
|
|
902 |
// } else if (currentTime < loopStartTime + 50+100+50) {
|
|
903 |
// setLed(BLT_TRUE);
|
|
904 |
// } else if (currentTime < loopStartTime + 50+100+50+300) {
|
|
905 |
// setLed(BLT_FALSE);
|
|
906 |
// } else {
|
|
907 |
// loopStartTime = currentTime;
|
|
908 |
// }
|
|
909 | 909 |
|
910 | 910 |
/* run the bootloader task */ |
911 | 911 |
BootTask(); |
Target/Source/AMiRo/amiroblt.h | ||
---|---|---|
50 | 50 |
/** |
51 | 51 |
* @brief The minor version number of the bootloader. |
52 | 52 |
*/ |
53 |
#define BL_VERSION_MINOR 0
|
|
53 |
#define BL_VERSION_MINOR 1
|
|
54 | 54 |
|
55 | 55 |
/** |
56 | 56 |
* @brief The major version number of the implemented SSSP (Startup & Shutdown Synchronization Protocol). |
Target/Source/AMiRo/helper.c | ||
---|---|---|
333 | 333 |
saTimerUpdate(&stateStartTime); |
334 | 334 |
uint32_t currentTime = stateStartTime; |
335 | 335 |
|
336 |
/* return immediately if the number of bytes is zero */ |
|
337 |
if (bytes == 0) { |
|
338 |
return; |
|
339 |
} |
|
340 |
|
|
336 | 341 |
/* either loop the specified number, or infinetly */ |
337 | 342 |
while (loop < loops || loops == 0) { |
338 | 343 |
led = 0; |
Target/Source/ARMCM3_STM32/can.c | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
|
34 |
#define CAN_DEBUG (0) |
|
34 | 35 |
|
35 | 36 |
/**************************************************************************************** |
36 | 37 |
* Include files |
37 | 38 |
****************************************************************************************/ |
38 | 39 |
#include "boot.h" /* bootloader generic header */ |
39 | 40 |
|
41 |
#if (CAN_DEBUG > 0) |
|
42 |
#include <helper.h> |
|
43 |
#endif |
|
44 |
|
|
40 | 45 |
|
41 | 46 |
#if (BOOT_COM_CAN_ENABLE > 0 || BOOT_GATE_CAN_ENABLE > 0) |
42 | 47 |
/**************************************************************************************** |
... | ... | |
58 | 63 |
volatile blt_int32u RDTR; |
59 | 64 |
volatile blt_int32u RDLR; |
60 | 65 |
volatile blt_int32u RDHR; |
61 |
} tCanRxFIFOMailBox;
|
|
66 |
} tCanRxFIFOMailBox; |
|
62 | 67 |
|
63 | 68 |
/** \brief CAN filter register layout. */ |
64 | 69 |
typedef struct |
... | ... | |
92 | 97 |
volatile blt_int32u FA1R; |
93 | 98 |
blt_int32u RESERVED5[8]; |
94 | 99 |
tCanFilter sFilterRegister[14]; |
95 |
} tCanRegs;
|
|
100 |
} tCanRegs; |
|
96 | 101 |
|
97 | 102 |
|
98 | 103 |
/**************************************************************************************** |
... | ... | |
144 | 149 |
* Local constant declarations |
145 | 150 |
****************************************************************************************/ |
146 | 151 |
/** \brief CAN bittiming table for dynamically calculating the bittiming settings. |
147 |
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
|
|
148 |
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
|
|
149 |
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
|
|
152 |
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25 |
|
153 |
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC |
|
154 |
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) * |
|
150 | 155 |
* 100%. This array contains possible and valid time quanta configurations with |
151 | 156 |
* a sample point between 68..78%. |
152 | 157 |
*/ |
... | ... | |
175 | 180 |
|
176 | 181 |
|
177 | 182 |
/************************************************************************************//** |
178 |
** \brief Search algorithm to match the desired baudrate to a possible bus
|
|
183 |
** \brief Search algorithm to match the desired baudrate to a possible bus |
|
179 | 184 |
** timing configuration. |
180 | 185 |
** \param baud The desired baudrate in kbps. Valid values are 10..1000. |
181 | 186 |
** \param prescaler Pointer to where the value for the prescaler will be stored. |
182 | 187 |
** \param tseg1 Pointer to where the value for TSEG2 will be stored. |
183 | 188 |
** \param tseg2 Pointer to where the value for TSEG2 will be stored. |
184 |
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
|
|
189 |
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE |
|
185 | 190 |
** otherwise. |
186 | 191 |
** |
187 | 192 |
****************************************************************************************/ |
188 |
static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
|
|
193 |
static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler, |
|
189 | 194 |
blt_int8u *tseg1, blt_int8u *tseg2) |
190 | 195 |
{ |
191 | 196 |
blt_int8u cnt; |
... | ... | |
229 | 234 |
commandSend = BLT_FALSE; |
230 | 235 |
#endif /* BOOT_GATE_CAN_ENABLE > 0 */ |
231 | 236 |
|
232 |
/* the current implementation supports CAN1. throw an assertion error in case a
|
|
233 |
* different CAN channel is configured.
|
|
237 |
/* the current implementation supports CAN1. throw an assertion error in case a |
|
238 |
* different CAN channel is configured. |
|
234 | 239 |
*/ |
235 |
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
|
|
240 |
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0); |
|
236 | 241 |
/* obtain bittiming configuration information */ |
237 | 242 |
result = CanGetSpeedConfig(BOOT_COM_CAN_BAUDRATE/1000, &prescaler, &tseg1, &tseg2); |
238 | 243 |
ASSERT_RT(result == BLT_TRUE); |
... | ... | |
275 | 280 |
/* 32-bit scale for the filter */ |
276 | 281 |
CANx->FS1R |= CAN_BIT_FILTER0; |
277 | 282 |
/* open up the acceptance filter to receive all messages */ |
278 |
CANx->sFilterRegister[0].FR1 = 0;
|
|
279 |
CANx->sFilterRegister[0].FR2 = 0;
|
|
283 |
CANx->sFilterRegister[0].FR1 = 0; |
|
284 |
CANx->sFilterRegister[0].FR2 = 0; |
|
280 | 285 |
/* select id/mask mode for the filter */ |
281 | 286 |
CANx->FM1R &= ~CAN_BIT_FILTER0; |
282 | 287 |
/* FIFO 0 assignation for the filter */ |
... | ... | |
296 | 301 |
** \return none. |
297 | 302 |
** |
298 | 303 |
****************************************************************************************/ |
299 |
void CanTransmitPacket(blt_int8u *data, blt_int8u len, blt_int8u deviceID)
|
|
304 |
void CanTransmitPacket(blt_int8u *data, blt_int8u len, blt_int32u deviceID)
|
|
300 | 305 |
{ |
301 | 306 |
/* make sure that transmit mailbox 0 is available */ |
302 | 307 |
ASSERT_RT((CANx->TSR&CAN_BIT_TME0) == CAN_BIT_TME0); |
303 |
/* build the message identifier */ |
|
304 |
CANx->sTxMailBox[0].TIR &= CAN_BIT_TXRQ; |
|
305 | 308 |
|
306 | 309 |
blt_int32u address; |
307 | 310 |
#if (BOOT_GATE_CAN_ENABLE > 0) |
... | ... | |
311 | 314 |
#if (BOOT_GATE_CAN_ENABLE > 0) |
312 | 315 |
commandSend = BLT_FALSE; |
Also available in: Unified diff