Jump to bootloader from APP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Jump to bootloader from APP

2,226 Views
张华荣
Contributor II

Hello,

I used the taget CPU is MK22FN1M0AVLQ12,the bootloader version is NXP_Kinetis_Bootloader_2_0_0,the development tool is KDS 3.2.0.

The bootloader running OK and the Update image funcion is OK.When CPU power,the bootloader timeout 2S,then jump to APP,the APP running OK.

 

Now i want to implemnet the function that Jump to bootloader from APP,and through the APP_flag control the bootloader running.

 

bool RunBootloaderFlag = 0U;

 

if(0x55 = APP_flag)

{

     RunBootloaderFlag = 1U;

}

 

time out = 2000U;    /* 2S */

 

while(activePeripheral == NULL)

{

      if((time out > 0U) && (RunBootloaderFlag == 0))

      {

            time out--;

      }

      if(time out == 0 )

      {

           jump_to_application(applicationAddress, stackPointer);

       }

      

      wait the shake hands;

}

 

How can i do that modify the APP_flag?Whether i can call the runBootloader function and pass the parameter.

Labels (1)
6 Replies

1,415 Views
ramboyang
NXP Employee
NXP Employee

Hello,

Looks like you want to pass an argument to Flash-resident bootloader.

For now, the runBootloader API doesn't support any paramters.

Here is an alternative way.

Define a gloabal variable that is not in the Bootloader reserved region (otherwise, it may be overwritten during the bss and rw data section initialization).

For example, in the application.

#define APP__FLAG  *(uint32_t*)0x20010000

APP_FLAG  = 0x55.

In the Bootloader,

Using the same definition.

It is not a good solution, but it may be helpful to address your requirement.

Best Regards.

1,415 Views
harshpatel
Contributor IV

Hello

For my curiosity i want to know how you plan to manage App_flag?  means, when you jump from app to bootloader same App_flag no longer exist.

Thanks & regards

Harsh

0 Kudos

1,415 Views
张华荣
Contributor II

Hello,

through config a reserved RAM(App_flag) in LINK file in bootloader and APP project.So the booloader and the APP can share the common RAM.The APP modify the APP_Flag,when jump to bootloader,check the APP_flag.

0 Kudos

1,415 Views
harshpatel
Contributor IV

Hello 

You mean App is started already and now from app you want to jump in bootloader.

if it so than you can add following things in your app as we have done previously:

In UART Callback:

------------------------

if(wait4boot==1 && c == 0x55)
{
wait4boot=0;
jumptobootloadder=1;
}

In Main Function:

---------------------------

#define BL_VECTORS       0x0

uint32_t run_bootloader;

if(RunBootloaderFlag)
{
RunBootloaderFlag=0;
run_bootloader = ((uint32_t*)BL_VECTORS)[1];
((void(*)(void))run_bootloader)();
}

Let me know if any...

----------------------------------------------------------------------------------------------------------------

PLEASE MARK AS CORRECT OR HELPFULL IF IT IS 

---------------------------------------------------------------------------------------------------------------

Thanks & regards,

Harsh

Einfochips INDIA

1,415 Views
张华荣
Contributor II

OK,thanks,the CPU can jump to bootloader from APP,and the function is OK.

But I want to through the APP Flag to make the bootloader always running,do not timeout.

the APP code:

if(jumpToBootloader)

{

        APP_flag = 1;

}

the bootloader code:

if(APP_flag == 1)

{

      bootloader always running,do not timeout.

}

else

{

      timeout ,the bootloader jump to APP

}

I hope you can understand,thanks!

0 Kudos

1,415 Views
jeremyzhou
NXP Employee
NXP Employee

Hi 张 华荣,

According to your statement, I'd like to suggest to insert the APP_flag macro in the *get_active_peripheral(void) function to eliminate the peripheral detection times out flow.

I think it can achieve your goal.

