Programming both MCUBOOT and Application on flash

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

Programming both MCUBOOT and Application on flash

Jump to solution
9,085 Views
vrg6
Contributor I

Some background:

  • Have access to IAR 6,7,and 8
  • Have access to version 2.0.0 and version 2.5.0 of MCBOOT
  • Using a custom microcontroller board with a K64 chip

   I have began a new project. The goal of this project is to have have MCUBOOT running in the flash memory of a K64 chip. While the bootloader is in the flash I want to have a specialized application running in the background. The intention is to use the bootloader to update and flash the application when needed.

   Both the application and the bootloader have their own .ICF files to map them out to memory. However, in order to have the application and bootloader co-existing, I would need to modify the .ICF files. The Bootloader would have to exist at address 0x000 of the flash memory and the application would have to exist afterwards.

   To give perspective, this project is functionally similar to how you can flash the led_demo program to address 0x0A000 using the bootloader.

   Does anyone know what a good starting place is or if there is a way to automatically generate an .ICF file?

Labels (1)
0 Kudos
Reply
1 Solution
8,467 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   About this area knowledge, please refer to my attached document.

Chapter 4.4 BCA utilities tab page

Chapter 4.5 Bootloader configuration page

  Chapter 5.8 Integrate config file to user project

  If you have time, I suggest you read all the document, you will be clear about it.

  Wish it helps you!


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

View solution in original post

0 Kudos
Reply
19 Replies
8,467 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent Garbonick,

    Do you want to program the bootloader code and the application code together to the K64?

   You can't mix the bootloader and the application code in one project, but you can generate two .hex file, then find some tool to mix two hex file together.

   So, you can't use only one .icf file for both the bootloader the app project.

   You still need to use two projects, different project have different .icf file.

   From my own opinion, you can download the bootloader to the board at first, then use the bootloader to download your app. This is the normal operation.

 Wish it helps you!

If you still have question about it, please kindly let me know.

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
Reply
8,467 Views
vrg6
Contributor I

Hello Kerry! 

   I see what you are saying. I have been able to get the bootloader and the application on the same flash device now by moving the start position of the application down in such a way that it does not overwrite the bootloader. However, the BCA configuration of the application is not recognized by the KinetisFlashTool. Since the BCA start-of-file information is invalid, the application code does not execute properly. Attached is a picture describing what I am saying. BCA-project-data.PNG 

   How would one go about generating proper BCA information for the application so it is recognized by the bootloader and executes properly? 

0 Kudos
Reply
8,467 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent Garbonick,

  If you don't modify the BCA area, the application code works ok or not on your side?

  Do you mean, just when modify the BCA area, the app function can't work?

This is my test result:

pastedImage_3.png

I just disable CAN module, then generate the app again, the code still works OK.

I also attached my app bin file for your reference.

 Wish it helps you!

If you still have question about it, please kindly let me know.

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
Reply
8,467 Views
vrg6
Contributor I

Hello Kerry!

   What I am saying is that when our application does not have BCA information, the bootloader does not recognize the application and boot into it. We cannot get our application to work with the bootloader since it does not have BCA information programmed into the .bin image file. 

   We need to find a way to add BCA information to our custom project so the bootloader recognizes it. 

Thanks for everything,

     Vincent Garbonick

0 Kudos
Reply
8,467 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   If your app don't have the BCA, you can generate the .bin file, then use the KinetisFlashTool to add it automatically.

   Or you in the app source code, just define the BCA area, and add it.

  You also can refer to the KBOOT2.0 k64 APP project:

https://www.nxp.com/webapp/Download?colCode=NXP_KINETIS_BOOTLOADER_2_0_0&appType=license 

Folder: NXP_Kinetis_Bootloader_2_0_0\apps\led_demo\MK64F12

pastedImage_2.png

Wish it helps you!
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
Reply
8,467 Views
vrg6
Contributor I

Hello Kerry! Thank you for all your help so far. I was able to follow the steps as you said, but now I am having trouble properly setting up the linker file in order to accept the bootloader configuration information. I added the bootloader_config.c to my project and changed the start address to 0x000A000. I modified the linker file and have been having errors. 

I attached a picture of the error message and the linker file. Thank you for your continued support. 

image.png

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x0000A000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000 ;
define symbol __ICFEDIT_region_ROM_end__   = 0x000FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0000;
define symbol __ICFEDIT_region_RAM_end__   = 0x2002FFF0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0;
define symbol __ICFEDIT_size_heap__   = 0;
/**** End of ICF editor section. ###ICF###*/

define exported symbol __EXTERNAL_MRAM_ROM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
define exported symbol __EXTERNAL_MRAM_RAM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_RAM_SIZE = 0x00080000;

