Skip to content

Commit

Permalink
[IOTSFW-2509] Rework memory layout
Browse files Browse the repository at this point in the history
Previous change to memory layout to avoid the 64K RAM discontinuity broke some
builds, as it restricted static data to the first 64K. Only stack and dlmalloc
heap were in the top 192K. Nanostack builds were particularly affected as the
Nanostack heap is a large bss allocation, and didn't fit.

Rework the memory allocation to better use the memory - stack and uVisor data
now go in the first 64K, with the stack auto-sized. Data, bss and dlmalloc heap
go in the 192K region.

Also fix the broken uVisor RAM layout symbols and restore the 512-byte initial
reservation (for uVisor?).

Stack limit checking also restored by putting the stack back immediately above
the secure memory.

Previous layout
---------------
1fff0000 RAM  uvisor.bss (512-byte reservation missing)
1fff2000      data, bss
1fff....      end of bss
(some unused RAM)
20000000 RAM2 stack (fixed 32K)
20008000      start of dlmalloc heap (fixed 160K)
2002ffff      end of dlmalloc heap

New layout
----------
1fff0000      Start of physical ram, 512 bytes reserved
1fff0200 RAM  uvisor.bss
1fff....      start of stack (autosized 64K - uvisor data)
1fffffff      end of stack
20000000 RAM2 data, bss
2000....      start of dlmalloc heap (autosized 192K - static data)
2002ffff      end of dlmalloc heap
  • Loading branch information
kjbracey authored and Hasnain Virk committed Apr 28, 2016
1 parent 6562472 commit 2fcaed5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ld/K64FN1M0xxx12.ld
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ MEMORY
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
FLASH_PROTECTION (rx) : ORIGIN = 0x00000400, LENGTH = 0x00000010
FLASH (rx) : ORIGIN = 0x00000410, LENGTH = 0x00100000 - 0x00000410
RAM (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
RAM_RESERVED (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 0x00000200
RAM (rwx) : ORIGIN = 0x1FFF0200, LENGTH = 0x00010000 - 0x00000200
RAM2 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00030000
}

Expand Down Expand Up @@ -130,13 +131,10 @@ SECTIONS
{
__StackLimit = .;
*(.stack*);
. += 0x8000 - (. - __StackLimit);
} > RAM2
. += (ORIGIN(RAM) + LENGTH(RAM) - .);
__StackTop = .;
} > RAM

/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ADDR(.stack) + SIZEOF(.stack);
__StackLimit = ADDR(.stack);
PROVIDE(__stack = __StackTop);

.data :
Expand Down Expand Up @@ -171,7 +169,7 @@ SECTIONS
. = ALIGN(32);
__data_end__ = .;

} >RAM AT>FLASH
} >RAM2 AT>FLASH

/* uvisor configuration data */
.uvisor.secure :
Expand Down Expand Up @@ -215,15 +213,15 @@ SECTIONS
KEEP(*(.keep.uninitialized))
. = ALIGN(32);
__uninitialized_end = .;
} > RAM
} > RAM2

.bss (NOLOAD):
{
__bss_start__ = .;
*(.bss*)
*(COMMON)
__bss_end__ = .;
} > RAM
} > RAM2

.heap (NOLOAD):
{
Expand All @@ -240,6 +238,6 @@ SECTIONS
/* Provide physical memory boundaries for uVisor. */
__uvisor_flash_start = ORIGIN(VECTORS);
__uvisor_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
__uvisor_sram_start = ORIGIN(RAM) - 0x200;
__uvisor_sram_end = ORIGIN(RAM) + LENGTH(RAM);
__uvisor_sram_start = ORIGIN(RAM_RESERVED);
__uvisor_sram_end = ORIGIN(RAM2) + LENGTH(RAM2);
}

0 comments on commit 2fcaed5

Please sign in to comment.