FSL Kinetis Bootloader K80 Tools Example Problem

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

FSL Kinetis Bootloader K80 Tools Example Problem

1,137 Views
john_newton
Contributor II

Using:

KDS 3.2.0

FSL_Kinetis_Bootloader_K80_Tools_1_0_0

FRDM K82F

Kinetis Bootloader QuadSPI User's Guide.pdf Rev0

 

Issue Summary:

Using led_demo_qspi example, adding simple code to the example will prevent the device from booting from external flash memory

 

 

Issue Detail:

I have followed the QuadSPI User Guide and built the led_demo_qspi example using KDS 3.2.0 GCC.  I have encrypted the file and programmed the external flash with the encrypted image and the LED flashes as per the example.  All good.

 

I have added code to the main function after the clocks have been switched and the hardware has been initialised.  

 

The code I have added is multiple lines of __asm("nop"); to simplify the issue I am having, same occurs with any other code.

 

Depending on the number of NOP's added will effect if the processor will successfully boot from external flash. 

 

So you will see in the following code snippet that I am executing 8 NOP instructions, this results in the boot sequence resetting the processor as seen by the reset LED on the FRDM board momentarily flashing.  If I add no NOP's the processor boots and correctly flashes the LED's.  If I add 10 NOP's the processor correctly boot's.

 

Again, the is an example project found in the FSL_Kinetis_Bootloader_K80_Tools_1_0_0, the only code I have added is NOP's.  The linker and project settings are all from the example. 

 

I have included my project as an attachment.

 

If any one can help with this I would be very grateful.

 

John

 

 

 

<code>

int main(void)
{
copy_to_ram();
clock_change();
hardware_init();
milliseconds_delay_init();
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Not working
__asm("nop"); //Not working
__asm("nop"); //Not working (reset LED flash)
/*__asm("nop"); //Not working (reset LED flash)
__asm("nop"); //Not working
__asm("nop"); //Not working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Not working
__asm("nop"); //Not working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working

__asm("nop"); //Working
__asm("nop"); //Not working (no reset LED flash)
__asm("nop"); //Not working (no reset LED flash)
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Not working (reset LED flash)
__asm("nop"); //Not working (reset LED flash)
__asm("nop"); //Not working (no reset LED flash)
__asm("nop"); //Not working (no reset LED flash)
__asm("nop"); //Working

__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Working
__asm("nop"); //Not working (no reset LED flash)
__asm("nop"); //Not working (no reset LED flash)
__asm("nop"); //Working
/* */
uint32_t led_idx = LED0;
while(1)
{
led_toggle(led_idx);
milliseconds_delay(1000);
led_toggle(led_idx);
led_idx <<= 1;
if(led_idx > MAX_LED_IDX)
{
led_idx = LED0;
}

// Re-enter bootloader if the bootloader pin is asserted.
if (is_bootloader_pin_asserted())
{
app_enter_bootloader();
}
}
}

</code>

Original Attachment has been moved to: led_demo_qspi_project_export_from_KDS.zip

5 Replies

728 Views
john_newton
Contributor II

The clock_change function was to blame.

 

I copied the clock_change function from:

NXP_Kinetis_Bootloader_2_0_0.zip\NXP_Kinetis_Bootloader_2_0_0\apps\demo_qspi\led_demo\src\led_demo_qspi.c

Everything ok in non-encrypted and encrypted, no NOPs -> 100's of NOP's.

0 Kudos

728 Views
john_newton
Contributor II

I wonder if this is related to the clock_change function.  The reason I ask is that I have out of desparation, commented out the clock_change function and tried upto 12 NOP's, every time the processor boots after programming.  

The processor will still not boot from turning on the power supply.

Ideas???

0 Kudos

728 Views
john_newton
Contributor II

Ok, I have the same issues with the board I designed.

So going back to the FRDM-K82F board, I have performed some more testing to determine what is happening with each added NOP.

I have looked at the boot behaviour whilst adding more NOP's into the vanilla  led_demo_qspi demo included with the FSL_Kinetis_Bootloader_K80_Tools_1_0_0

The NOP's am adding are as follows:

int main(void)
{
  copy_to_ram();
  clock_change();
  hardware_init();
  milliseconds_delay_init();

  __asm("nop");  //Add multiple NOP's

  uint32_t led_idx = LED0;
  while(1)
  {
    led_toggle(led_idx);
    milliseconds_delay(1000);
    led_toggle(led_idx);
    led_idx <<= 1;
    if(led_idx > MAX_LED_IDX)
    {
      led_idx = LED0;
    }
    // Re-enter bootloader if the bootloader pin is asserted.
    if (is_bootloader_pin_asserted())
    {
      app_enter_bootloader();
    }
  }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For every NOP I add, I recompile and regenerate a SB file both encrypted and plain text:

  • For the non-encrypted firmware version the following commands are passed to elftosb to generate the .sb used to program the K82F:
    • elftosb -V -c qspi_image.bd -o plain_image.sb    
    • The following files that are attached to this ticket have been used to generate the .sb file:
      • plain_image.sb
      • qspi_config_block_generator.c and qspi_config_block.bin
  • The non-encrypted firmware version is programmed in to the K82F using the following blhost command sequence
    • blhost -p COM17,115200 -- flash-erase-all-unsecure
    • blhost -p COM17,115200 -- write-memory 0x20000000 qspi_config_block.bin
    • blhost -p COM17,115200 -- configure-quadspi 1 0x20000000
    • blhost -p COM17,115200 -- flash-erase-region 0x68000000 4096
    • blhost -p COM17,115200 -- write-memory 0x68000000 qspi_config_block.bin
    • blhost -p COM17,115200 -- flash-erase-region 0x0 0x800
    • blhost -p COM17,115200 -- write-memory 0x40c {{FEBDFFFF}}
    • blhost -p COM17,115200 -- reset
    • timeout 4
    • blhost -d -V -p COM17,115200 -- receive-sb-file plain_image.sb

  • For the encrypted firmware version the following commands are passed to elftosb to generate the .sb used to program the K82F:
    • elftosb -V -c qspi_image_encrypt.bd -k key.txt -o encrypted_image.sb
    • The following files that are attached to this ticket have been used to generate the .sb file:
      • encrypted_image.sb
      • qspi_config_block_generator.c and qspi_config_block.bin
      • key.txt
    • The encrypted version also need the keys to be programmed, the following commands are passed to elftosb to generate the .sb used to program the K82F keys:
      • elftosb -V -c program_keys.bd -o program_keys.sb
      • The following files that are attached to this ticket have been used to generate the .sb key file:
        • program_keys.bd
  • The encrypted firmware version is programmed in to the K82F using the following blhost command sequence
    • blhost -p COM17,115200 -- flash-erase-all-unsecure
    • blhost -p COM17,115200 -- get-property 12
    • blhost -p COM17,115200 -- write-memory 0x20000000 qspi_config_block.bin
    • blhost -p COM17,115200 -- configure-quadspi 1 0x20000000
    • blhost -p COM17,115200 -- read-memory 0x68000000 16
    • blhost -p COM17,115200 -- flash-erase-region 0x68000000 4096
    • blhost -p COM17,115200 -- write-memory 0x68000000 qspi_config_block.bin
    • blhost -p COM17,115200 -- flash-erase-region 0x0 0x800
    • blhost -p COM17,115200 -- write-memory 0x40c {{febfffff}}
    • blhost -p COM17,115200 -- reset
    • blhost -p COM17,115200 -- read-memory 0x68000000 512
    • blhost -p COM17,115200 -- receive-sb-file program_keys.sb
    • timeout 4
    • blhost -d -V -p COM17,115200 -- receive-sb-file encrypted_image.sb

I am programming the K82F on the FRDM board via the J24, the BlueTooth Header.  The BlueTooth header uses PTC3 and PTC4 (UART1).  I have moved J23 jumper to position 2-3 so I can use SW1 to reset the processor.

The boot scenarios I have tested are as follows:

  1. Will the processor boot after programming the firmware?
  2. Will the processor boot after pressing SW1 with serial dongle connected? 
  3. Will the processor boot after pressing SW1 without serial dongle connected?
  4. Will the processor boot after power cycling with serial dongle connected? 
  5. Will the processor boot after power cycling without serial dongle connected? 

Observations:

1 Will the processor boot after programming the firmware

  • Depending on the number of NOPs added to the code, either the processor would boot or not. 
  • Sometimes the processor would boot using the non-encrypted and would not boot using the encrypted version of firmware using the same number of NOPs. 
  • Sometimes the processor would not boot using the non-encrypted and would boot using the encrypted version of firmware using the same number of NOPs. 
  • Sometimes the processor would boot using the non-encrypted and would boot using the encrypted version of firmware using the same number of NOPs. 
  • Sometimes the processor would not boot using the non-encrypted and would not boot using the encrypted version of firmware using the same number of NOPs. 
  • If the processor did not boot, removing the serial programming cable and touching the Rx pin of UART1 would make the processor boot.
  • When to processor did not boot, it was observed that the RESET Pin strobes every 2.5 seconds for 100us.

2 Will the processor boot after pressing SW1 with serial dongle connected?

  • The result of this test was the same as observation 1

3 Will the processor boot after pressing SW1 without serial dongle connected?

  • The result of this test was the same as observation 1

4 Will the processor boot after power cycling with serial dongle connected? 

  • The result of this test was the same as observation 1

5 Will the processor boot after power cycling without serial dongle connected?

  • The result of this test showed that irrespective of if the firmware was encrypted or not encrypted, and irrelevant of the number of NOP's, the processor would not boot if the power was cycled with the serial dongle not connected.  The processor would enter the bootloader state where by reconnecting the serial dongle, blhost can communicate with the bootloader.

A pattern has emerged based on the number of NOPs added.  See the following table:

 

pastedImage_21.png

 

Summary

Due to the behaviour of the processor during boot and the fact that touching the Rx pin of bootloader UART1 (UART0 and UART2 do the same), I think there is possibly an issue with the K82F ROM bootloader.  I think it would be useful for an NXP to look at this and try and reproduce on the same silicon version 1N03P.  It is possible by touching the Rx pin I am inducing mains hum and effecting the bootloader state machine?

I have seen in the errata for the K82F processor that SPI has an issue with the bootloader, I have disabled SPI in my BCA (.enabledPeripherals = 0x1) and therefore the problem should only isolated to the UART.

The fact that when the FRDM-K82F is powered from a lab power supply (I have tried 2 different ones) and it enters the ROM bootloader when the power is turn on suggests the bootloader peripheral detect has an anomaly during power on or it's a power sequencing of the K82F and External QuadSPI flash.  Perhaps the QuadSPI flash does not initilise in time for the K82F to read the BCA?  

I don't think I have made a mistake in the code as the code is straight from an example provided with the FSL_Kinetis_Bootloader_K80_Tools_1_0_0, it would be very much appreciated if someone who has experience of this processor and booting from external QuadSPI flash could take a look at my project to see if I have made any obvious mistakes.

If any one has a project that they know to work using the FRDM-K82F and QuadSPI that can be built using KDS 3.2.0 that they could send to me so I can verify my hardware, that too would be much appreciated.

John

0 Kudos

728 Views
john_newton
Contributor II

So I have investigated this further. These are my findings:

  • Comparing the list file for working and non-working firmware, every looks good, no alignment problems, entry points look good.
  • Tested the code on two FRDM-K82F boards, both result in same operation.
  • I have been powering the board using a bench PSU at 6V via J3 Pins 14/16 0V/Vin, holding a wire connected to J2 Pin 2 (PTB16 LPUART0_RX) the processor boots most of the time.
  • Powering the board from USB does result in the board booting most of the time.
  • I have been using plain text firmware sb files and loading these in to the K82F using the K82F ROM KBOOT.  Changing to Encrypted firmware SB file, the processor boots and runs the application irrelevant of the number of NOP's.

I have designed my own board using the K82F processor and I have not experienced (YET) any issues with booting.

I am very confused with the FRDM-K82F, has anyone else had booting issues?

0 Kudos

728 Views
UK_CF_FAE
NXP Employee
NXP Employee

Well I would expect that the entry point is changing as the number of NOPs changes. You could check this in the plain-text SREC or the map file: create one working image and find out the entry point. Then create a non-working version. Is the entry point the same? The transfer from the bootloader to the application is likely failing.