Revision d54d2f07 Target/Source/xcp.c
| Target/Source/xcp.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 |
|
| ... | ... | |
| 36 | 36 |
****************************************************************************************/ |
| 37 | 37 |
#include "boot.h" /* bootloader generic header */ |
| 38 | 38 |
|
| 39 |
#include <helper.h> |
|
| 39 | 40 |
|
| 40 | 41 |
/**************************************************************************************** |
| 41 | 42 |
* Defines |
| ... | ... | |
| 49 | 50 |
/* XCP packet identifiers */ |
| 50 | 51 |
/** \brief Command response packet identifier. */ |
| 51 | 52 |
#define XCP_PID_RES (0xff) |
| 52 |
/** \brief Error packet identifier. */
|
|
| 53 |
/** \brief Error packet identifier. */ |
|
| 53 | 54 |
#define XCP_PID_ERR (0xfe) |
| 54 | 55 |
|
| 55 | 56 |
/* XCP error codes */ |
| ... | ... | |
| 123 | 124 |
{
|
| 124 | 125 |
blt_int8u connected; /**< connection established */ |
| 125 | 126 |
#if (BOOT_GATE_ENABLE > 0) |
| 126 |
blt_int8u other_connection; /**< connection to other device established */
|
|
| 127 |
blt_int32u other_connection; /**< connection to other device established */
|
|
| 127 | 128 |
#endif |
| 128 | 129 |
#if (BOOTLOADER_OF_MAIN_DEVICE > 0) |
| 129 | 130 |
blt_bool wasMainConnection; /**< connection to serialboot (0x00) established */ |
| ... | ... | |
| 149 | 150 |
#endif /* BOOT_GATE_ENABLE > 0 */ |
| 150 | 151 |
|
| 151 | 152 |
/* application specific functions */ |
| 152 |
static blt_int8u XcpComputeChecksum(blt_int32u address, blt_int32u length,
|
|
| 153 |
static blt_int8u XcpComputeChecksum(blt_int32u address, blt_int32u length, |
|
| 153 | 154 |
blt_int32u *checksum); |
| 154 | 155 |
|
| 155 | 156 |
#if (XCP_SEED_KEY_PROTECTION_EN == 1) |
| ... | ... | |
| 217 | 218 |
* External functions |
| 218 | 219 |
****************************************************************************************/ |
| 219 | 220 |
#if (BOOT_COM_ENABLE == 0) |
| 220 |
/* in case no internally supported communication interface is used, a custom
|
|
| 221 |
/* in case no internally supported communication interface is used, a custom |
|
| 221 | 222 |
* communication module can be added. In order to use the XCP protocol in the custom |
| 222 | 223 |
* communication module, this hook function needs to be implemented. In the XCP protocol |
| 223 | 224 |
* is not needed, then simply remove the xcp.c source from the project. |
| ... | ... | |
| 296 | 297 |
|
| 297 | 298 |
|
| 298 | 299 |
/************************************************************************************//** |
| 299 |
** \brief Informs the core that a pending packet transmission was completed by
|
|
| 300 |
** \brief Informs the core that a pending packet transmission was completed by |
|
| 300 | 301 |
** the transport layer. |
| 301 | 302 |
** \return none |
| 302 | 303 |
** |
| ... | ... | |
| 454 | 455 |
****************************************************************************************/ |
| 455 | 456 |
void XcpPacketReceivedForwarding(blt_int8u *data, blt_int16s dataLength) {
|
| 456 | 457 |
/* save id of connected device */ |
| 457 |
blt_int8u connectionTo = xcpInfo.other_connection;
|
|
| 458 |
blt_int32u connectionTo = xcpInfo.other_connection;
|
|
| 458 | 459 |
|
| 459 | 460 |
/* proof commands */ |
| 460 | 461 |
switch (data[0]) {
|
| ... | ... | |
| 464 | 465 |
case XCP_CMD_DISCONNECT: |
| 465 | 466 |
xcpInfo.other_connection = 0; |
| 466 | 467 |
xcpInfo.connected = 0; |
| 468 |
setLed(0); |
|
| 467 | 469 |
break; |
| 468 | 470 |
/* if there is a reset command, it has to be handled like a disconnection |
| 469 | 471 |
* (above) because other devices shouldn't get the ability to reset |
| ... | ... | |
| 472 | 474 |
case XCP_CMD_PROGRAM_RESET: |
| 473 | 475 |
xcpInfo.other_connection = 0; |
| 474 | 476 |
xcpInfo.connected = 0; |
| 477 |
setLed(0); |
|
| 475 | 478 |
data[0] = XCP_CMD_DISCONNECT; |
| 476 | 479 |
break; |
| 477 | 480 |
default: |
| ... | ... | |
| 535 | 538 |
#else |
| 536 | 539 |
ComTransmitPacket(data, len); |
| 537 | 540 |
#endif |
| 538 |
|
|
| 541 |
|
|
| 539 | 542 |
} /*** end of XcpTransmitPacket ***/ |
| 540 | 543 |
|
| 541 | 544 |
|
| ... | ... | |
| 568 | 571 |
|
| 569 | 572 |
#if (XCP_SEED_KEY_PROTECTION_EN == 1) |
| 570 | 573 |
/************************************************************************************//** |
| 571 |
** \brief Provides a seed to the XCP master that will be used for the key
|
|
| 572 |
** generation when the master attempts to unlock the specified resource.
|
|
| 574 |
** \brief Provides a seed to the XCP master that will be used for the key |
|
| 575 |
** generation when the master attempts to unlock the specified resource. |
|
| 573 | 576 |
** Called by the GET_SEED command. |
| 574 | 577 |
** \param resource Resource that the seed if requested for (XCP_RES_XXX). |
| 575 | 578 |
** \param seed Pointer to byte buffer wher the seed will be stored. |
| ... | ... | |
| 584 | 587 |
|
| 585 | 588 |
|
| 586 | 589 |
/************************************************************************************//** |
| 587 |
** \brief Called by the UNLOCK command and checks if the key to unlock the
|
|
| 588 |
** specified resource was correct. If so, then the resource protection
|
|
| 590 |
** \brief Called by the UNLOCK command and checks if the key to unlock the |
|
| 591 |
** specified resource was correct. If so, then the resource protection |
|
| 589 | 592 |
** will be removed. |
| 590 | 593 |
** \param resource resource to unlock (XCP_RES_XXX). |
| 591 | 594 |
** \param key pointer to the byte buffer holding the key. |
| ... | ... | |
| 671 | 674 |
XcpSetCtoError(XCP_ERR_CMD_BUSY); |
| 672 | 675 |
return; |
| 673 | 676 |
} |
| 674 |
#endif
|
|
| 675 |
|
|
| 677 |
#endif |
|
| 678 |
|
|
| 676 | 679 |
// #if (XCP_CONNECT_MODE_HOOK_EN == 1) |
| 677 | 680 |
// /* pass on the mode to a application specific hook function. This function can determine |
| 678 | 681 |
// * is the mode is supported or not. A return value of BLT_FALSE causes the CONNECT command |
| ... | ... | |
| 690 | 693 |
/* enable resource protection */ |
| 691 | 694 |
XcpProtectResources(); |
| 692 | 695 |
|
| 696 |
/* extract the device ID. |
|
| 697 |
* NOTE: For legacy support the following code depends on the data length. |
|
| 698 |
* If two bytes were received the system switches to legacy mode. |
|
| 699 |
* In legacy mode, the device ID was only one byte. |
|
| 700 |
*/ |
|
| 701 |
blt_int32u deviceID; |
|
| 702 |
if (dataLength == 2) {
|
|
| 703 |
deviceID = ((blt_int32u)0 << 24) | \ |
|
| 704 |
((blt_int32u)0 << 16) | \ |
|
| 705 |
((blt_int32u)0 << 8) | \ |
|
| 706 |
((blt_int32u)data[1]); |
|
| 707 |
} else if (dataLength == 5) {
|
|
| 708 |
deviceID = ((blt_int32u)data[4] << 24) | \ |
|
| 709 |
((blt_int32u)data[3] << 16) | \ |
|
| 710 |
((blt_int32u)data[2] << 8) | \ |
|
| 711 |
((blt_int32u)data[1]); |
|
| 712 |
} else {
|
|
| 713 |
blinkSOSinf(); |
|
| 714 |
} |
|
| 693 | 715 |
/* indicate that the connection is established */ |
| 694 | 716 |
#if (BOOT_GATE_ENABLE > 0) |
| 695 |
if (data[1] == 0x00 || data[1] == BOOT_COM_DEVICE_ID) {
|
|
| 717 |
if (deviceID == 0 || |
|
| 718 |
deviceID == (blt_int32u)BOOT_COM_DEVICE_ID || |
|
| 719 |
deviceID == (blt_int32u)BOOT_COM_DEVICE_LEGACY_ID) {
|
|
| 696 | 720 |
#endif |
| 697 | 721 |
xcpInfo.connected = 1; |
| 722 |
setLed(1); |
|
| 698 | 723 |
#if (BOOT_GATE_ENABLE > 0) |
| 699 | 724 |
xcpInfo.other_connection = 0; |
| 700 | 725 |
#endif |
| 701 | 726 |
#if (BOOTLOADER_OF_MAIN_DEVICE > 0) |
| 702 |
if (data[1] == 0x00) {
|
|
| 727 |
if (deviceID == 0x00) {
|
|
| 703 | 728 |
xcpInfo.wasMainConnection = BLT_TRUE; |
| 704 | 729 |
} |
| 705 | 730 |
#endif |
| ... | ... | |
| 757 | 782 |
|
| 758 | 783 |
#if (BOOT_GATE_ENABLE > 0) |
| 759 | 784 |
} else {
|
| 760 |
xcpInfo.other_connection = data[1]; |
|
| 785 |
xcpInfo.other_connection = deviceID; |
|
| 786 |
setLed(1); |
|
| 761 | 787 |
xcpInfo.connected = 0; |
| 762 | 788 |
XcpPacketReceivedForwarding(data, dataLength); |
| 763 | 789 |
xcpInfo.ctoLen = 0; |
| ... | ... | |
| 768 | 794 |
} |
| 769 | 795 |
#endif |
| 770 | 796 |
|
| 771 |
|
|
| 797 |
|
|
| 772 | 798 |
} /*** end of XcpCmdConnect ***/ |
| 773 | 799 |
|
| 774 | 800 |
|
| ... | ... | |
| 789 | 815 |
#if (BOOT_GATE_ENABLE > 0) |
| 790 | 816 |
xcpInfo.other_connection = 0; |
| 791 | 817 |
#endif |
| 818 |
setLed(0); |
|
| 792 | 819 |
|
| 793 | 820 |
/* enable resource protection */ |
| 794 | 821 |
XcpProtectResources(); |
| ... | ... | |
| 1456 | 1483 |
#if (BOOT_GATE_ENABLE > 0) |
| 1457 | 1484 |
xcpInfo.other_connection = 0; |
| 1458 | 1485 |
#endif |
| 1486 |
setLed(0); |
|
| 1459 | 1487 |
|
| 1460 | 1488 |
#if (XCP_SEED_KEY_PROTECTION_EN == 1) |
| 1461 | 1489 |
/* check if PGM resource is unlocked */ |
Also available in: Unified diff