define exported symbol __EXTERNAL_LCD_BASE      = 0x60000000;
define exported symbol __EXTERNAL_LCD_SIZE      = 0x1FFFF;
define exported symbol __EXTERNAL_LCD_DC_BASE   = 0x60010000;
define exported symbol __INTERNAL_FLASH_BASE    = 0x00000000;
define exported symbol __INTERNAL_FLASH_SIZE    = 0x00100000;
define exported symbol __INTERNAL_SRAM_BASE     = 0x1FFF0000;
define exported symbol __INTERNAL_SRAM_SIZE     = 0x00040000;
define exported symbol __UNCACHED_DATA_START    = 0x1FFF0000;
define exported symbol __UNCACHED_DATA_SIZE     = 0x00020000;
define exported symbol __UNCACHED_DATA_END      = 0x2000FFF0;
define exported symbol __SRAM_POOL              = 0x1FFF0000;

define exported symbol __INTERNAL_FLEXNVM_BASE = 0;
define exported symbol __INTERNAL_FLEXNVM_SIZE = 0;

define exported symbol __VECTOR_TABLE_ROM_START = 0x00000000;
define exported symbol __VECTOR_TABLE_RAM_START = __ICFEDIT_region_RAM_start__;

define exported symbol __DEFAULT_PROCESSOR_NUMBER = 1;
define exported symbol __DEFAULT_INTERRUPT_STACK_SIZE = 1024;

/* mem_init writes a storeblock_struct at the end of kernel data, max size 32 bytes, so use 0x100 offset */
define exported symbol __BOOT_STACK_ADDRESS = __ICFEDIT_region_RAM_end__ - 0x100;


define exported symbol __KERNEL_DATA_END = __ICFEDIT_region_RAM_end__;

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block KERNEL_DATA with alignment = 8 { section .kernel_data };

define exported symbol __FLASHX_SECT_SIZE = 0x1000;
define exported symbol __FLASHX_END_ADDR = __INTERNAL_FLASH_BASE + __INTERNAL_FLASH_SIZE;

define symbol m_bootloader_config_start = __ICFEDIT_intvec_start__ + 0x3C0;
define symbol m_bootloader_config_end = __ICFEDIT_intvec_start__ + 0x3FF;
define region m_bootloader_config_region = mem:[from m_bootloader_config_start to m_bootloader_config_end];

define block CFMPROTROM with size = 20 { section .cfmconfig };
define block FLASHX_POOL with alignment = __FLASHX_SECT_SIZE { section .flashx };
define block TEXTSECTION with alignment = 4 { section .text };

keep { section .cfmconfig };
keep { section .flashx };

initialize by copy { readwrite };
do not initialize  { section .noinit };
do not initialize  { section .kernel_data };
do not initialize  { section .flashx };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, block CFMPROTROM };
place in m_bootloader_config_region{ section .bootloaderconfig };
place in ROM_region { first block TEXTSECTION, readonly,  last block FLASHX_POOL };

place at address mem:__ICFEDIT_region_RAM_start__ { readwrite section .vectors_ram };

/* each block/segment must be in one line (association to region) because I need kernel data start after other datas */
place in RAM_region   { readwrite, last block KERNEL_DATA };
0 Kudos
Reply
8,467 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   What's the code you put in bootloader_config.c ?

  Why you define the cstack as 0?

  Could you also share the linker file before your modification, and which don't have the build problems?


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
Reply
8,467 Views
vrg6
Contributor I

Hi Kerry. Thanks again for all the help. 

