user_linker.icf 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2021-2023 HPMicro
  3. * SPDX-License-Identifier: BSD-3-Clause
  4. */
  5. define memory with size = 4G;
  6. /* Regions */
  7. define region NOR_CFG_OPTION = [ from 0x80000400 size 0x0C00 ];
  8. define region BOOT_HEADER = [ from 0x80001000 size 0x2000 ];
  9. define region XPI0 = [from 0x80003000 size (_flash_size - 0x3000) ]; /* XPI0 */
  10. define region ILM = [from 0x00000000 size 256k]; /* ILM */
  11. define region DLM = [from 0x00080000 size 256k]; /* DLM */
  12. define region AXI_SRAM = [from 0x01080000 size 768k]; /* AXI SRAM */
  13. define region SHARE_RAM = [from 0x0117C000 size 16k];
  14. define region AHB_SRAM = [from 0xF0300000 size 32k];
  15. define region APB_SRAM = [from 0xF40F0000 size 8k];
  16. define region SDRAM = [from 0x40000000 size _extram_size - 4M];
  17. define region NONCACHEABLE_RAM = [from 0x40000000 + _extram_size - 4M size 4M];
  18. /* Blocks */
  19. define block vectors with fixed order { section .vector_table, section .isr_vector, section .isr_vector.* };
  20. define block ctors { section .ctors, section .ctors.*, block with alphabetical order { init_array } };
  21. define block dtors { section .dtors, section .dtors.*, block with reverse alphabetical order { fini_array } };
  22. define block eh_frame { section .eh_frame, section .eh_frame.* };
  23. define block tbss { section .tbss, section .tbss.* };
  24. define block tdata { section .tdata, section .tdata.* };
  25. define block tls with fixed order { block tbss, block tdata };
  26. define block tdata_load { copy of block tdata };
  27. define block heap with size = __HEAPSIZE__, alignment = 8, /* fill =0x00, */ readwrite access { };
  28. define block stack with size = __STACKSIZE__, alignment = 16, /* fill =0xCD, */ readwrite access { };
  29. define block boot_header with fixed order { section .boot_header, section .fw_info_table, section .dc_info };
  30. define block cherryusb_usbh_class_info with alignment = 8 { section .usbh_class_info };
  31. define block framebuffer with alignment = 8 { section .framebuffer, section .framebuffer.* };
  32. define block rtthread_FSymTab { section FSymTab };
  33. define block rtthread_VSymTab { section VSymTab };
  34. define block rtthread_rti_fn with alphabetical order { section .rti_fn* };
  35. define block rtthread_RTMSymTab { section RTMSymTab };
  36. /* Symbols */
  37. define exported symbol __nor_cfg_option_load_addr__ = start of region NOR_CFG_OPTION;
  38. define exported symbol __boot_header_load_addr__ = start of region BOOT_HEADER;
  39. define exported symbol __app_load_addr__ = start of region XPI0;
  40. define exported symbol __app_offset__ = __app_load_addr__ - __boot_header_load_addr__;
  41. define exported symbol __boot_header_length__ = size of block boot_header;
  42. define exported symbol __fw_size__ = 0x1000;
  43. define exported symbol __noncacheable_start__ = start of region NONCACHEABLE_RAM;
  44. define exported symbol __noncacheable_end__ = end of region NONCACHEABLE_RAM + 1;
  45. define exported symbol __share_mem_start__ = start of region SHARE_RAM;
  46. define exported symbol __share_mem_end__ = end of region SHARE_RAM + 1;
  47. define exported symbol _stack_safe = end of block stack + 1;
  48. define exported symbol _stack = end of block stack + 1;
  49. define exported symbol __usbh_class_info_start__ = start of block cherryusb_usbh_class_info;
  50. define exported symbol __usbh_class_info_end__ = end of block cherryusb_usbh_class_info + 1;
  51. define exported symbol __fsymtab_start = start of block rtthread_FSymTab;
  52. define exported symbol __fsymtab_end = end of block rtthread_FSymTab + 1;
  53. define exported symbol __vsymtab_start = start of block rtthread_VSymTab;
  54. define exported symbol __vsymtab_end = end of block rtthread_VSymTab + 1;
  55. define exported symbol __rt_init_start = start of block rtthread_rti_fn;
  56. define exported symbol __rt_init_end = end of block rtthread_rti_fn + 1;
  57. define exported symbol __rtmsymtab_start = start of block rtthread_RTMSymTab;
  58. define exported symbol __rtmsymtab_end = end of block rtthread_RTMSymTab + 1;
  59. /* Initialization */
  60. do not initialize { section .noncacheable, section .fast_ram }; // Legacy sections, kept for backwards compatibility
  61. do not initialize { section .non_init, section .non_init.*, section .*.non_init, section .*.non_init.* };
  62. do not initialize { section .no_init, section .no_init.*, section .*.no_init, section .*.no_init.* }; // Legacy sections, kept for backwards compatibility
  63. do not initialize { section .noinit, section .noinit.*, section .*.noinit, section .*.noinit.* }; // Legacy sections, used by some SDKs/HALs
  64. do not initialize { section .backup_sram, section .backup_sram.*};
  65. initialize by copy with packing=auto { section .noncacheable.init, section .noncacheable.init.*, section .fast_ram.init, section .fast_ram.init.* };
  66. initialize by copy with packing=none { section .data, section .data.*, section .*.data, section .*.data.* }; // Static data sections
  67. initialize by copy with packing=auto { section .sdata, section .sdata.* };
  68. initialize by copy with packing=auto { section .fast, section .fast.*, section .*.fast, section .*.fast.*, section .text.*nx* }; // "RAM Code" sections
  69. initialize by calling __SEGGER_init_heap { block heap }; // Init the heap if there is one
  70. initialize by calling __SEGGER_init_ctors { block ctors }; // Call constructors for global objects which need to be constructed before reaching main (if any). Make sure this is done after setting up heap.
  71. initialize by copy { block vectors };
  72. /* Placement */
  73. place in NOR_CFG_OPTION { section .nor_cfg_option };
  74. place in BOOT_HEADER with fixed order { block boot_header };
  75. place at start of XPI0 with fixed order { symbol _start};
  76. place at start of ILM with fixed order { block vectors };
  77. place in XPI0 with minimum size order {
  78. block tdata_load, // Thread-local-storage load image
  79. block ctors, // Constructors block
  80. block dtors, // Destructors block
  81. block eh_frame, // Exception frames placed directly into flash overriding default placement (sections writable)
  82. block rtthread_FSymTab,
  83. block rtthread_VSymTab,
  84. block rtthread_rti_fn,
  85. block rtthread_RTMSymTab,
  86. block cherryusb_usbh_class_info,
  87. readonly, // Catch-all for readonly data (e.g. .rodata, .srodata)
  88. readexec // Catch-all for (readonly) executable code (e.g. .text)
  89. };
  90. //
  91. // The GNU compiler creates these exception-related sections as writeable.
  92. // Override the section header flag and make them readonly so they can be
  93. // placed into flash.
  94. //
  95. define access readonly { section .gcc_except_table, section .gcc_except_table.* };
  96. define access readonly { section .eh_frame, section .eh_frame.* };
  97. define access readonly { section .sdata.DW.* };
  98. place in ILM {
  99. section .fast, section .fast.*, section .text.*nx*, // "ramfunc" section
  100. };
  101. place in SDRAM { block framebuffer };
  102. place in AXI_SRAM then SDRAM {
  103. block tls, // Thread-local-storage block
  104. readwrite, // Catch-all for initialized/uninitialized data sections (e.g. .data, .noinit)
  105. zeroinit // Catch-all for zero-initialized data sections (e.g. .bss)
  106. };
  107. place in NONCACHEABLE_RAM { section .noncacheable.non_init, section .noncacheable.non_init.*, section .noncacheable.init, section .noncacheable.init.*, section .noncacheable.bss, section .noncacheable.bss.*, section .noncacheable }; // Noncacheable
  108. place in SHARE_RAM { section .sh_mem, section .sh_mem.*}; // Share memory
  109. place in AHB_SRAM { section .ahb_sram, section .ahb_sram.*}; // AHB SRAM memory
  110. place in APB_SRAM { section .backup_sram, section .backup_sram.*}; // Backup SRAM memory
  111. place in DLM { section .fast_ram.init, section .fast_ram.init.*, section .fast_ram.non_init, section .fast_ram.non_init.*, section .fast_ram.bss, section .fast_ram.bss.*, section .fast_ram }; // Fast access memory
  112. place in SDRAM { block heap }; // Heap reserved block
  113. place at end of DLM { block stack }; // Stack reserved block
  114. /* Keep */
  115. keep { section .nor_cfg_option, section .boot_header, section .fw_info_table, section .dc_info };
  116. keep { section .usbh_class_info, section FSymTab, section VSymTab, section .rti_fn*, section RTMSymTab };