This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: cc2541: Stop unwanted Bin File in OTA

Part Number: CC2541

I am working on OTA. I want to set password in OTA BIM project and oad_target.c so BIM first check that password and then upload that File(imgx.bin)

1-I used OAD_IMAGE_A_USER_ID /OAD_IMAGE_B_USER_ID For this purpose(While creating bin file for OTA) in oad_target.c

#if !defined (OAD_IMAGE_A_USER_ID)
#define OAD_IMAGE_A_USER_ID {'A', 'B', 'C', 'D'}
#endif

#if !defined (OAD_IMAGE_B_USER_ID)
#define OAD_IMAGE_B_USER_ID {'A', 'B', 'C', 'D'}
#endif

2-Then I changed in BIM to check OAD_IMAGE_A_USER_ID /OAD_IMAGE_B_USER_ID:

void main(void)
{
uint8 password[4];
uint16 crc[2];

// Check for valid password before running program.
HalFlashRead(BIM_IMG_B_PAGE, 8 , (uint8 *)password, 4);

if((password[0] == 'A') && (password[1] == 'B') &&(password[2] == 'C')&&(password[3] == 'D'))

{

// Prefer to run Image-B over Image-A so that Image-A does not have to invalidate itself.
HalFlashRead(BIM_IMG_B_PAGE, BIM_CRC_OSET, (uint8 *)crc, 4);

if ((crc[0] != 0xFFFF) && (crc[0] != 0x0000))
{
if (crc[0] == crc[1])
{
JumpToImageAorB = 1;
// Simulate a reset for the Application code by an absolute jump to the expected INTVEC addr.
asm("LJMP 0x4030");
HAL_SYSTEM_RESET(); // Should not get here.
}

crcCheck(BIM_IMG_B_PAGE, crc);
}
}

// Check for valid password before running program.
HalFlashRead(BIM_IMG_A_PAGE, 8 , (uint8 *)password, 4);

if((password[0] == 'A') && (password[1] == 'B') &&(password[2] == 'C')&&(password[3] == 'D'))

{
HalFlashRead(BIM_IMG_A_PAGE, BIM_CRC_OSET, (uint8 *)crc, 4);

if ((crc[0] != 0xFFFF) && (crc[0] != 0x0000))
{
if (crc[0] == crc[1])
{
JumpToImageAorB = 0;
// Simulate a reset for the Application code by an absolute jump to the expected INTVEC addr.
asm("LJMP 0x0830");
HAL_SYSTEM_RESET(); // Should not get here.
}
else if (crc[1] == 0xFFFF) // If first run of an image that was physically downloaded.
{
crcCheck(BIM_IMG_A_PAGE, crc);
}
}

SLEEPCMD |= 0x03; // PM3, All clock oscillators off, voltage regulator off.
halSleepExec();
HAL_SYSTEM_RESET(); // Should not get here.
}
}

Now I uploaded(OTA) a bin file with wrong OAD_IMAGE_A_USER_ID/OAD_IMAGE_B_USER_ID

#if !defined (OAD_IMAGE_A_USER_ID)
#define OAD_IMAGE_A_USER_ID {'A', 'A', 'A', 'A'}
#endif

#if !defined (OAD_IMAGE_B_USER_ID)
#define OAD_IMAGE_B_USER_ID {'B', 'B', 'B', 'B'}
#endif

And device accepted this bin file successfully..
Where I am making mistske.?

is this correct way?and correct syntax i using?
Kindly mention how can i set this password?

  • Hi Muqarrab,

    Is the code you are running executing? Can you set a breakpoint to see what happens when the image header is read? Do you have a sniffer capture showing the OAD and the new image advertising after the OAD?

    "And device accepted this bin file successfully.." Can you clarify what you mean here? Do you mean that it accepted the download or that the new image ran after the download complete?
  • I am setting this OAD_IMAGE_A_USER_ID/OAD_IMAGE_B_USER_ID in target_ota.c

    #if !defined (OAD_IMAGE_A_USER_ID)
    #define OAD_IMAGE_A_USER_ID {'A', 'B', 'C', 'D'}
    #endif

    #if !defined (OAD_IMAGE_B_USER_ID)
    #define OAD_IMAGE_B_USER_ID {'A', 'B', 'C', 'D'}
    #endif

    And getting OAD_IMAGE_A_USER_ID/OAD_IMAGE_A_USER_ID in BIM main like this

    uint8 password[4];
    HalFlashRead(BIM_IMG_A_PAGE, 8 , (uint8 *)password, 4);

    is this correct way to get value of OAD_IMAGE_A_USER_ID/OAD_IMAGE_A_USER_ID in BIM?
  • Hi Muqarrab,

    That should be the correct way to get the value of the User ID. What does password contain after the Flash Read?

    Could you answer the following questions from my previous post:

    1. Do you have a sniffer capture showing the OAD and the new (unwanted) image advertising after the OAD?
    2. "And device accepted this bin file successfully.." Can you clarify what you mean here? Do you mean that it accepted the download or that the new image ran after the download complete?
  • Thank you for your reply I have fixed this issue
  • Hi Muqarrab,

    I'm glad you were able to resolve this issue. Can you share what was going on and how you fixed it?
  • Yes Actually i was working on cc2541 and only changing (OAD_IMAGE_X_USER_ID) in target_ota.c. And as you can see that

    #if !defined (OAD_IMAGE_A_USER_ID)
    #define OAD_IMAGE_A_USER_ID {'A', 'B', 'C', 'D'}
    #endif

    #if !defined (OAD_IMAGE_B_USER_ID)
    #define OAD_IMAGE_B_USER_ID {'A', 'B', 'C', 'D'}
    #endif

    if not define then set this.

    It has been already define in buildConfig.cfg as
    // OAD User IDs
    -DOAD_IMAGE_A_USER_ID="'A', 'A', 'A', 'A'"
    -DOAD_IMAGE_B_USER_ID="'B', 'B', 'B', 'B'"

    As i changed here then BIM first checked user ID then run new bin file.