serious issue when using IAR

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at https://www.dialog-semiconductor.com/support . We’ll be fixing bugs / optimising the searching and tagging over the coming days.
9 posts / 0 new
Last post
kevinchen_sz
Offline
Last seen: 2 months 3 weeks ago
Joined: 2017-12-06 09:24
serious issue when using IAR

Hi,

i'm using IAR(8.11.1)  to develop.

I found a serious issue that some values always be changed when booting.

Finally I find the code which break the RAM:

void arch_rom_init(void)
{
#if defined (__DA14531__) && (!USE_CHACHA20_RAND)
    // Store value of _rand_state stdlib/rand.c RW variable
    uint32_t rand_temp = _rand_state_ROM_DATA;
#endif
    test1 = DB_HEAP_BASE;
    test2 = RAM_UNINIT_START_ADDRESS;
    test3 = RAM_UNINIT_END_ADDRESS - RAM_UNINIT_START_ADDRESS;
    test4 = (__section_begin(".heap_db_area"));
    test5 = RET_MEM_BASE;

#if defined (__DA14531__) && (USE_TRNG)
    // Given that the DA14531 secondary bootloader and flash programmer
    // (UART version) leaves untouched the memory area between
    // RAM_UNINIT_START_ADDRESS and RAM_UNINIT_END_ADDRESS address,
    // this memory area can be used to feed the TRNG buffer with
    // true random data (random values after RAM block power up).
    // The maximum size of the TRNG buffer is the difference between the
    // RAM_UNINIT_END_ADDRESS and RAM_UNINIT_START_ADDRESS.
    //
    // Note: The maximum TRNG buffer size should be recalculated
    //       if the application uses the Free Area region (check the
    //       scatter file). In any case, if the used TRNG buffer size is
    //       small enough, the TRNG algorithm will operate with true random
    //       data independently to the maximum size used in the following
    //       memory copy. For further details check the SDK6 documentation.
    if (trng_state_val != 0x12348765)
    {
        memcpy((uint8_t *) DB_HEAP_BASE,
               (uint8_t *) RAM_UNINIT_START_ADDRESS,
               RAM_UNINIT_END_ADDRESS - RAM_UNINIT_START_ADDRESS);
    } 
#endif

when first boot,the TRNG is enabled and here will do copy to DB_HEAP_BASE.

but i find in boot.h ,all the definitions are compiled to 0.(on keil project,it contains the right address)

at address 0,it contains the address of <heap_mem_area_not_ret>.(remapped at 0?)

Then data start from <heap_mem_area_not_ret> are all be overwritten ,then cause crash.

/**
 ****************************************************************************************
 *
 * @file boot.h
 *
 * @brief This file contains the declarations of the boot related variables.
 *
 * Copyright (C) 2019-2020 Dialog Semiconductor.
 * This computer program includes Confidential, Proprietary Information
 * of Dialog Semiconductor. All Rights Reserved.
 *
 ****************************************************************************************
 */

#ifndef _BOOT_H_
#define _BOOT_H_

#include <stdint.h>

extern const uint32_t __ER_IROM3_BASE__[];
#define CODE_AREA_BASE      ((uint32_t)__ER_IROM3_BASE__)

extern const uint32_t __ER_IROM3_LENGTH__[];
#define CODE_AREA_LENGTH    ((uint32_t)__ER_IROM3_LENGTH__)

#pragma section = ".retention_mem_area_uninit"
#define RET_MEM_BASE        (*(uint32_t*)(__section_begin(".retention_mem_area_uninit")))

#pragma section = ".heap_mem_area_not_ret"
#define NON_RET_HEAP_BASE   (*(uint32_t*)(__section_begin(".heap_mem_area_not_ret")))

#define NON_RET_HEAP_END    (*(uint32_t*)(__section_end(".heap_mem_area_not_ret")))

#define NON_RET_HEAP_LENGTH (NON_RET_HEAP_END - NON_RET_HEAP_BASE)

#pragma section = ".heap_db_area"
#define DB_HEAP_BASE        (*(uint32_t*)(__section_begin(".heap_db_area")))

#define DB_HEAP_END         (*(uint32_t*)(__section_end(".heap_db_area")))

#define DB_HEAP_LENGTH (DB_HEAP_END - DB_HEAP_BASE)

#endif // _BOOT_H_

Futher more,

even if the address is right,

how can it promise the section[heap_db_area] is bigger than (RAM_UNINIT_END_ADDRESS - RAM_UNINIT_START_ADDRESS)?

it is still a risk if the compiler put some initialed variables after secton[heap_db_area].

Device: 
PM_Dialog
Offline
Last seen: 7 months 1 week ago
Staff
Joined: 2018-02-08 11:03
Hi kevinchen_sz,

Hi kevinchen_sz,

Apologies for the late response and happy new year. Can you please indicate if you are using the prox_reporter IAR project from the SDK to replicate this issue? I mean project that is located in projects\target_apps\ble_examples\prox_reporter\IAR SDK path.

Thanks, PM_Dialog

kevinchen_sz
Offline
Last seen: 2 months 3 weeks ago
Joined: 2017-12-06 09:24
yes.it is prox_reporter\IAR.

yes.it is prox_reporter\IAR.

but i think it has nothing to do with the application code.

The code using these defination from compiler is located in the system init or sleep handler functions.

 

PM_Dialog
Offline
Last seen: 7 months 1 week ago
Staff
Joined: 2018-02-08 11:03
Hi kevinchen_sz,

Hi kevinchen_sz,

Are you using the project as provided by the SDK? The prox_reporter\IAR should work out of the box and as provided by the SDK. Please try it with a clear SDK directory.

>>Finally I find the code which break the RAM:

Do you mean that you ran in with the debugger attached and the project got crashed?

If you could provide some extra information/screenshots on this issue, it would be very helpful.

Thanks, PM_Dialog

kevinchen_sz
Offline
Last seen: 2 months 3 weeks ago
Joined: 2017-12-06 09:24
I have attached my screenshot

I have attached my screenshot what I finally found.

The root cause of this issue is : __section_begin() and __section_end() in "boot.h" don't return the right address but zero.

see screenshot in the atthached file.

Two part have use the macro in "boot.h":

1.arch_rom.c, when CFG_TRNG is defined

this cause crash

2.arch_main.c,when sleep is enabled

sleep code use to calculate which RAM block need retention.

 

Above issue only found in IAR IDE.

Attachment: 
PM_Dialog
Offline
Last seen: 7 months 1 week ago
Staff
Joined: 2018-02-08 11:03
Hi kevinchen_sz,

Hi kevinchen_sz,

Thanks for the screenshot. One more question and I’ll escalate it internally to replicate it: are you using the project as provided by the SDK, or have you done any modification?

Thanks, PM_Dialog

kevinchen_sz
Offline
Last seen: 2 months 3 weeks ago
Joined: 2017-12-06 09:24
both.

both.

and i also tried different version of IAR.

all have the same question.

PM_Dialog
Offline
Last seen: 7 months 1 week ago
Staff
Joined: 2018-02-08 11:03
Hi kevinchen_sz,

Hi kevinchen_sz,

I’ll escalated this internally to check this out and will get back to you.

Thanks, PM_Dialog

PM_Dialog
Offline
Last seen: 7 months 1 week ago
Staff
Joined: 2018-02-08 11:03
Hi janosN, many thanks for

Hi janosN, many thanks for comments and for your valuable feedback! We’ll review all your comments/solutions.

Hi sfuentes-digi, thanks for verifying this!

If you have any other question or feedback on the CodeLess, please raise a new forum ticket!

Thanks, PM_Dialog