ORIGINAL LINKER FILE 

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000 ;
define symbol __ICFEDIT_region_ROM_end__   = 0x000FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0000;
define symbol __ICFEDIT_region_RAM_end__   = 0x2002FFF0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0;
define symbol __ICFEDIT_size_heap__   = 0;
/**** End of ICF editor section. ###ICF###*/
define exported symbol __EXTERNAL_MRAM_ROM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
define exported symbol __EXTERNAL_MRAM_RAM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_RAM_SIZE = 0x00080000;
define exported symbol __EXTERNAL_LCD_BASE      = 0x60000000;
define exported symbol __EXTERNAL_LCD_SIZE      = 0x1FFFF;
define exported symbol __EXTERNAL_LCD_DC_BASE   = 0x60010000;
define exported symbol __INTERNAL_FLASH_BASE    = 0x00000000;
define exported symbol __INTERNAL_FLASH_SIZE    = 0x00100000;
define exported symbol __INTERNAL_SRAM_BASE     = 0x1FFF0000;
define exported symbol __INTERNAL_SRAM_SIZE     = 0x00040000;
define exported symbol __UNCACHED_DATA_START    = 0x1FFF0000;
define exported symbol __UNCACHED_DATA_SIZE     = 0x00020000;
define exported symbol __UNCACHED_DATA_END      = 0x2000FFF0;
define exported symbol __SRAM_POOL              = 0x1FFF0000;
define exported symbol __INTERNAL_FLEXNVM_BASE = 0;
define exported symbol __INTERNAL_FLEXNVM_SIZE = 0;
define exported symbol __VECTOR_TABLE_ROM_START = 0x00000000;
define exported symbol __VECTOR_TABLE_RAM_START = __ICFEDIT_region_RAM_start__;
define exported symbol __DEFAULT_PROCESSOR_NUMBER = 1;
define exported symbol __DEFAULT_INTERRUPT_STACK_SIZE = 1024;
/* mem_init writes a storeblock_struct at the end of kernel data, max size 32 bytes, so use 0x100 offset */
define exported symbol __BOOT_STACK_ADDRESS = __ICFEDIT_region_RAM_end__ - 0x100;
define exported symbol __KERNEL_DATA_END = __ICFEDIT_region_RAM_end__;
define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];
define block KERNEL_DATA with alignment = 8 { section .kernel_data };
define exported symbol __FLASHX_SECT_SIZE = 0x1000;
define exported symbol __FLASHX_END_ADDR = __INTERNAL_FLASH_BASE + __INTERNAL_FLASH_SIZE;
define block CFMPROTROM with size = 20 { section .cfmconfig };
define block FLASHX_POOL with alignment = __FLASHX_SECT_SIZE { section .flashx };
define block TEXTSECTION with alignment = 4 { section .text };
keep { section .cfmconfig };
keep { section .flashx };
initialize by copy { readwrite };
do not initialize  { section .noinit };
do not initialize  { section .kernel_data };
do not initialize  { section .flashx };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, block CFMPROTROM };
place in ROM_region { first block TEXTSECTION, readonly,  last block FLASHX_POOL };
place at address mem:__ICFEDIT_region_RAM_start__ { readwrite section .vectors_ram };
/* each block/segment must be in one line (association to region) because I need kernel data start after other datas */
place in RAM_region   { readwrite, last block KERNEL_DATA };

BOOTLOADER_CONFIG.C

/*
* Copyright (c) 2013 - 15, Freescale Semiconductor, Inc.
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without modification,
*are permitted provided that the following conditions are met :
*
* o Redistributions of source code must retain the above copyright notice, this list
*   of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
*   list of conditions and the following disclaimer in the documentation and / or
*   other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
*   contributors may be used to endorse or promote products derived from this
*   software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*!
* @brief Device specific configuration file for Kinetis bootloader
*
* Provides a bootloader configuration structure and a global variable that
* contains
* the system bootloader configuration data.
*/

#include <stdint.h>

/*!
* @brief Defines the structure to set the Bootloader Configuration Area
*
* This type of variable is used to set the Bootloader Configuration Area
* of the chip.
*
* Warning: some configuration may not work on the devices that donot support 
* corresponding feature.
*/
typedef struct BootloaderConfiguration
{
    uint32_t tag; //!< [00:03] Magic number to verify bootloader configuration is
                  //! valid. Must be set to 'kcfg'.
    uint32_t crcStartAddress; //!< [04:07] Start address for application image CRC
                              //! check. If the bits are all set then Kinetis
                              //! bootloader by default will not perform any CRC 
                              //! check.
    uint32_t crcByteCount; //!< [08:0b] Byte count for application image CRC
                           //! check. If the bits are all set then Kinetis
                           //! bootloader by default will not prform any CRC check.
    uint32_t crcExpectedValue; //!< [0c:0f] Expected CRC value for application CRC
                               //! check. If the bits are all set then Kinetis
                               //! bootloader by default will not perform any CRC
                               //! check.
    uint8_t enabledPeripherals; //!< [10:10] Bitfield of peripherals to enable.
                                //! bit 0 - LPUART, bit 1 - I2C, bit 2 - SPI,
                                //! bit 3 - CAN, bit 4 - USB
                                //! Kinetis bootloader will enable the peripheral if
                                //! corresponding bit is set to 1.
    uint8_t i2cSlaveAddress; //!< [11:11] If not 0xFF, used as the 7-bit I2C slave
                             //! address. If 0xFF, defaults to 0x10
                             //! for I2C slave address.
    uint16_t peripheralDetectionTimeoutMs; //!< [12:13] Timeout in milliseconds
                                           //! for active peripheral detection. If
                                           //! 0xFFFF, defaults to 5 seconds.
    uint16_t usbVid; //!< [14:15] Sets the USB Vendor ID reported by the device
                     //! during enumeration. If 0xFFFF, it defaults to 0x15A2.
    uint16_t usbPid; //!< [16:17] Sets the USB Product ID reported by the device
                     //! during enumeration.
    uint32_t usbStringsPointer; //!< [18:1b] Sets the USB Strings reported by the
                                //! device during enumeration.
    uint8_t clockFlags; //!< [1c:1c] The flags in the clockFlags configuration
                        //! field are enabled if the corresponding bit is cleared (0).
                        //! bit 0 - HighSpeed Enable high speed mode (i.e., 48 MHz).
    uint8_t clockDivider; //!< [1d:1d] Inverted value of the divider to use for
                          //! core and bus clocks when in high speed mode.
    uint8_t bootFlags; //!< [1e:1e] If bit 0 is cleared, then Kinetis bootloader
                       //! will jump to either Quad SPI Flash or internal flash
                       //! image depending on FOPT BOOTSRC_SEL bits.
                       //! If the bit is set, then Kinetis bootloader will prepare
                       //! for host communication over serial peripherals.
    uint8_t pad0; //!< [1f:1f] Reserved, set to 0xFF
    uint32_t mmcauConfigPointer; //!< [20:23] A pointer to the MMCAU configuration
                                 //! structure in memory.
    uint32_t keyBlobPointer; //!< [24:27]Holds a pointer value to the key blob
                             //! array used to configure OTFAD
    uint8_t pad1; //!< [28:28] reserved
    uint8_t canConfig1; //!< [29:29] ClkSel[1], PropSeg[3], SpeedIndex[4]
    uint16_t canConfig2; //!< [2a:2b] Pdiv[8], Pseg1[3], Pseg2[3],  rjw[2]
    uint16_t canTxId; //!< [2c:2d] txId
    uint16_t canRxId; //!< [2e:2f] rxId
    uint32_t qspi_config_block_pointer; //!< [30:33] A pointer to the QSPI config
                                        //! block in internal flash array.
    uint32_t reserved[3]; //!<[34:3f] reserved
} bootloader_config_t;