//! @brief Determines the active peripheral.
//!
//! This function has several stages:
//! - Init enabled peripherals.
//! - Compute timeout.
//! - Wait for peripheral activity with timeout.
//! - Shutdown inactive peripherals.
//!
//! If peripheral detection times out, then this function will call jump_to_application() to
//! directly enter the user application.
//!
//! The timeout value comes from the BCA if set, or the #BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT
//! configuration macro. If the boot pin is asserted, or if there is not a valid user application
//! in flash, then the timeout is disabled and peripheral detection will continue infinitely.
static peripheral_descriptor_t const *get_active_peripheral(void)
{
    peripheral_descriptor_t const *peripheral;
    peripheral_descriptor_t const *activePeripheral = NULL;
    bootloader_configuration_data_t *configurationData =
        &g_bootloaderContext.propertyInterface->store->configurationData;

    // Bring up all the peripherals
    for (peripheral = g_peripherals; peripheral->typeMask != 0; ++peripheral)
    {
        // Check that the peripheral is enabled in the user configuration data
        if (configurationData->enabledPeripherals & peripheral->typeMask)
        {
            assert(peripheral->controlInterface->init);

            debug_printf("Initing %s\r\n", get_peripheral_name(peripheral->typeMask));
            peripheral->controlInterface->init(peripheral, peripheral->packetInterface->byteReceivedCallback);
        }
    }

#if !BL_FEATURE_TIMEOUT
    uint64_t lastTicks = 0;    // Value of our last recorded ticks second marker
    uint64_t timeoutTicks = 0; // The number of ticks we will wait for timeout, 0 means no timeout
#if BL_FEATURE_POWERDOWN
    bool shortTimeout = false;
#endif
    const uint64_t ticksPerMillisecond = microseconds_convert_to_ticks(1000);

    // Get the user application entry point and stack pointer.
    uint32_t applicationAddress, stackPointer;
    get_user_application_entry(&applicationAddress, &stackPointer);

    // If the boot to rom option is not set AND there is a valid jump application determine the timeout value
    if (!is_boot_pin_asserted() && is_application_ready_for_executing(applicationAddress))
    {
        if (is_direct_boot())
        {
            jump_to_application(applicationAddress, stackPointer);
        }

        // Calculate how many ticks we need to wait based on the bootloader config. Check to see if
        // there is a valid configuration data value for the timeout. If there's not, use the
        // default timeout value.
        uint32_t milliseconds;
        if (configurationData->peripheralDetectionTimeoutMs != 0xFFFF)
        {
            milliseconds = configurationData->peripheralDetectionTimeoutMs;
        }
        else
        {
            milliseconds = BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT;
        }
        timeoutTicks = milliseconds * ticksPerMillisecond;

        // save how many ticks we're currently at before the detection loop starts
        lastTicks = microseconds_get_ticks();
#if BL_FEATURE_POWERDOWN
        shortTimeout = true;
#endif
    }
#if BL_FEATURE_POWERDOWN
    else
    {
        timeoutTicks = BL_DEFAULT_POWERDOWN_TIMEOUT * ticksPerMillisecond;
        lastTicks = microseconds_get_ticks();
    }
#endif
#endif // !BL_FEATURE_TIMEOUT

    // Wait for a peripheral to become active
    while (activePeripheral == NULL)
    {
#if !BL_FEATURE_TIMEOUT
        // If timeout is enabled, check to see if we've exceeded it.
        if (timeoutTicks)
        {
            // Note that we assume that the tick counter won't overflow and wrap back to 0.
            // The timeout value is only up to 65536 milliseconds, and the tick count starts
            // at zero when when inited the microseconds driver just a few moments ago.
            uint64_t elapsedTicks = microseconds_get_ticks() - lastTicks;

            // Check if the elapsed time is longer than the timeout.
            if (elapsedTicks >= timeoutTicks)
            {
#if BL_FEATURE_POWERDOWN
                if (shortTimeout)
                {
#endif
                    // In the case of the typical peripheral timeout, jump to the user application.
                    jump_to_application(applicationAddress, stackPointer);
#if BL_FEATURE_POWERDOWN
                }
                else
                {
                    // Make sure a timeout value has been defined before shutting down.
                    if (BL_DEFAULT_POWERDOWN_TIMEOUT)
                    {
                        // Shut down the bootloader and return to reset-type state prior to low
                        // power entry
                        shutdown_cleanup(kShutdownType_Shutdown);

                        // Enter VLLS1 low power mode
                        enter_vlls1();
                    }
                }
#endif
            }
        }
#endif // !BL_FEATURE_TIMEOUT
        // Traverse through all the peripherals
        for (peripheral = g_peripherals; peripheral->typeMask != 0; ++peripheral)
        {
            // Check that the peripheral is enabled in the user configuration data
            if (configurationData->enabledPeripherals & peripheral->typeMask)
            {
                assert(peripheral->controlInterface->pollForActivity);

                if (peripheral->controlInterface->pollForActivity(peripheral))
                {
                    debug_printf("%s is active\r\n", get_peripheral_name(peripheral->typeMask));

                    activePeripheral = peripheral;
                    break;
                }
            }
        }
    }

    // Shut down all non active peripherals
    for (peripheral = g_peripherals; peripheral->typeMask != 0; ++peripheral)
    {
        // Check that the peripheral is enabled in the user configuration data
        if (configurationData->enabledPeripherals & peripheral->typeMask)
        {
            if (activePeripheral != peripheral)
            {
                debug_printf("Shutting down %s\r\n", get_peripheral_name(peripheral->typeMask));

                assert(peripheral->controlInterface->shutdown);
                peripheral->controlInterface->shutdown(peripheral);
            }
        }
    }

    return activePeripheral;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos