/memory.x
MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x00000000, LENGTH = 512K
  RAM : ORIGIN = 0x20084000, LENGTH = 16K
  APPRAM : ORIGIN = 0x20000000, LENGTH = 64K
  KGRAM : ORIGIN = 0x20080000, LENGTH = 16K
}

/* This is where the call stack will be allocated. */
/* The stack is of the full descending type. */
/* You may want to use this variable to locate the call stack and static
   variables in different memory regions. Below is shown the default value */
/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */

/* You can use this symbol to customize the location of the .text section */
/* If omitted the .text section will be placed right after the .vector_table
   section */
/* This is required only on microcontrollers that store some configuration right
   after the vector table */
/* _stext = ORIGIN(FLASH) + 0x400; */

/* Example of putting non-initialized variables into custom RAM locations. */
/* This assumes you have defined a region RAM2 above, and in the Rust
   sources added the attribute `#[link_section = ".ram2bss"]` to the data
   you want to place there. */
/* Note that the section will not be zero-initialized by the runtime! */
/* SECTIONS {
     .ram2bss (NOLOAD) : ALIGN(4) {
       *(.ram2bss);
       . = ALIGN(4);
     } > RAM2
   } INSERT AFTER .bss;
*/

_appram = ORIGIN(APPRAM);
_appram_end = ORIGIN(APPRAM) + LENGTH(APPRAM);

SECTIONS {
  .driver_interfaces : ALIGN(4) {
    *(.driver_interfaces);
    . = ALIGN(4);
  } > FLASH

  .init_array : ALIGN(4) {
    *(.init_array);
    . = ALIGN(4);
  } > FLASH

  PROVIDE(_stext = ADDR(.init_array) + SIZEOF(.init_array));
} INSERT AFTER .vector_table;

SECTIONS {
  .kgdata : ALIGN(4) {
    *(.kgdata);
    *libc.a*(.data .data.*);
    *libm.a*(.data .data.*);
    *liblua.a*(.data .data.*);
    *libshell.a*(.data .data.*);
    . = ALIGN(4);
  } > KGRAM AT >FLASH

  /* .kgdata ROM location */
  __skgdata = ADDR(.kgdata);
  __ekgdata = ADDR(.kgdata) + SIZEOF(.kgdata);

  /* .kgdata RAM location */
  __sikgdata = LOADADDR(.kgdata);
} INSERT BEFORE .data;

SECTIONS {
  .kgbss : ALIGN(4) {
    *(.kgbss);
    *libc.a*(.bss .bss.* COMMON);
    *libm.a*(.bss .bss.* COMMON);
    *liblua.a*(.bss .bss.* COMMON);
    *libshell.a*(.bss .bss.* COMMON);
    . = ALIGN(4);
  } > KGRAM AT >KGRAM  /* Don't ask me why, but simply "> KGRAM" doesn't work */

  __skgbss = ADDR(.kgbss);
  __ekgbss = ADDR(.kgbss) + SIZEOF(.kgbss);
} INSERT BEFORE .bss;