300-ARM-BCM5301X-Disable-MMU-and-Dcache-during-decompres.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  2. Date: Wed, 24 Sep 2014 22:14:07 +0200
  3. Subject: [PATCH] ARM: BCM5301X: Disable MMU and Dcache during decompression
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. Broadcom devices have broken CFE (bootloader) that leaves hardware in an
  8. invalid state. It causes problems with booting Linux. On Northstar
  9. devices kernel was randomly hanging in ~25% of tries during early init.
  10. Hangs used to happen at random places in the start_kernel. On BCM53573
  11. kernel doesn't even seem to start booting.
  12. To workaround this problem we need to do following very early:
  13. 1) Clear 2 following bits in the SCTLR register:
  14. #define CR_M (1 << 0) /* MMU enable */
  15. #define CR_C (1 << 2) /* Dcache enable */
  16. 2) Flush the whole D-cache
  17. 3) Disable L2 cache
  18. Unfortunately this patch is not upstreamable as it does above things
  19. unconditionally. We can't check if we are running on Broadcom platform
  20. in any safe way and doing such hacks with ARCH_MULTI_V7 is unacceptable
  21. as it could break other devices support.
  22. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  23. ---
  24. --- a/arch/arm/boot/compressed/Makefile
  25. +++ b/arch/arm/boot/compressed/Makefile
  26. @@ -31,6 +31,11 @@ ifeq ($(CONFIG_ARCH_ACORN),y)
  27. OBJS += ll_char_wr.o font.o
  28. endif
  29. +ifeq ($(CONFIG_ARCH_BCM_5301X),y)
  30. +OBJS += head-bcm_5301x-mpcore.o
  31. +OBJS += cache-v7-min.o
  32. +endif
  33. +
  34. ifeq ($(CONFIG_ARCH_SA1100),y)
  35. OBJS += head-sa1100.o
  36. endif
  37. --- /dev/null
  38. +++ b/arch/arm/boot/compressed/head-bcm_5301x-mpcore.S
  39. @@ -0,0 +1,37 @@
  40. +/*
  41. + *
  42. + * Platform specific tweaks. This is merged into head.S by the linker.
  43. + *
  44. + */
  45. +
  46. +#include <linux/linkage.h>
  47. +#include <asm/assembler.h>
  48. +#include <asm/cp15.h>
  49. +
  50. + .section ".start", "ax"
  51. +
  52. +/*
  53. + * This code section is spliced into the head code by the linker
  54. + */
  55. +
  56. +__plat_uncompress_start:
  57. +
  58. + @ Preserve r8/r7 i.e. kernel entry values
  59. + mov r12, r8
  60. +
  61. + @ Clear MMU enable and Dcache enable bits
  62. + mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR
  63. + bic r0, #CR_C|CR_M
  64. + mcr p15, 0, r0, c1, c0, 0 @ Write SCTLR
  65. + nop
  66. +
  67. + @ Call the cache invalidation routine
  68. + bl v7_flush_dcache_all
  69. + nop
  70. + mov r0,#0
  71. + ldr r3, =0x19022000 @ L2 cache controller, control reg
  72. + str r0, [r3, #0x100] @ Disable L2 cache
  73. + nop
  74. +
  75. + @ Restore
  76. + mov r8, r12
  77. --- a/arch/arm/boot/compressed/cache-v7-min.S
  78. +++ b/arch/arm/boot/compressed/cache-v7-min.S
  79. @@ -12,6 +12,7 @@
  80. #include <linux/linkage.h>
  81. #include <linux/init.h>
  82. +#include <asm/assembler.h>
  83. __INIT
  84. @@ -63,7 +64,7 @@ loop2:
  85. ARM( orr r11, r11, r9, lsl r2 ) @ factor index number into r11
  86. THUMB( lsl r6, r9, r2 )
  87. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  88. - mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  89. + mcr p15, 0, r11, c7, c6, 2 @ clean & invalidate by set/way
  90. subs r9, r9, #1 @ decrement the index
  91. bge loop2
  92. subs r4, r4, #1 @ decrement the way