/*
* Warning: To enable bootloader configuration, User still needs two extra steps :
*
*   Step1 : Enable BOOTLOADER_CONFIG.
*   Example : #define BOOTLOADER_CONFIG 1
*
*   Step2 : Add configuration of the section "BootloaderConfig" to your
*   linker configuration file.
*   Example(IAR) :
*       define symbol __application_startaddress = 0; // User-defined
*       define symbol m_bootloader_config_start = __application_startaddress + 0x3C0;
*       define symbol m_bootloader_config_end = __application_startaddress + 0x3FF;
*       define region m_bootloader_config_region = mem:[from m_bootloader_config_start to m_bootloader_config_end];
*       place in m_bootloader_config_region{ section BootloaderConfig };
*
*   Example(Keil) :
*       #define __application_startaddress = 0 // User-defined
*       #define m_bootloader_config_start      __application_startaddress + 0x3C0
*       #define m_bootloader_config_size       0x00000040
*
*       LR_m_bootloader_config m_bootloader_config_start m_bootloader_config_size{
*         ER_m_bootloader_config m_bootloader_config_start m_bootloader_config_size{ ; load address = execution address
*           * (BootloaderConfig)
*         }
*       }
*
*   Example(ARM - GCC) :
*       MEMORY
*       {
*           m_bootloader_config(RX) : ORIGIN = 0x000003C0, LENGTH = 0x00000040
*       }
*       .bootloader_config :
*       {
*           . = ALIGN(4);
*           KEEP(*(.BootloaderConfig)) // Bootloader Configuration Area (BCA)
*           . = ALIGN(4);
*       } > m_bootloader_config
*
*/

#ifdef BOOTLOADER_CONFIG
/* Bootlader configuration area */
#if defined(__IAR_SYSTEMS_ICC__)
/* Pragma to place the Bootloader Configuration Array on correct location
* defined in linker file. */
#pragma language = extended
#pragma location = "BootloaderConfig"
__root const bootloader_config_t BootloaderConfig @"BootloaderConfig" =
#elif defined(__GNUC__)
__attribute__((section(".BootloaderConfig"))) const bootloader_config_t BootloaderConfig =
#elif defined(__CC_ARM)
__attribute__((section("BootloaderConfig"))) const bootloader_config_t BootloaderConfig __attribute__((used)) =
#else
#error Unsupported compiler!
#endif
    {
        .tag = 0x6766636B, //!< Magic Number
        .crcStartAddress = 0xFFFFFFFF, //!< Disable CRC check
        .crcByteCount = 0xFFFFFFFF, //!< Disable CRC check
        .crcExpectedValue = 0xFFFFFFFF, //!< Disable CRC check
        .enabledPeripherals = 0xE7, //!< Enabled Peripheral: UART I2C SPI 
        .i2cSlaveAddress = 0xD5, //!< Use user-defined I2C address
        .peripheralDetectionTimeoutMs = 0x1388, //!< Use user-defined timeout(ms)
        .usbVid = 0xFFFF, //!< Use default Vendor ID(0x15A2)
        .usbPid = 0xFFFF, //!< Use default Product ID(0x0073)
        .usbStringsPointer = 0xFFFFFFFF, //!< Use default USB String
        .clockFlags = 0xFF, //!< Disable High speed mode
        .clockDivider = 0xFF, //!< Use clock divider(0)
        .bootFlags = 0xFE, //!< Enable direct boot
        .mmcauConfigPointer = 0x0009D5A1, //!< MMCAU configuration is available
        .keyBlobPointer = 0x0009D5A1, //!< Key blob is available
        .canConfig1 = 0xFF, //!< Use default canConfig1
        .canConfig2 = 0xFFFF, //!< Use default canConfig2
        .canTxId = 0xFFFF, //!< Use default CAN TX ID(0x123)
        .canRxId = 0xFFFF, //!< Use default CAN RX ID(0x321)
        .qspi_config_block_pointer = 0x0009D5A1, //!< QSPI configuration is available
    };
