Static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] , privileged data or not?

Hi !

Heap_4 file have reservation for heap area and for my understanding this is privileged data
and for my understanding should be defined as:

static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] PRIVILEGED_DATA;

But it cause hardFault.

Why it happens. Does in rtos kernel exists some accesses to this area with unprivileged rights ?
It should be used for allocate internal buffers and be accessed in privileged mode only.
I have few unprivileged tasks and one privileged.

Regards,
Eugene

I tried to make the same change and it does not result in a fault for me. I have tried it with this sample project: https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso

Can you describe what your tasks are doing - just trying to figure out if I am missing anything here.

Thanks.

Hi Gaurav !

I’m using the same LPC55S69 port but from NXP SDk directly. I have secure and nonsecure part
of code and hardfault report reason “Another secure bus error.\r\n”. I think it some how connected with security violation, but I haven’t got a idea how heap can be involved to that picture. Any idea ? I need start point for investigation.

I’m able to relocate other variables from heap_4.c without any problem.

/* The size of the structure placed at the beginning of each allocated memory
block must by correctly byte aligned. */
PRIVILEGED_FUNCTION
static const size_t xHeapStructSize	= ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );

/* Create a couple of list links to mark the start and end of the list. */
PRIVILEGED_DATA static BlockLink_t xStart, *pxEnd = NULL; //

/* Keeps track of the number of free bytes remaining, but says nothing about
fragmentation. */
PRIVILEGED_DATA static size_t xFreeBytesRemaining = 0U; //
PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U; //

/* Gets set to the top bit of an size_t type.  When this bit in the xBlockSize
member of an BlockLink_t structure is set then the block belongs to the
application.  When the bit is free the block is still part of the free heap
space. */
PRIVILEGED_DATA static size_t xBlockAllocatedBit = 0; //

On secure side I haven’t touch secure heap yet. It is used for allocate stacks of tasks what have secure context. But problem with this approach that some tasks can run with user privileges and some - privileged and it difficult to separate privileged and nonprivileged data.

As you know LPC55S69 require well done separation of priliges/nonprivileged code and data ,
in other case is not possible to enforce AHB bus privilege checking for secure and non secure sides ( AHB misc register.). And I should be able to have MPU_S/NS settings in way when MPU boundaries aligned with MPC/PPC sections as well.

Regards,
Eugene

Hi Eugene,

Are you allocating any memory from heap which is used by any unprivileged task? Another reason may be that an unprivileged task is causing some memory overrun into the heap area which was not detected earlier because the heap memory array was not protected.

Is it possible for you to create a small sample project showing this problem so that I can investigate?

Thanks,
Gaurav

Hi Gaurav !

I have quite huge enviroment and narrow down it to problematic part is basically only one way to find reason.

I have disabled all my tasks and only IDLE and Timer task remains.
Also I have disabled Secure context creation in IDLE task as well.
And it still generate the same HardFault.
I think this is somewhere in generic rtos code but no idea yet where.
Do you have some suggestion what part to check more ?

Regards,
Eugene