RT1020 resets original boot_data when returning from plugin function?

cancel
Showing results for 
Search instead for 
Did you mean: 

RT1020 resets original boot_data when returning from plugin function?

163 Views
rshipman
Contributor V

IDE: MCUXpresso IDE v11.0.1 [Build 2563] [2019-09-01]

Platform: MIMXRT1020-evk eval board

Example project: demos/iled_blinky

I am experimenting with the boot plugin functionality of the RT1021 using the iled_blinky demo.

As a very quick first step, I created a simple plugin function that simply calls ResetISR (which then calls main() - which I modified to flash the led a couple of times and return 0).

Both the plugin and application images are identical apart the following changes:

The image as loaded into flash by MCUXpresso:

   IVT entry field points to my plugin function

   boot_data plugin field is set to 1 (plugin mode)

The image just before the plugin function returns:

   IVT entry field points to ResetISR

   boot_data plugin field is set to 0 (plugin mode off)

Both images run, but between the return from the plugin function and the (second) call to ResetISR the boot_data fields have been overwritten with the original values. So the boot_data plugin field is set to 1 again.

I have confirmed this using the MCUXpresso debugger.

I cannot see how this is possible as there is only one image in flash and none of the code is run between the end of the plugin function and the start of ResetISR as far as I am aware (seeing as one is an image exit point and the other is an image entry point).

Also when returning from execution of the second image it crashes with a hard fault. The entry field is now set to call ResetISR but the plugin field has been set to 1, so presumably all the arguments and return values the ARM bootloader is expecting from a plugin function are missing/garbage.

Note that my plugin function simply calls ResetISR, sets the above fields and then sets up the function arguments before returning.

The source mods follow (- they're not beautiful mods, just a quick experiment to get something working).

You may need to add a couple forward declarations etc:

In source/iled_blinky.c:

Near the top:

#include "fsl_flexspi_nor_boot.h"

In the main function, change main while (1) loop to:

/* Flash led n times */
int n = 2;

int i = n*2;

while (i--)

{

  :

  :

}

return 0;

After main() function:

extern void ResetISR(void);

int PluginFunction(void **start, uint32_t *bytes, uint32_t *ivt_offset)

{

  ResetISR();

  *start = (void*)boot_data.start;

  *bytes = boot_data.size;

  *ivt_offset = 0x1000;

  // Reuse the same image, just not this plugin function.

  // Bodge away const etc.

  *((uint32_t*)&(image_vector_table.entry)) = IMAGE_ENTRY_ADDRESS;

  *((uint32_t*)&(boot_data.plugin)) = 0; // This gets set back to 1. The MCUXpresso confirms this is set to 0 here. And set back to 1 by the start of the next call to ResetISR

  // The following I added as experiments, the problem exists without these three lines.

  *((uint32_t*)&(boot_data.size)) -= 4; // Experiment - this gets overwritten.

  *((uint32_t*)&(image_vector_table.dcd)) = 0x60001234; // Experiment - this does not get overwritten.

  *((uint32_t*)&(boot_data.start)) = 0x60005678; // Experiment - this gets overwritten.

  return 1; // 1 is success

}

In fsl_flexspi_nor_boot.c:

const ivt image_vector_table = {

  IVT_HEADER, /* IVT Header */

  ((uint32_t)PluginFunction), // IMAGE_ENTRY_ADDRESS

  :

  :

In fsl_flexspi_nor_boot.h:

#define PLUGIN_FLAG (uint32_t)1

In startup_mimxrt1021.c, comment out while(1) {;} loop at end of ResetISR function.

I will eventually have two separate images, so I think it is important to understand what is going on here.

Any help appreciated.

0 Kudos
3 Replies

61 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi rshipman ,

  Thank you for your interest in NXP MIMXRT product, I would like to provide service for you.

  You mentioned: " but between the return from the plugin function and the (second) call to ResetISR the boot_data fields have been overwritten with the original values"

 And you also debug to confirm it, could you also share some debug result screenshot about the problem?

  BTW, could you also attach your modified plug-in project, then I will also can try it to reproduce the problem, thanks.

Waiting for your updated information.

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
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

61 Views
rshipman
Contributor V

Hi Kerry,

Thanks for your reply.

Please find 3 zip archives uploaded:

  • evkmimxrt1020_iled_blinky_plugin_for_nxp.zip
  • Screenshots with line 128 commented out.zip
  • Screenshots with line 128 NOT commented out.zip

See notes regarding them below.

Modifed iled_blinky project: evkmimxrt1020_iled_blinky_plugin_for_nxp.zip

Files modifed:

  • source/led_blinky.c
  • startup/startup_mimxrt1021.c
  • xip/fsl_flexspi_nor_boot.c
  • xip/fsl_flexspi_nor_boot.h

You will need to define the preprocessor symbol PLUGIN_MODE in MCUXpress project settings. To test, you can omit it and a normal iled_blinky demo should run.

Screenshots with line 128 commented out.zip

The unexpected change to the boot_data fields happens between screenshots

  • 03_at_end_first_call_to_PluginFunction.png
  • 04_second_entry_into_image_PluginFunction.png

Screenshots with line 128 NOT commented out.zip

The unexpected change to the boot_data fields happens between screenshots

  • 04_at_end_first_call_to_PluginFunction.png
  • 05_second_call_into_ResetISR.png

Note that this is an unrealistic setup just to experiment with the plugin functionality.

The plugin and app images are identical, all I am doing is changing the IVT entry field and the plugin flag between the two invocations.

In reality the two images would be in different devices or different places in the same device.

But I need to understand what is going wrong here. Am I doing something daft (other than using an unrealistic setup)?

Kind regards

0 Kudos

61 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi rshipman,

   Thanks for your updated detail information, I will check it on my side, please give me more time.

   Any updated information, I will let you know.

  Please keep patient, thank you!

Best Regards,

Kerry

0 Kudos