#endif

I do not know why I set cstack to zero.

Thanks, 

    Vincent

0 Kudos
Reply
8,469 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   If you don't add the bootloader_config.c , and relocate your code to 0xa000, do you have the build linker errors?

   If you are convenient, you can share me your project which can reproduce the problem. You can deleted all the important code to you, just leave the project which can reproduce the problem.


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
Reply
8,469 Views
vrg6
Contributor I

Hello Kerry,

   I am not able to post the full project because it is proprietary in nature at the moment. 

   When the bootloader_config.c code is not included, the code still gives the same error, which leads me to believe is is an issue with the linker file.

0 Kudos
Reply
8,469 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vicent,

   I understand you can't post the project.

   If you don't add the bootloader_config.c , it means your linker file modification have problems.

   Now, please modify your problem linker file like this:

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x0000A000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x0000A000 ;
define symbol __ICFEDIT_region_ROM_end__   = 0x000FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0000;
define symbol __ICFEDIT_region_RAM_end__   = 0x2002FFF0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0;
define symbol __ICFEDIT_size_heap__   = 0;
/**** End of ICF editor section. ###ICF###*/

define exported symbol __EXTERNAL_MRAM_ROM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
define exported symbol __EXTERNAL_MRAM_RAM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_RAM_SIZE = 0x00080000;

define exported symbol __EXTERNAL_LCD_BASE      = 0x60000000;
define exported symbol __EXTERNAL_LCD_SIZE      = 0x1FFFF;
define exported symbol __EXTERNAL_LCD_DC_BASE   = 0x60010000;
define exported symbol __INTERNAL_FLASH_BASE    = 0x00000000;
define exported symbol __INTERNAL_FLASH_SIZE    = 0x00100000;
define exported symbol __INTERNAL_SRAM_BASE     = 0x1FFF0000;
define exported symbol __INTERNAL_SRAM_SIZE     = 0x00040000;
define exported symbol __UNCACHED_DATA_START    = 0x1FFF0000;
define exported symbol __UNCACHED_DATA_SIZE     = 0x00020000;
define exported symbol __UNCACHED_DATA_END      = 0x2000FFF0;
define exported symbol __SRAM_POOL              = 0x1FFF0000;

define exported symbol __INTERNAL_FLEXNVM_BASE = 0;
define exported symbol __INTERNAL_FLEXNVM_SIZE = 0;

define exported symbol __VECTOR_TABLE_ROM_START = 0x0000A000;
define exported symbol __VECTOR_TABLE_RAM_START = __ICFEDIT_region_RAM_start__;

define exported symbol __DEFAULT_PROCESSOR_NUMBER = 1;
define exported symbol __DEFAULT_INTERRUPT_STACK_SIZE = 1024;

/* mem_init writes a storeblock_struct at the end of kernel data, max size 32 bytes, so use 0x100 offset */
define exported symbol __BOOT_STACK_ADDRESS = __ICFEDIT_region_RAM_end__ - 0x100;


define exported symbol __KERNEL_DATA_END = __ICFEDIT_region_RAM_end__;

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block KERNEL_DATA with alignment = 8 { section .kernel_data };

define exported symbol __FLASHX_SECT_SIZE = 0x1000;
define exported symbol __FLASHX_END_ADDR = __INTERNAL_FLASH_BASE + __INTERNAL_FLASH_SIZE;
/*
define symbol m_bootloader_config_start = __ICFEDIT_intvec_start__ + 0x3C0;
define symbol m_bootloader_config_end = __ICFEDIT_intvec_start__ + 0x3FF;
define region m_bootloader_config_region = mem:[from m_bootloader_config_start to m_bootloader_config_end];
*/
define block CFMPROTROM with size = 20 { section .cfmconfig };
define block FLASHX_POOL with alignment = __FLASHX_SECT_SIZE { section .flashx };
define block TEXTSECTION with alignment = 4 { section .text };

keep { section .cfmconfig };
keep { section .flashx };

