vmlinux-xip.lds.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/vmlinux.lds.h>
  10. #include <asm/cache.h>
  11. #include <asm/thread_info.h>
  12. #include <asm/page.h>
  13. #include <asm/mpu.h>
  14. OUTPUT_ARCH(arm)
  15. ENTRY(stext)
  16. #ifndef __ARMEB__
  17. jiffies = jiffies_64;
  18. #else
  19. jiffies = jiffies_64 + 4;
  20. #endif
  21. SECTIONS
  22. {
  23. /*
  24. * XXX: The linker does not define how output sections are
  25. * assigned to input sections when there are multiple statements
  26. * matching the same input section name. There is no documented
  27. * order of matching.
  28. *
  29. * unwind exit sections must be discarded before the rest of the
  30. * unwind sections get included.
  31. */
  32. /DISCARD/ : {
  33. ARM_DISCARD
  34. *(.alt.smp.init)
  35. *(.pv_table)
  36. #ifndef CONFIG_ARM_UNWIND
  37. *(.ARM.exidx) *(.ARM.exidx.*)
  38. *(.ARM.extab) *(.ARM.extab.*)
  39. #endif
  40. }
  41. . = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR);
  42. _xiprom = .; /* XIP ROM area to be mapped */
  43. .head.text : {
  44. _text = .;
  45. HEAD_TEXT
  46. }
  47. .text : { /* Real text segment */
  48. _stext = .; /* Text and read-only data */
  49. ARM_TEXT
  50. }
  51. RO_DATA(PAGE_SIZE)
  52. . = ALIGN(4);
  53. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
  54. __start___ex_table = .;
  55. ARM_MMU_KEEP(KEEP(*(__ex_table)))
  56. __stop___ex_table = .;
  57. }
  58. #ifdef CONFIG_ARM_UNWIND
  59. ARM_UNWIND_SECTIONS
  60. #endif
  61. _etext = .; /* End of text and rodata section */
  62. ARM_VECTORS
  63. INIT_TEXT_SECTION(8)
  64. .exit.text : {
  65. ARM_EXIT_KEEP(EXIT_TEXT)
  66. }
  67. .init.proc.info : {
  68. ARM_CPU_DISCARD(PROC_INFO)
  69. }
  70. .init.arch.info : {
  71. __arch_info_begin = .;
  72. KEEP(*(.arch.info.init))
  73. __arch_info_end = .;
  74. }
  75. .init.tagtable : {
  76. __tagtable_begin = .;
  77. *(.taglist.init)
  78. __tagtable_end = .;
  79. }
  80. .init.rodata : {
  81. INIT_SETUP(16)
  82. INIT_CALLS
  83. CON_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(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. DWARF_DEBUG
  134. ARM_DETAILS
  135. ARM_ASSERTS
  136. }
  137. /*
  138. * These must never be empty
  139. * If you have to comment these two assert statements out, your
  140. * binutils is too old (for other reasons as well)
  141. */
  142. ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
  143. #ifndef CONFIG_COMPILE_TEST
  144. ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")
  145. #endif
  146. #ifdef CONFIG_XIP_DEFLATED_DATA
  147. /*
  148. * The .bss is used as a stack area for __inflate_kernel_data() whose stack
  149. * frame is 9568 bytes. Make sure it has extra room left.
  150. */
  151. ASSERT((_end - __bss_start) >= 12288, ".bss too small for CONFIG_XIP_DEFLATED_DATA")
  152. #endif
  153. #if defined(CONFIG_ARM_MPU) && !defined(CONFIG_COMPILE_TEST)
  154. /*
  155. * Due to PMSAv7 restriction on base address and size we have to
  156. * enforce minimal alignment restrictions. It was seen that weaker
  157. * alignment restriction on _xiprom will likely force XIP address
  158. * space spawns multiple MPU regions thus it is likely we run in
  159. * situation when we are reprogramming MPU region we run on with
  160. * something which doesn't cover reprogramming code itself, so as soon
  161. * as we update MPU settings we'd immediately try to execute straight
  162. * from background region which is XN.
  163. * It seem that alignment in 1M should suit most users.
  164. * _exiprom is aligned as 1/8 of 1M so can be covered by subregion
  165. * disable
  166. */
  167. ASSERT(!(_xiprom & (SZ_1M - 1)), "XIP start address may cause MPU programming issues")
  168. ASSERT(!(_exiprom & (SZ_128K - 1)), "XIP end address may cause MPU programming issues")
  169. #endif