Skip to content

Commit c70559c

Browse files
committed
Merge branch 'feature/MCU16GITHUB-842-add-the-icsp-inhibit-feature' into feature/MCU16GITHUB-883-determine-a-way-to-verify-if-the-application-was-programmed-or-loaded-via-bo
2 parents dc0b336 + 75a6525 commit c70559c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4625
-7
lines changed

.main-meta/main.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
}
3636
},
3737
"keywords": [
38-
"GPIO",
39-
"UART"
38+
"GPIO"
4039
]
4140
}
4241
}

secure_boot_and_secure_firmware_upgrade_over_canfd/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The associated bootloader and application projects demonstrate the following:
2727
* The unzipped example project files, boot.X and app.X
2828
* [MPLAB® X IDE v6.15 or later](https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide)
2929
* [MPLAB® XC16 v2.10 or later](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers)
30-
* [Universal Bootloader Host Application v1.19.3 or later](www.microchip.com/16-bit-bootloader)
30+
* [Universal Bootloader Host Application v1.19.3 or later](https://www.microchip.com/16-bit-bootloader)
3131
* Device Family Pack 1.12.354
3232
* [MPLAB® Code Configurator (MCC) v5.6.1 or later (optional - for code configuration)](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator)
3333
* 16-Bit Bootloader MCC module v1.25.0 or later (optional - for code configuration)
@@ -60,8 +60,8 @@ The associated bootloader and application projects demonstrate the following:
6060
![Force Update](./images/MCC_Force_Update.png)
6161
4. Click "Generate"<br>
6262
![Generate](./images/MCC_Generate.png)
63-
5. Accept all incoming code changes for files **within the CryptoAuthenticationLibrary directory** by selecting "Replace All" in the merge helper UI. **NOTE: DO NOT accept incoming changes for boot_demo.c. Accept all other file changes and close out of MCC**<br>
64-
![Merge Resolution](./images/MCC_Merge_Resolution.PNG)
63+
5. Accept all incoming code changes for files **within the CryptoAuthenticationLibrary directory** by selecting "Replace All" in the merge helper UI<br> **NOTE: DO NOT accept incoming changes for boot_demo.c. Accept all other file changes and close out of MCC**<br>
64+
![Merge Resolution](./images/MCC_Merge_Resolution.png)
6565
6. Press the “Make and Program” button on the top bar<br>
6666
![Make and Program Device](./images/make_and_program.png)
6767
7. Select the appropriate programmer if prompted
@@ -70,7 +70,7 @@ The associated bootloader and application projects demonstrate the following:
7070

7171
#### Building the Application
7272
1. Open the app.X project in MPLAB® X
73-
2. Press the “Clean and Build Project” button on the top bar. **NOTE**: Make sure not to hit the program button. This will program the application code over the bootloader that was just programmed<br>
73+
2. Click the dropdown arrow next to the “Clean and Build Project” button on the top bar and select "Clean and Build Project" <br>**NOTE**: If "Clean and Build for Debugging" is selected instead, a new hex file will not be generated <br>**NOTE**: Make sure not to hit the program button. This will program the application code over the bootloader that was just programmed<br>
7474
![Clean and Build](./images/clean_and_build.png)
7575
3. The project should compile cleanly. app.X/dist/default/production/app.X.production.hex should be generated
7676
4. Verify that LED11 is still solid
@@ -103,7 +103,7 @@ The associated bootloader and application projects demonstrate the following:
103103
![Open Hex File](./images/UBHA_Open_Hex.png)
104104
8. Check the "Enable Self Verification After Program" checkbox<br>
105105
![Enable Verification](./images/UBHA_Enable_Verification.png)
106-
9. Press “Program Device”. The application should program erase, program and perform a self verify using the TA100 for an ECDSA verify then read back verify correctly. Note: The reset response may not be fully transmitted before reset which may result in the reset response failing. The reset most likely did occur and the error can be safely ignored.
106+
9. Press “Program Device”. The application should program erase, program and perform a self verify using the TA100 for an ECDSA verify then read back verify correctly.<br>**NOTE**: The reset response may not be fully transmitted before reset which may result in the reset response failing. The reset most likely did occur and the error can be safely ignored
107107
a. After a few seconds, LED11 should be blinking<br>
108108
![Program Device](./images/UBHA_Program.png)
109109

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.mc3

Lines changed: 326 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
© [2024] Microchip Technology Inc. and its subsidiaries.
3+
4+
Subject to your compliance with these terms, you may use Microchip
5+
software and any derivatives exclusively with Microchip products.
6+
You are responsible for complying with 3rd party license terms
7+
applicable to your use of 3rd party software (including open source
8+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19+
THIS SOFTWARE.
20+
*/
21+
22+
#include <stdio.h>
23+
#include <string.h>
24+
#include <stdbool.h>
25+
26+
#define WINDOW_SIZE 10
27+
#define UNLOCK_COMMAND "LOCKDEVICE"
28+
29+
// Function prototypes
30+
static void ClearTerminalScreen(void);
31+
static void ClearTerminalLine(void);
32+
static void MoveCursor(int row);
33+
static void HideCursor(void);
34+
static void PrintWarning(void);
35+
static void AppendCharToWindow(char receivedChar, char *window, int *windowIndex);
36+
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex);
37+
static void ResetWindowOnMismatch(char *window, int *windowIndex);
38+
static void CheckForUnlockCommand(char *window, int *windowIndex);
39+
40+
int main(void)
41+
{
42+
char window[WINDOW_SIZE + 1] = {0};
43+
int windowIndex = 0;
44+
45+
SYSTEM_Initialize();
46+
ClearTerminalScreen();
47+
PrintWarning();
48+
while (1)
49+
{
50+
if (UART1_IsRxReady())
51+
{
52+
char receivedChar = UART1_Read();
53+
ProcessReceivedChar(receivedChar, window, &windowIndex);
54+
CheckForUnlockCommand(window, &windowIndex);
55+
}
56+
}
57+
}
58+
59+
static void ClearTerminalScreen(void)
60+
{
61+
printf("\033[2J");
62+
}
63+
64+
static void ClearTerminalLine(void)
65+
{
66+
printf("\33[2K\r");
67+
}
68+
69+
static void MoveCursor(int row)
70+
{
71+
printf("\033[%d;0f", row);
72+
}
73+
74+
static void HideCursor(void)
75+
{
76+
printf("\033[?25l");
77+
}
78+
79+
static void PrintWarning(void)
80+
{
81+
MoveCursor(1);
82+
printf("Type LOCKDEVICE to enable the ICSP Inhibit feature.");
83+
MoveCursor(3);
84+
printf("WARNING: THIS PERMANENTLY DISABLES DIRECT PROGRAMMING OF THE BOARD.");
85+
}
86+
87+
static void ProcessReceivedChar(char receivedChar, char *window, int *windowIndex)
88+
{
89+
bool isCharValid = (*windowIndex < strlen(UNLOCK_COMMAND)) && (receivedChar == UNLOCK_COMMAND[*windowIndex]);
90+
91+
if (isCharValid)
92+
{
93+
AppendCharToWindow(receivedChar, window, windowIndex);
94+
MoveCursor(10);
95+
printf("%s", window);
96+
}
97+
else
98+
{
99+
ResetWindowOnMismatch(window, windowIndex);
100+
}
101+
}
102+
103+
static void AppendCharToWindow(char receivedChar, char *window, int *windowIndex)
104+
{
105+
window[(*windowIndex)++] = receivedChar;
106+
window[*windowIndex] = '\0';
107+
}
108+
109+
static void ResetWindowOnMismatch(char *window, int *windowIndex)
110+
{
111+
MoveCursor(10);
112+
ClearTerminalLine();
113+
MoveCursor(5);
114+
ClearTerminalLine();
115+
printf("Invalid character entered. Try again.");
116+
*windowIndex = 0;
117+
memset(window, 0, WINDOW_SIZE + 1);
118+
}
119+
120+
static void CheckForUnlockCommand(char *window, int *windowIndex)
121+
{
122+
if (strncmp(window, UNLOCK_COMMAND, *windowIndex) == 0 && *windowIndex == strlen(UNLOCK_COMMAND))
123+
{
124+
MoveCursor(5);
125+
ClearTerminalLine();
126+
printf("ICSP Programming/Debugging permanently disabled. \n");
127+
MoveCursor(10);
128+
ClearTerminalLine();
129+
*windowIndex = 0;
130+
memset(window, 0, WINDOW_SIZE + 1);
131+
}
132+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/**
3+
@Generated 16-bit Bootloader Source File
4+
5+
@Company:
6+
Microchip Technology Inc.
7+
8+
@File Name:
9+
app_code_protect.c
10+
11+
@Summary:
12+
This is the app_code_protect.c file generated using 16-bit Bootloader
13+
14+
@Description:
15+
This header file provides implementations for driver APIs for all modules selected in the GUI.
16+
Generation Information :
17+
Product Revision : 16-bit Bootloader - 1.25.0
18+
Device : dsPIC33CK1024MP710
19+
The generated drivers are tested against the following:
20+
Compiler : XC16 v1.36B
21+
MPLAB : MPLAB X v5.15
22+
*/
23+
/*
24+
Copyright (c) [2012-2024] Microchip Technology Inc.
25+
26+
All rights reserved.
27+
28+
You are permitted to use the accompanying software and its derivatives
29+
with Microchip products. See the Microchip license agreement accompanying
30+
this software, if any, for additional info regarding your rights and
31+
obligations.
32+
33+
MICROCHIP SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
34+
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
35+
LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
36+
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP OR ITS
37+
LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT
38+
LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE
39+
THEORY FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
40+
LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES,
41+
OR OTHER SIMILAR COSTS.
42+
43+
To the fullest extend allowed by law, Microchip and its licensors
44+
liability will not exceed the amount of fees, if any, that you paid
45+
directly to Microchip to use this software.
46+
47+
THIRD PARTY SOFTWARE: Notwithstanding anything to the contrary, any
48+
third party software accompanying this software is subject to the terms
49+
and conditions of the third party's license agreement. To the extent
50+
required by third party licenses covering such third party software,
51+
the terms of such license will apply in lieu of the terms provided in
52+
this notice or applicable license. To the extent the terms of such
53+
third party licenses prohibit any of the restrictions described here,
54+
such restrictions will not apply to such third party software.
55+
*/
56+
57+
#include <xc.h>
58+
59+
#if (__XC16_VERSION__ < 1050)
60+
#error "The code protection/CodeGuard feature of this bootloader requires features only found in XC16 version 1.50 or later. Update to a newer version of the XC16 compiler."
61+
#endif

0 commit comments

Comments
 (0)