initialize by copy { readwrite };
do not initialize  { section .noinit };
do not initialize  { section .kernel_data };
do not initialize  { section .flashx };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, block CFMPROTROM };
place in m_bootloader_config_region{ section .bootloaderconfig };
place in ROM_region { first block TEXTSECTION, readonly,  last block FLASHX_POOL };

place at address mem:__ICFEDIT_region_RAM_start__ { readwrite section .vectors_ram };

/* each block/segment must be in one line (association to region) because I need kernel data start after other datas */
place in RAM_region   { readwrite, last block KERNEL_DATA };

About the BCA area add, you totally can add it in the startup_MK64F12.s

#ifdef BL_HAS_BOOTLOADER_CONFIG

__bootloaderConfigurationArea ; 0x3c0
        DCD     'kcfg'        ; [00:03] tag - Tag value used to validate the bootloader configuration data. Must be set to 'kcfg'.
        DCD     0xFFFFFFFF    ; [04:07] crcStartAddress
        DCD     0xFFFFFFFF    ; [08:0b] crcByteCount
        DCD     0xFFFFFFFF    ; [0c:0f] crcExpectedValue
        DCB     0xFF          ; [10:10] enabledPeripherals
        DCB     0xFF          ; [11:11] i2cSlaveAddress
        DCW     5000           ; [12:13] peripheralDetectionTimeoutMs - Timeout in milliseconds for peripheral detection before jumping to application code
        DCW     0xFFFF        ; [14:15] usbVid
        DCW     0xFFFF        ; [16:17] usbPid
        DCD     0xFFFFFFFF    ; [18:1b] usbStringsPointer
        DCB     0xFF          ; [1c:1c] clockFlags - High Speed and other clock options
        DCB     0xFF          ; [1d:1d] clockDivider - One's complement of clock divider, zero divider is divide by 1
        DCW     0xFFFF        ; [1e:1f] reserved
        ; Fill to align with flash configuration field.
        REPT    (0x400-0x3e0)/4   ; 0x3E0 - 0x3FF
        DCD     0xFFFFFFFF        ; Reserved for user TRIM value
        ENDR
#else        
        ; Fill to align with flash configuration field.
        REPT    (0x400-0x3c0)/4 ; 0x3c0:0x400
        DCD     0xFFFFFFFF      ; Reserved for user TRIM value
        ENDR
#endif // BL_HAS_BOOTLOADER_CONFIG

I also attach the .s file.


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
Reply
8,469 Views
vrg6
Contributor I

Hello Kerry,

The startup.s code was already in the bootloader project. That is not the issue however. The BCA area is defined in the linker file and the bootloader_config.c file is included in the application project. When I check the map file, the issue becomes apparent. The BCA information should be placed right after .intvec start, but instead it is appearing at an improper address (0x000bf5f8).

I have tried explicitly telling the linker file where to place the application code to no avail. Attached are images of the map file and the linker file used. The red boxed area is where the BCA area SHOULD be. The second photo is where the bootloader_config.c is ACTUALLY showing up. 

pastedImage_1.pngpastedImage_2.png

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x0000A000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x0000A000 ;
define symbol __ICFEDIT_region_ROM_end__   = 0x000FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0000;
define symbol __ICFEDIT_region_RAM_end__   = 0x2002FFF0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0;
define symbol __ICFEDIT_size_heap__   = 0;
/**** End of ICF editor section. ###ICF###*/

define exported symbol __EXTERNAL_MRAM_ROM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_ROM_SIZE = 0x0000A000;
define exported symbol __EXTERNAL_MRAM_RAM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_RAM_SIZE = 0x00080000;

define exported symbol __EXTERNAL_LCD_BASE      = 0x60000000;
define exported symbol __EXTERNAL_LCD_SIZE      = 0x1FFFF;
define exported symbol __EXTERNAL_LCD_DC_BASE   = 0x60010000;
define exported symbol __INTERNAL_FLASH_BASE    = 0x0000A000;
define exported symbol __INTERNAL_FLASH_SIZE    = 0x00100000;
define exported symbol __INTERNAL_SRAM_BASE     = 0x1FFF0000;
define exported symbol __INTERNAL_SRAM_SIZE     = 0x00040000;
define exported symbol __UNCACHED_DATA_START    = 0x1FFF0000;
define exported symbol __UNCACHED_DATA_SIZE     = 0x00020000;
define exported symbol __UNCACHED_DATA_END      = 0x2000FFF0;
define exported symbol __SRAM_POOL              = 0x1FFF0000;

define exported symbol __INTERNAL_FLEXNVM_BASE = 0;
define exported symbol __INTERNAL_FLEXNVM_SIZE = 0;

define exported symbol __VECTOR_TABLE_ROM_START = 0x0000A000;
define exported symbol __VECTOR_TABLE_RAM_START = __ICFEDIT_region_RAM_start__;

