1.5.1 Bootloader Single Partition Demo Project

Provides a description of the code generated by the MCC bootloader library for a Single Partition Project.

Demo Overview:

This section will walk through the high-level operation of the bootloader from a user perspective. It will focus on the high-level interfaces and not go into the low level operation of the bootloader kernel. The code below is found in main.c and mcc_generated_files\boot\boot_demo.c

In the file main.c, after device reset, the first bootloader code called is BOOT_DEMO_Initialize(). This purpose of this code is to initialize anything the bootloader may need to run like extra GPIO or peripheral configuration that is not done in SYSTEM_Initialize(). Following this, the next bootloader call is to call BOOT_DEMO_Tasks() in a loop as shown below.

int main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    BOOT_DEMO_Initialize();
 
    while (1)
    {
    // Add your application code
    BOOT_DEMO_Tasks();
    }
 
    return 1;
}

 

The code in BOOT_DEMO_Tasks() does three things.  

  • First, it checks to see if the user is wanting to enter bootloader mode right after reset is released by calling EnterBootloadMode(). If this returns true, it immediately enters the bootloader without doing anything else.

  • Second, it verifies the integrity of the application image.

  • Finally, if the integrity of the application is verified, then the application is run. If the integrity check of the application fails, the bootloader is then run.

static bool inBootloadMode = false;
static bool executionImageRequiresValidation = true;
static bool executionImageValid = false;

void BOOT_DEMO_Initialize(void)
{    
    
}


void BOOT_DEMO_Tasks(void)
{
    if(inBootloadMode == false)
    {
        if( EnterBootloadMode() == true )
        {
            inBootloadMode = true;
        }
        else
        {
            if( executionImageRequiresValidation == true )
            {
                executionImageValid = BOOT_ImageVerify(EXECUTION_IMAGE);
            }

            if(executionImageValid == false)
            {
                inBootloadMode = true;
            }

            if(inBootloadMode == false)
            {
                BOOT_StartApplication();
            }
        }
    }
    
    (void)BOOT_ProcessCommand();
}

static bool EnterBootloadMode(void)
{
    #warning "Update this function to return 'true' when you want to stay in the bootloader, and 'false' when you want to allow a release to the application code"
 
    /* NOTE: This might be a a push button status on power up, a command from a peripheral, 
     * or whatever is specific to your bootloader implementation */    

    return false;
}