Custom Bootloader - Start Application on Power Reset

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

cross mob
Bigby
Level 2
Level 2
25 sign-ins 10 sign-ins 5 replies posted

Hello,

I'm working on a custom bootloader on a CY8CKIT-042.
My work is based on AN68272 and this article: https://community.cypress.com/t5/Knowledge-Base-Articles/PSoC-4-Custom-Bootloader-KBA229075/ta-p/257...

So basically i start the bootloader from the application via Bootloadable_Load and in the bootloader section I receive rows of data via a proprietary interface. These rows are programmed using CySysFlashWriteRow.

If there are no errors, Bootloader_Exit is called and the new Application starts.
This works fine so far.

My problem is that on a power reset I want the application to start, but it always starts the bootloader.


If I would use Bootloader_Start, this would work, but I can't because I wouldn't know how to work my interface into the default functions like CyBtldrCommWrite and CyBtldrCommRead.

So i checked Bootloader.c and tried to make sense of it.

I tried to call CyBtldr_CheckLaunch during initialisation, but this didn't do anything.

I tried

if(Bootloader_ValidateBootloadable(0) == CYRET_SUCCESS)
{
Bootloader_Exit(Bootloader_EXIT_TO_BTLDB);
}

But this leads t the bootloader always directly jumping back to the application, even if the bootloader ist startet from the application.

I tried:

if ((Bootloader_GET_RUN_TYPE == Bootloader_SCHEDULE_BTLDR) ||\
(CYRET_SUCCESS != Bootloader_ValidateBootloadable(Bootloader_MD_BTLDB_ACTIVE_0)))
{
    Bootloader_Exit(Bootloader_EXIT_TO_BTLDB);
}

But this seems to crash the bootloader. When bootloader is active a PWM is used for a blinking red LED but with this code the LED stays always on.

Now I thought i try to ask the community for help on this.

I know that the Bootloadable manipulates a certain memory part so the bootloader can differ between being called from the application with a software reset and a power reset.

I need to know how I can manually detect this in the bootloader.

Thanks in advance.

This is the content of my bootloader main.c:

#include "main.h"

void CyBtldrCommStart(void){}
void CyBtldrCommStop(void){}
void CyBtldrCommReset(void){}
cystatus CyBtldrCommWrite(uint8 pData[], uint16 size, uint16* count, uint8 timeOut)
{return CYRET_SUCCESS;}
cystatus CyBtldrCommRead(uint8 pData[], uint16 size, uint16* count, uint8 timeOut)
{return CYRET_SUCCESS;}

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    PWM_Start();
    //CyBtldr_CheckLaunch();

    for(;;)
    {
        /* Place your application code here. */
        if(OWS_Main() == UPD_CMD_UPDATE)
        {
            PWM_WriteCompare(192);
            if(UPD_RunUpdate() == UPD_STAT_SUCCESS)
            {
                Bootloader_Exit(Bootloader_EXIT_TO_BTLDB);
            }
        }
    }
}

/* [] END OF FILE */

0 Likes
1 Solution
Bigby
Level 2
Level 2
25 sign-ins 10 sign-ins 5 replies posted

I finally found a solution that seems to work.

In case anybody wants to know, I found out that Bootloadable_Load sets the variable cyBtldrRunType  to 0x40. This variable is also present in the Bootloader files and keeps this value.

So I check this value and if there is a valid application, which looks like this in my code.

if((cyBtldrRunType != Bootloader_SCHEDULE_BTLDR) &&\
(CYRET_SUCCESS == Bootloader_ValidateBootloadable(Bootloader_MD_BTLDB_ACTIVE_0)))
{
    Bootloader_Exit(Bootloader_EXIT_TO_BTLDB);
}

 

View solution in original post

0 Likes
1 Reply
Bigby
Level 2
Level 2
25 sign-ins 10 sign-ins 5 replies posted

I finally found a solution that seems to work.

In case anybody wants to know, I found out that Bootloadable_Load sets the variable cyBtldrRunType  to 0x40. This variable is also present in the Bootloader files and keeps this value.

So I check this value and if there is a valid application, which looks like this in my code.

if((cyBtldrRunType != Bootloader_SCHEDULE_BTLDR) &&\
(CYRET_SUCCESS == Bootloader_ValidateBootloadable(Bootloader_MD_BTLDB_ACTIVE_0)))
{
    Bootloader_Exit(Bootloader_EXIT_TO_BTLDB);
}

 

0 Likes