define exported symbol __DEFAULT_PROCESSOR_NUMBER = 1;
define exported symbol __DEFAULT_INTERRUPT_STACK_SIZE = 1024;

/* mem_init writes a storeblock_struct at the end of kernel data, max size 32 bytes, so use 0x100 offset */
define exported symbol __BOOT_STACK_ADDRESS = __ICFEDIT_region_RAM_end__ - 0x100;


define exported symbol __KERNEL_DATA_END = __ICFEDIT_region_RAM_end__;

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block KERNEL_DATA with alignment = 8 { section .kernel_data };

define exported symbol __FLASHX_SECT_SIZE = 0x1000;
define exported symbol __FLASHX_END_ADDR = __INTERNAL_FLASH_BASE + __INTERNAL_FLASH_SIZE;

define symbol m_bootloader_config_start = __ICFEDIT_intvec_start__ + 0x3C0;
define symbol m_bootloader_config_end = __ICFEDIT_intvec_start__ + 0x3FF;
define region m_bootloader_config_region = mem:[from m_bootloader_config_start to m_bootloader_config_end];

define block CFMPROTROM with size = 20 { section .cfmconfig };
define block FLASHX_POOL with alignment = __FLASHX_SECT_SIZE { section .flashx };
define block TEXTSECTION with alignment = 4 { section .text };

keep { section .cfmconfig };
keep { section .flashx };

initialize by copy { readwrite };
do not initialize  { section .noinit };
do not initialize  { section .kernel_data };
do not initialize  { section .flashx };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, block CFMPROTROM };
place in m_bootloader_config_region{ section .bootloaderconfig };
place in ROM_region { first block TEXTSECTION, readonly,  last block FLASHX_POOL };

place at address mem:__ICFEDIT_region_RAM_start__ { readwrite section .vectors_ram };

/* each block/segment must be in one line (association to region) because I need kernel data start after other datas */
place in RAM_region   { readwrite, last block KERNEL_DATA };
0 Kudos
Reply
8,469 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   I know you already define the .s, that's why I let you define the BCA area in the .s directly, just like our bootloader app sample code startup_MK64F12.s, this method will allocate the BCA area in the correct address.

   You can try it on your side.

    I think your problem still in the IAR function detail address allocation side.

   Please try the official startup_MK64F12.s on your side, and don't use your bootloader_config.c.

Whether it works ok or not?
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
Reply
8,469 Views
vrg6
Contributor I

Hello Kerry,

I add the startup_config.s file to my application project. However, when I compile the project I get the following errors.

pastedImage_2.png

 This is the assembly code I am using 

pastedImage_3.png

This is the linker I am using 

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x0000A000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x0000A000 ;
define symbol __ICFEDIT_region_ROM_end__   = 0x000FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x1FFF0000;
define symbol __ICFEDIT_region_RAM_end__   = 0x2002FFF0;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0;
define symbol __ICFEDIT_size_heap__   = 0;
/**** End of ICF editor section. ###ICF###*/

define exported symbol __EXTERNAL_MRAM_ROM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
define exported symbol __EXTERNAL_MRAM_RAM_BASE = 0x60000000;
define exported symbol __EXTERNAL_MRAM_RAM_SIZE = 0x00080000;

define exported symbol __EXTERNAL_LCD_BASE      = 0x60000000;
define exported symbol __EXTERNAL_LCD_SIZE      = 0x1FFFF;
define exported symbol __EXTERNAL_LCD_DC_BASE   = 0x60010000;
define exported symbol __INTERNAL_FLASH_BASE    = 0x00000000;
define exported symbol __INTERNAL_FLASH_SIZE    = 0x00100000;
define exported symbol __INTERNAL_SRAM_BASE     = 0x1FFF0000;
define exported symbol __INTERNAL_SRAM_SIZE     = 0x00040000;
define exported symbol __UNCACHED_DATA_START    = 0x1FFF0000;
define exported symbol __UNCACHED_DATA_SIZE     = 0x00020000;
define exported symbol __UNCACHED_DATA_END      = 0x2000FFF0;
define exported symbol __SRAM_POOL              = 0x1FFF0000;

define exported symbol __INTERNAL_FLEXNVM_BASE = 0;
define exported symbol __INTERNAL_FLEXNVM_SIZE = 0;

define exported symbol __VECTOR_TABLE_ROM_START = 0x0000A000;
define exported symbol __VECTOR_TABLE_RAM_START = __ICFEDIT_region_RAM_start__;

define exported symbol __DEFAULT_PROCESSOR_NUMBER = 1;
define exported symbol __DEFAULT_INTERRUPT_STACK_SIZE = 1024;

