0001-armv8-Support-loading-32-bit-OS-in-AArch32-execution.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. From e03f571b1e9564ca422134b2013d80c8373c9db2 Mon Sep 17 00:00:00 2001
  2. From: Alison Wang <[email protected]>
  3. Date: Fri, 13 May 2016 10:19:24 +0800
  4. Subject: [PATCH 01/93] armv8: Support loading 32-bit OS in AArch32 execution
  5. state
  6. To support loading a 32-bit OS, the execution state will change from
  7. AArch64 to AArch32 when jumping to kernel.
  8. The architecture information will be got through checking FIT
  9. image, then U-Boot will load 32-bit OS or 64-bit OS automatically.
  10. Signed-off-by: Ebony Zhu <[email protected]>
  11. Signed-off-by: Alison Wang <[email protected]>
  12. Signed-off-by: Chenhui Zhao <[email protected]>
  13. ---
  14. arch/arm/cpu/armv8/transition.S | 100 +++++++++++++++++++++++++++++++++++++++
  15. arch/arm/include/asm/system.h | 2 +
  16. arch/arm/lib/bootm.c | 20 +++++++-
  17. common/image-fit.c | 12 ++++-
  18. 4 files changed, 131 insertions(+), 3 deletions(-)
  19. diff --git a/arch/arm/cpu/armv8/transition.S b/arch/arm/cpu/armv8/transition.S
  20. index 253a39b..9d7a17a 100644
  21. --- a/arch/arm/cpu/armv8/transition.S
  22. +++ b/arch/arm/cpu/armv8/transition.S
  23. @@ -21,3 +21,103 @@ ENTRY(armv8_switch_to_el1)
  24. 0: ret
  25. 1: armv8_switch_to_el1_m x0, x1
  26. ENDPROC(armv8_switch_to_el1)
  27. +
  28. +/*
  29. + * x0: kernel entry point
  30. + * x1: machine nr
  31. + * x2: fdt address
  32. + */
  33. +ENTRY(armv8_switch_to_el2_aarch32)
  34. + switch_el x3, 1f, 0f, 0f
  35. +0: ret
  36. +1:
  37. + mov x7, x0
  38. + mov x8, x1
  39. + mov x9, x2
  40. +
  41. + /* 32bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | Non-secure EL0/EL1 */
  42. + mov x1, 0x1b1
  43. + msr scr_el3, x1
  44. + msr cptr_el3, xzr /* Disable coprocessor traps to EL3 */
  45. + mov x1, 0x33ff
  46. + msr cptr_el2, x1 /* Disable coprocessor traps to EL2 */
  47. +
  48. + /* Initialize Generic Timers */
  49. + msr cntvoff_el2, xzr
  50. +
  51. + mov x1, #0x0830
  52. + movk x1, #0x30c5, lsl #16
  53. + msr sctlr_el2, x1
  54. +
  55. + /* Return to AArch32 Hypervisor mode */
  56. + mov x1, sp
  57. + msr sp_el2, x1
  58. + mrs x1, vbar_el3
  59. + msr vbar_el2, x1 /* Migrate VBAR */
  60. + mov x1, #0x1da
  61. + msr spsr_el3, x1
  62. + msr elr_el3, x7
  63. +
  64. + mov x0, #0
  65. + mov x1, x8
  66. + mov x2, x9
  67. +
  68. + eret
  69. +ENDPROC(armv8_switch_to_el2_aarch32)
  70. +
  71. +/*
  72. + * x0: kernel entry point
  73. + * x1: machine nr
  74. + * x2: fdt address
  75. + */
  76. +ENTRY(armv8_switch_to_el1_aarch32)
  77. + switch_el x3, 0f, 1f, 0f
  78. +0: ret
  79. +1:
  80. + mov x7, x0
  81. + mov x8, x1
  82. + mov x9, x2
  83. +
  84. + /* Initialize Generic Timers */
  85. + mrs x0, cnthctl_el2
  86. + orr x0, x0, #0x3 /* Enable EL1 access to timers */
  87. + msr cnthctl_el2, x0
  88. + msr cntvoff_el2, xzr
  89. +
  90. + /* Initialize MPID/MPIDR registers */
  91. + mrs x0, midr_el1
  92. + mrs x1, mpidr_el1
  93. + msr vpidr_el2, x0
  94. + msr vmpidr_el2, x1
  95. +
  96. + /* Disable coprocessor traps */
  97. + mov x0, #0x33ff
  98. + msr cptr_el2, x0 /* Disable coprocessor traps to EL2 */
  99. + msr hstr_el2, xzr /* Disable coprocessor traps to EL2 */
  100. + mov x0, #3 << 20
  101. + msr cpacr_el1, x0 /* Enable FP/SIMD at EL1 */
  102. +
  103. + /* Initialize HCR_EL2 */
  104. + mov x0, #(0 << 31) /* 32bit EL1 */
  105. + orr x0, x0, #(1 << 29) /* Disable HVC */
  106. + msr hcr_el2, x0
  107. +
  108. + mov x0, #0x0800
  109. + movk x0, #0x30d0, lsl #16
  110. + msr sctlr_el1, x0
  111. +
  112. + /* Return to AArch32 Supervisor mode */
  113. + mov x0, sp
  114. + msr sp_el1, x0 /* Migrate SP */
  115. + mrs x0, vbar_el2
  116. + msr vbar_el1, x0 /* Migrate VBAR */
  117. + mov x0, #0x1d3
  118. + msr spsr_el2, x0
  119. + msr elr_el2, x7
  120. +
  121. + mov x0, #0
  122. + mov x1, x8
  123. + mov x2, x9
  124. +
  125. + eret
  126. +ENDPROC(armv8_switch_to_el1_aarch32)
  127. diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
  128. index 71b3108..0ecbcf7 100644
  129. --- a/arch/arm/include/asm/system.h
  130. +++ b/arch/arm/include/asm/system.h
  131. @@ -81,6 +81,8 @@ int __asm_flush_l3_cache(void);
  132. void armv8_switch_to_el2(void);
  133. void armv8_switch_to_el1(void);
  134. +void armv8_switch_to_el2_aarch32(u64 entry_point, u64 mach_nr, u64 fdt_addr);
  135. +void armv8_switch_to_el1_aarch32(u64 entry_point, u64 mach_nr, u64 fdt_addr);
  136. void gic_init(void);
  137. void gic_send_sgi(unsigned long sgino);
  138. void wait_for_wakeup(void);
  139. diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
  140. index a477cae..36f2cb0 100644
  141. --- a/arch/arm/lib/bootm.c
  142. +++ b/arch/arm/lib/bootm.c
  143. @@ -276,8 +276,24 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
  144. announce_and_cleanup(fake);
  145. if (!fake) {
  146. - do_nonsec_virt_switch();
  147. - kernel_entry(images->ft_addr, NULL, NULL, NULL);
  148. + if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) &&
  149. + (images->os.arch == IH_ARCH_ARM)) {
  150. + smp_kick_all_cpus();
  151. + dcache_disable();
  152. +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
  153. + armv8_switch_to_el2();
  154. + armv8_switch_to_el1_aarch32((u64)images->ep,
  155. + (u64)gd->bd->bi_arch_number,
  156. + (u64)images->ft_addr);
  157. +#else
  158. + armv8_switch_to_el2_aarch32((u64)images->ep,
  159. + (u64)gd->bd->bi_arch_number,
  160. + (u64)images->ft_addr);
  161. +#endif
  162. + } else {
  163. + do_nonsec_virt_switch();
  164. + kernel_entry(images->ft_addr, NULL, NULL, NULL);
  165. + }
  166. }
  167. #else
  168. unsigned long machid = gd->bd->bi_arch_number;
  169. diff --git a/common/image-fit.c b/common/image-fit.c
  170. index c531ee7..0d54f71 100644
  171. --- a/common/image-fit.c
  172. +++ b/common/image-fit.c
  173. @@ -1144,7 +1144,8 @@ int fit_image_check_arch(const void *fit, int noffset, uint8_t arch)
  174. if (fit_image_get_arch(fit, noffset, &image_arch))
  175. return 0;
  176. return (arch == image_arch) ||
  177. - (arch == IH_ARCH_I386 && image_arch == IH_ARCH_X86_64);
  178. + (arch == IH_ARCH_I386 && image_arch == IH_ARCH_X86_64) ||
  179. + (arch == IH_ARCH_ARM64 && image_arch == IH_ARCH_ARM);
  180. }
  181. /**
  182. @@ -1567,6 +1568,9 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
  183. int type_ok, os_ok;
  184. ulong load, data, len;
  185. uint8_t os;
  186. +#ifndef USE_HOSTCC
  187. + uint8_t os_arch;
  188. +#endif
  189. const char *prop_name;
  190. int ret;
  191. @@ -1650,6 +1654,12 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
  192. return -ENOEXEC;
  193. }
  194. #endif
  195. +
  196. +#ifndef USE_HOSTCC
  197. + fit_image_get_arch(fit, noffset, &os_arch);
  198. + images->os.arch = os_arch;
  199. +#endif
  200. +
  201. if (image_type == IH_TYPE_FLATDT &&
  202. !fit_image_check_comp(fit, noffset, IH_COMP_NONE)) {
  203. puts("FDT image is compressed");
  204. --
  205. 1.7.9.5