vmlinux-xip.lds.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* ld script to make ARM Linux kernel
  3. * taken from the i386 version by Russell King
  4. * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  5. */
  6. /* No __ro_after_init data in the .rodata section - which will always be ro */
  7. #define RO_AFTER_INIT_DATA
  8. #include <linux/sizes.h>
  9. #include <asm-generic/vmlinux.lds.h>
  10. #include <asm/cache.h>
  11. #include <asm/thread_info.h>
  12. #include <asm/memory.h>
  13. #include <asm/mpu.h>
  14. #include <asm/page.h>
  15. #include "vmlinux.lds.h"
  16. OUTPUT_ARCH(arm)
  17. ENTRY(stext)
  18. #ifndef __ARMEB__
  19. jiffies = jiffies_64;
  20. #else
  21. jiffies = jiffies_64 + 4;
  22. #endif
  23. SECTIONS
  24. {
  25. /*
  26. * XXX: The linker does not define how output sections are
  27. * assigned to input sections when there are multiple statements
  28. * matching the same input section name. There is no documented
  29. * order of matching.
  30. *
  31. * unwind exit sections must be discarded before the rest of the
  32. * unwind sections get included.
  33. */
  34. /DISCARD/ : {
  35. ARM_DISCARD
  36. *(.alt.smp.init)
  37. *(.pv_table)
  38. }
  39. . = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR);
  40. _xiprom = .; /* XIP ROM area to be mapped */
  41. .head.text : {
  42. _text = .;
  43. HEAD_TEXT
  44. }
  45. .text : { /* Real text segment */
  46. _stext = .; /* Text and read-only data */
  47. ARM_TEXT
  48. }
  49. RO_DATA(PAGE_SIZE)
  50. . = ALIGN(4);
  51. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  52. __start___ex_table = .;
  53. ARM_MMU_KEEP(*(__ex_table))
  54. __stop___ex_table = .;
  55. }
  56. #ifdef CONFIG_ARM_UNWIND
  57. ARM_UNWIND_SECTIONS
  58. #endif
  59. NOTES
  60. _etext = .; /* End of text and rodata section */
  61. ARM_VECTORS
  62. INIT_TEXT_SECTION(8)
  63. .exit.text : {
  64. ARM_EXIT_KEEP(EXIT_TEXT)
  65. }
  66. .init.proc.info : {
  67. ARM_CPU_DISCARD(PROC_INFO)
  68. }
  69. .init.arch.info : {
  70. __arch_info_begin = .;
  71. *(.arch.info.init)
  72. __arch_info_end = .;
  73. }
  74. .init.tagtable : {
  75. __tagtable_begin = .;
  76. *(.taglist.init)
  77. __tagtable_end = .;
  78. }
  79. .init.rodata : {
  80. INIT_SETUP(16)
  81. INIT_CALLS
  82. CON_INITCALL
  83. SECURITY_INITCALL
  84. INIT_RAM_FS
  85. }
  86. #ifdef CONFIG_ARM_MPU
  87. . = ALIGN(SZ_128K);
  88. #endif
  89. _exiprom = .; /* End of XIP ROM area */
  90. /*
  91. * From this point, stuff is considered writable and will be copied to RAM
  92. */
  93. __data_loc = ALIGN(4); /* location in file */
  94. . = PAGE_OFFSET + TEXT_OFFSET; /* location in memory */
  95. #undef LOAD_OFFSET
  96. #define LOAD_OFFSET (PAGE_OFFSET + TEXT_OFFSET - __data_loc)
  97. . = ALIGN(THREAD_SIZE);
  98. _sdata = .;
  99. RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
  100. .data.ro_after_init : AT(ADDR(.data.ro_after_init) - LOAD_OFFSET) {
  101. *(.data..ro_after_init)
  102. }
  103. _edata = .;
  104. . = ALIGN(PAGE_SIZE);
  105. __init_begin = .;
  106. .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
  107. INIT_DATA
  108. }
  109. .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
  110. ARM_EXIT_KEEP(EXIT_DATA)
  111. }
  112. #ifdef CONFIG_SMP
  113. PERCPU_SECTION(L1_CACHE_BYTES)
  114. #endif
  115. #ifdef CONFIG_HAVE_TCM
  116. ARM_TCM
  117. #endif
  118. /*
  119. * End of copied data. We need a dummy section to get its LMA.
  120. * Also located before final ALIGN() as trailing padding is not stored
  121. * in the resulting binary file and useless to copy.
  122. */
  123. .data.endmark : AT(ADDR(.data.endmark) - LOAD_OFFSET) { }
  124. _edata_loc = LOADADDR(.data.endmark);
  125. . = ALIGN(PAGE_SIZE);
  126. __init_end = .;
  127. BSS_SECTION(0, 0, 8)
  128. #ifdef CONFIG_ARM_MPU
  129. . = ALIGN(PMSAv8_MINALIGN);
  130. #endif
  131. _end = .;
  132. STABS_DEBUG
  133. }
  134. /*
  135. * These must never be empty
  136. * If you have to comment these two assert statements out, your
  137. * binutils is too old (for other reasons as well)
  138. */
  139. ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
  140. ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")
  141. /*
  142. * The HYP init code can't be more than a page long,
  143. * and should not cross a page boundary.
  144. * The above comment applies as well.
  145. */
  146. ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & PAGE_MASK) <= PAGE_SIZE,
  147. "HYP init code too big or misaligned")
  148. #ifdef CONFIG_XIP_DEFLATED_DATA
  149. /*
  150. * The .bss is used as a stack area for __inflate_kernel_data() whose stack
  151. * frame is 9568 bytes. Make sure it has extra room left.
  152. */
  153. ASSERT((_end - __bss_start) >= 12288, ".bss too small for CONFIG_XIP_DEFLATED_DATA")
  154. #endif
  155. #ifdef CONFIG_ARM_MPU
  156. /*
  157. * Due to PMSAv7 restriction on base address and size we have to
  158. * enforce minimal alignment restrictions. It was seen that weaker
  159. * alignment restriction on _xiprom will likely force XIP address
  160. * space spawns multiple MPU regions thus it is likely we run in
  161. * situation when we are reprogramming MPU region we run on with
  162. * something which doesn't cover reprogramming code itself, so as soon
  163. * as we update MPU settings we'd immediately try to execute straight
  164. * from background region which is XN.
  165. * It seem that alignment in 1M should suit most users.
  166. * _exiprom is aligned as 1/8 of 1M so can be covered by subregion
  167. * disable
  168. */
  169. ASSERT(!(_xiprom & (SZ_1M - 1)), "XIP start address may cause MPU programming issues")
  170. ASSERT(!(_exiprom & (SZ_128K - 1)), "XIP end address may cause MPU programming issues")
  171. #endif