/* mem_init writes a storeblock_struct at the end of kernel data, max size 32 bytes, so use 0x100 offset */
define exported symbol __BOOT_STACK_ADDRESS = __ICFEDIT_region_RAM_end__ - 0x100;


define exported symbol __KERNEL_DATA_END = __ICFEDIT_region_RAM_end__;

define memory mem with size = 4G;
define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block KERNEL_DATA with alignment = 8 { section .kernel_data };

define exported symbol __FLASHX_SECT_SIZE = 0x1000;
define exported symbol __FLASHX_END_ADDR = __INTERNAL_FLASH_BASE + __INTERNAL_FLASH_SIZE;
/*
define symbol m_bootloader_config_start = __ICFEDIT_intvec_start__ + 0x3C0;
define symbol m_bootloader_config_end = __ICFEDIT_intvec_start__ + 0x3FF;
define region m_bootloader_config_region = mem:[from m_bootloader_config_start to m_bootloader_config_end];
*/
define block CFMPROTROM with size = 20 { section .cfmconfig };
define block FLASHX_POOL with alignment = __FLASHX_SECT_SIZE { section .flashx };
define block TEXTSECTION with alignment = 4 { section .text };

keep { section .cfmconfig };
keep { section .flashx };

initialize by copy { readwrite };
do not initialize  { section .noinit };
do not initialize  { section .kernel_data };
do not initialize  { section .flashx };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, block CFMPROTROM };
place in m_bootloader_config_region{ section .bootloaderconfig };
place in ROM_region { first block TEXTSECTION, readonly,  last block FLASHX_POOL };

place at address mem:__ICFEDIT_region_RAM_start__ { readwrite section .vectors_ram };

/* each block/segment must be in one line (association to region) because I need kernel data start after other datas */
place in RAM_region   { readwrite, last block KERNEL_DATA };‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
Reply
8,469 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   You can delete all the important code to you, still use your original project without the .s modification, then delete all the API function important to you, just give me the simple project, I will help you to check it on my side.

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
Reply
8,469 Views
vrg6
Contributor I

Hello Kerry! 

I have good news. The startup_config.s file you shared works correctly in the application code! 

pastedImage_1.png

However the problem now is that I don't know how to further configure the bootloader options. I would like to enable the "tag" "direct boot" and "timeout" options but do not know how to begin editing the startup_config.s file. 

__bootloaderConfigurationArea ; 0x3c0
        DCD     'kcfg'        ; [00:03] tag - Tag value used to validate the bootloader configuration data. Must be set to 'kcfg'.
        DCD     0xFFFFFFFF    ; [04:07] crcStartAddress
        DCD     0xFFFFFFFF    ; [08:0b] crcByteCount
        DCD     0xFFFFFFFF    ; [0c:0f] crcExpectedValue
        DCB     0xFF          ; [10:10] enabledPeripherals
        DCB     0xFF          ; [11:11] i2cSlaveAddress
        DCW     5000           ; [12:13] peripheralDetectionTimeoutMs - Timeout in milliseconds for peripheral detection before jumping to application code
        DCW     0xFFFF        ; [14:15] usbVid
        DCW     0xFFFF        ; [16:17] usbPid
        DCD     0xFFFFFFFF    ; [18:1b] usbStringsPointer
        DCB     0xFF          ; [1c:1c] clockFlags - High Speed and other clock options
        DCB     0xFF          ; [1d:1d] clockDivider - One's complement of clock divider, zero divider is divide by 1
        DCW     0xFFFF        ; [1e:1f] reserved
        ; Fill to align with flash configuration field. 
        REPT    (0x400-0x3e0)/4   ; 0x3E0 - 0x3FF
        DCD     0xFFFFFFFF        ; Reserved for user TRIM value
        ENDR 
#else        
        ; Fill to align with flash configuration field. 
        REPT    (0x400-0x3c0)/4 ; 0x3c0:0x400
        DCD     0xFFFFFFFF      ; Reserved for user TRIM value
        ENDR
#endif // BL_HAS_BOOTLOADER_CONFIG

Thank you for everything! 

0 Kudos
Reply
8,469 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   Thank you for your updated information.

   You can delete the following yellow area, then build again, then check your .hex file, you will find the according tag area:

pastedImage_1.png

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
Reply
8,469 Views
vrg6
Contributor I

Hi Kerry,

That's not really what I meant. I was wondering how you could set these options

pastedImage_1.png

in startup_config.s code. I don't know how I would go about changing the hex values in a way that affects the BCA information. 

Thanks, 

Vincent 

0 Kudos
Reply
8,468 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Vincent,

   About this area knowledge, please refer to my attached document.

Chapter 4.4 BCA utilities tab page

Chapter 4.5 Bootloader configuration page

  Chapter 5.8 Integrate config file to user project

  If you have time, I suggest you read all the document, you will be clear about it.

  Wish it helps you!


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
Reply