Problem About HSM_UCB

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User17736
Level 1
Level 1
Hello

I have made a mistake to run a funcion at the TC297TF(as below, function name: flash_ucb_hsmcotp(1) ).


/*
* SartupHSM.c
*
* Created on: 2017-5-8
* Author: Infineon
*/

#include "Std_Types.h"
#include "Cry_Hsm.h"
#include "HsmCom_def.h"
#include "IfxStm_reg.h"
#include "IfxPmu_reg.h"
#include "IfxFlash_reg.h"
#include "StartupHSM.h"

#define HSMCOTP_BASEADDR 0xAF100800

#define MEM(memAddr) (*((volatile unsigned int *)(memAddr)))

/*!
* \brief Failure id x occured and stored, called from task in case of plausibility fail
*
* If a failure occurs this function will be called.
* The function stores Debug information into the failure sector.
* If the Debugger is connected a the Pattern is stopped via _debug instruction
*/

void FAIL (TFAIL_STATUS x, uint32 y)
{
while (1 == 1);
}

/*!
* \brief Erase a given sector to of Data Flash.
*
*/
uint32 dflash_erase (uint32 addr, uint32 cnt)
{
volatile uint32 pmuid;
if (!cnt)
return (1);
MEM (0xAF00AA50) = (uint32) addr;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF00AA58) = (uint32) cnt;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF00AAA8) = (uint32) 0x80;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF00AAA8) = (uint32) 0x50;
pmuid = MEM (&PMU0_ID.U);
return (0);
}

/*!
* \brief Program a 32byte Page to a given address of Data Flash.
*
*/
void dflash_program (uint32 addr, uint32 * pmem)
{
volatile uint32 i;
volatile uint32 low32bit, high32bit;
volatile uint32 pmuid;

MEM (0xAF005554) = 0x5D;
pmuid = MEM (&PMU0_ID.U);
if ((MEM (&FLASH0_FSR.U) & 0x400) == 0)
FAIL (DFLASH_PROGRAM0, 0);
if ((MEM (&FLASH0_FSR.U) & 0x3800) != 0)
FAIL (DFLASH_PROGRAM1, 0);

i = 0;
while (i < 0x8)
{
low32bit = pmem;
high32bit = pmem[i + 1];
MEM (0xAF0055F0) = low32bit;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF0055F4) = high32bit;
pmuid = MEM (&PMU0_ID.U);
i += 2;
}

MEM (0xAF00AA50) = (uint32) addr;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF00AA58) = (uint32) 0x00;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF00AAA8) = (uint32) 0xA0;
pmuid = MEM (&PMU0_ID.U);
MEM (0xAF00AAA8) = (uint32) 0x7A;
pmuid = MEM (&PMU0_ID.U);
}

/**!
* flash_ucb_hsmcotp
*/
void flash_ucb_hsmcotp(uint32 isEnable)
{
uint32 i;
uint32 buffer[0x40];
uint32 addr;

addr = HSMCOTP_BASEADDR; /* HSMCOTP*/

dflash_erase(addr, 1);
while ((MEM (&FLASH0_FSR.U) & 0x1E) != 0)
;

for (i = 0; i < 0x40; i += 1)
buffer = 0x0;
/*PROCONHSMCOTP will be set, see User Manual*/
buffer[0x0] = isEnable; /*PROCONHSMCOTP 1st Set 0111 1000 0011: enable reset and pins, sswwait, hsmboot*/
buffer[0x4] = isEnable; /*Copy of PROCONHSM*/
buffer[0x1C] = 0x43211234; /*unlocked*/
buffer[0x1E] = 0x43211234; /*unlocked*/
buffer[0x20] = 0x0; /*PROCONHSMCOTP 2nd Set*/
buffer[0x24] = 0x0; /*Copy of PROCONHSM*/
buffer[0x3C] = 0x43211234; /*unlocked*/
buffer[0x3E] = 0x43211234; /*unlocked*/
for (i = 0; i < 8; i += 1)
{
dflash_program(addr + i * 32, &buffer[i * 8]);
while ((MEM (&FLASH0_FSR.U) & 0x1E) != 0);
}

__debug(); /* Stop execution here */
}



then i try to use UDE-Debuger reconnect the chip, it works no never. These codes maybe erased and rewrited the flash at 0xAF100800. I dont know how to solve it or reset the chip. Who can help me? THANKS!!!

3697.attach

BR
0 Likes
2 Replies
MsMdt
Employee
Employee
10 replies posted 5 replies posted First reply posted
I did not check the content you programmed in detail but most likely you did enable the Hardware Security Module without having valid code for it in the Flash. This leads to a situation where protection including Debug interface protection is enabled.
This means you will never be able to connect to this chip again unless you have a separate SW flashed in the Chip beforehand that is able to unlock upon a command from any diagnosis interface. (Which I guess is not the case with your current setup).

For trials with UCB programming and HSM especially I recommend to use an ECU with a socket and a few spare samples. Also please read the UCB section of the user manual very carefully since it is quite easy to accidentally enable protections and lock the debug interface.
0 Likes
User17736
Level 1
Level 1
Thanks for your suggestions, i will be careful in the next time!
0 Likes