How to Jump into flashloader at runtime (RT1052)

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

How to Jump into flashloader at runtime (RT1052)

2,633 Views
eric_yp_chen
Contributor I

Hi jeremyzhou‌ & Everyone

I have another question about ivt_flashloader

I found that flashloader is just a application which allow user to upload new image to external nor flash.

This is what MCUBootUtility just did.

pastedImage_3.png

I'm wondering if I could copy "ivt_flashloader.bin" into the same memory address(ocram I guess).

Is it possible to jump into this application at runtime ?

I tried but nothing happened. (FlashLoaderIAR is converted from ivt_flashloader.bin)

pastedImage_5.png

pastedImage_6.png

0 Kudos
Reply
11 Replies

2,319 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eric Chen,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
In the ivt_flashloader.bin, the application only occupies the space from offset address: 0x2000 to the end. So it should remove unnecessary areas except for application code prior to store in FlashLoaderIAR array.
Hope this is clear.

Have a great day,
TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,319 Views
eric_yp_chen
Contributor I

Hi Jeremyzhou

I've tried to remove unnecessary areas in FlashLoaderIAR array.

Just copy the application from 0x2000 to the end into OCRAM.

But it still don't work.

Is it possible to give more hints ?

My develop device is RT1052

Thanks

0 Kudos
Reply

2,319 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eric Chen,

Thanks for your reply.
First, it should copy the flashloader bin to the area whose address starts 0x20002000, then use the below code to jump to flashloader.
    // relocate vector table
    SCB_VTOR = ocramAddr;
pFun = (Fun_t)(*((volatile uint32_t*)(ocramAddr+4)));
(void)(pFun)();

Have a great day,
TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,319 Views
eric_yp_chen
Contributor I

Hi jeremyzhou

Thanks for your reply

And I'm pretty sure my FlashLoaderIAR (ivt_flashloader.bin) array already located at DTC Ram

Copy FlashLoaderIAR to ocramAddr (0x20208200), then jump to this address.

It still failed.

So, I make double check to calculate checksum, the result is not the same as FlashLoaderIAR array.

Any possible step missing ?

pastedImage_1.png

Best Regards,

Eric

0 Kudos
Reply

2,319 Views
jeremyzhou
NXP Employee
NXP Employee

HiEric Chen,

Sorry for reply late.
There's an error in my previous reply, and I've corrected it, please follow it to do it.

Have a great day,
TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,319 Views
eric_yp_chen
Contributor I

Hi jeremyzhou

It doesn't work either.

Would you provide a project file for me ?

I'm using RT1052-EVKB with MCU-Xpresso.

Thank you 

Eric

0 Kudos
Reply

2,319 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eric Chen,

Thanks for your reply.
I was wondering if you can upload your demo project as I'd like to do some testing by myself and it can help me to figure this issue out.

Have a great day,
TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,319 Views
eric_yp_chen
Contributor I
0 Kudos
Reply

2,319 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eric Chen,

I've worked it out, my testing code is based on hello_world demo which is from the SDK library, so please check the attachment and give a try.

pastedImage_1.png

Have a great day,
TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

Attachments

0 Kudos
Reply

2,319 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eric Chen,

Thanks for your reply.
The flashloader code also doesn't run well after jumping. And it will trigger a reset event once jumping.
I've attached my flashloader.c and my basic testing code.
Now I'm still working on the issue, and I'll inform you ASAP after working it out.
Of course, you can contact me if you have some breakthroughs.

/*
 * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "flash_loader.h"

#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/
//uint8_t ocramAddr[];

/*******************************************************************************
 * Prototypes
 ******************************************************************************/
#define kDefaultVectorTableAddress 0

void bootloader_cleanup()
{
    // Turn off interrupts.
    __disable_irq();

    // Set the VTOR to default.
    SCB->VTOR = kDefaultVectorTableAddress;

    // Memory barriers for good measure.
    __ISB();
    __DSB();
}

static void jump_to_application(uint32_t applicationAddress, uint32_t stackPointer)
{


    // Create the function call to the user application.
    // Static variables are needed since changed the stack pointer out from under the compiler
    // we need to ensure the values we are using are not stored on the previous stack
    static uint32_t s_stackPointer = 0;
    s_stackPointer = stackPointer;
    static void (*farewellBootloader)(void) = 0;
    farewellBootloader = (void (*)(void))applicationAddress;

    // Set the VTOR to the application vector table address.
    SCB->VTOR = (uint32_t)stackPointer;

    // Set stack pointers to the application stack pointer.
    __set_MSP(s_stackPointer);
    __set_PSP(s_stackPointer);

    // Jump to the application.
    farewellBootloader();

}
/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Main function
 */
int main(void)
{
    char ch;
    //uint8_t *pointer_flashloader;

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();

    PRINTF("Flashloader testing.\r\n");
//
//    uint8_t *ocramAddr = (uint8_t*)(0x20002000);
//    for (uint32_t i = 0; i < 82142; i++) {
//     *(ocramAddr+i)=FlashLoaderIAR[i];
//    }
//
    // Copy flashloader image to RAM.
    memcpy((void *)0x20002000, FlashLoaderIAR, 82142);
    bootloader_cleanup();
    jump_to_application(0x20002004,0x20002000);

    while (1)
    {
        ch = GETCHAR();
        PUTCHAR(ch);
        bootloader_cleanup();
        jump_to_application(0x20002004,0x20002000);
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Have a great day,
TIC

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

2,319 Views
mjbcswitzerland
Specialist V

Hi

Assuming this is your resect vector:

pastedImage_1.png

the IAR program's initial stack pointer value is 0x402000d1 and initial program counter 0x2021b26d
I presume that this means that its stack will be in external memory (SDRAM?) although it is not normal for it to be an unaligned values(?). Before jumping you will presumably need to ensure that the SDRAM has been initialised (or the DCD of the boot loader is doing this). Also you will probably need to set the stack pointer value correctly.

The jump code doesn't look right if it should be jumping to the start address (0x2021b26d). It presently jumps to the initial stack pointer address. To jump to the code it needs to first read the values and then jump to where they are pointing to and not jump to the address of where the values are stored.

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

0 Kudos
Reply