Guest User

Untitled

a guest
Jun 15th, 2026
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # SPDX-License-Identifier: MIT
  3. import sys, pathlib, time
  4. sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
  5.  
  6. from m1n1.setup import *
  7. from m1n1 import asm
  8. from m1n1.fw.smc import SMCClient
  9. from m1n1.hw.dart import DART
  10. from m1n1.fw.aop.client import AOPClient
  11. from m1n1.fw.aop.ipc import *
  12.  
  13.  
  14. p.smp_start_secondaries()
  15. p.smp_stop_secondaries(True)
  16.  
  17.  
  18. rvbar = p.read64(u.adt["cpus"][0].cpu_impl_reg[0])& 0xffffffffffe
  19. print(hex(rvbar))
  20. code = u.malloc(0x1000)
  21.  
  22. util = asm.ARMAsm("""
  23. overwrite:
  24. isb
  25. mrs x3, SCTLR_EL1
  26. bfc x3, #0, #1
  27. msr SCTLR_EL1, x3
  28. isb
  29.  
  30. mov x3, 0
  31. .Lloop:
  32. ldrb w4, [x0, x3]
  33. strb w4, [x1, x3]
  34. add x3, x3, #1
  35. cmp x2, x3
  36. bne .Lloop
  37.  
  38. isb
  39. mrs x3, SCTLR_EL1
  40. orr x3, x3, #1
  41. msr SCTLR_EL1, x3
  42. isb
  43. ret
  44. """, code)
  45.  
  46. resp = asm.ARMAsm("""
  47. go:
  48. mov x1, #0x9b200000
  49. movk x1, #0x3, lsl #32
  50.  
  51. mov x0, '!'
  52. str w0, [x1, 0x020]
  53. mov x0, '!'
  54. str w0, [x1, 0x020]
  55. mov x0, '!'
  56. str w0, [x1, 0x020]
  57. mov x0, '!'
  58. str w0, [x1, 0x020]
  59.  
  60. ret
  61. """, rvbar)
  62. iface.writemem(code, util.data)
  63. p.dc_cvau(code, len(util.data))
  64. p.ic_ivau(code, len(util.data))
  65.  
  66. code2 = u.malloc(0x1000)
  67. iface.writemem(code2, resp.data)
  68. p.dc_cvau(code2, len(resp.data))
  69. p.ic_ivau(code2, len(resp.data))
  70.  
  71.  
  72. p.call(util.overwrite, code2, rvbar, len(resp.data))
  73.  
  74. code = u.malloc(0x1000)
  75.  
  76. util = asm.ARMAsm("""
  77. #define sys_reg(op0, op1, CRn, CRm, op2) s##op0##_##op1##_c##CRn##_c##CRm##_##op2
  78. #define ULONG(x) (x)
  79. #define BIT(x) (1UL << (x))
  80. #define GENMASK(msb, lsb) ((BIT((msb + 1) - (lsb)) - 1) << (lsb))
  81. #define SYS_IMP_APL_ACC_OVRD sys_reg(3, 5, 15, 6, 0)
  82. #define ACC_OVRD_PWR_DN_SRM(x) ((ULONG(x)) << 13)
  83. #define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK GENMASK(16, 15)
  84. #define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(x) ((ULONG(x)) << 15)
  85. #define ACC_OVRD_TRAIN_DOWN_LINK(x) ((ULONG(x)) << 17)
  86. #define ACC_OVRD_POWER_DOWN_CPM(x) ((ULONG(x)) << 25)
  87. #define ACC_OVRD_DISABLE_PIO_ON_WFI_CPU BIT(32)
  88. #define ACC_OVRD_DEEP_SLEEP BIT(34)
  89. #define SYS_IMP_APL_CYC_OVRD sys_reg(3, 5, 15, 5, 0)
  90. #define CYC_OVRD_WFI_MODE(x) ((ULONG(x)) << 24)
  91. #define CYC_OVRD_DISABLE_WFI_RET BIT(0)
  92.  
  93.  
  94. sleep:
  95. mrs x1, SYS_IMP_APL_ACC_OVRD
  96. orr x1, x1, #ACC_OVRD_PWR_DN_SRM(3)
  97. and x1, x1, #~ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK
  98. orr x1, x1, #ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(2)
  99. orr x1, x1, #ACC_OVRD_TRAIN_DOWN_LINK(3)
  100. orr x1, x1, #ACC_OVRD_POWER_DOWN_CPM(3)
  101. orr x1, x1, #ACC_OVRD_DISABLE_PIO_ON_WFI_CPU
  102. orr x1, x1, #ACC_OVRD_DEEP_SLEEP
  103. msr SYS_IMP_APL_ACC_OVRD, x1
  104.  
  105. mrs x1, SYS_IMP_APL_CYC_OVRD
  106. orr x1, x1, #CYC_OVRD_WFI_MODE(3)
  107. orr x1, x1, #CYC_OVRD_DISABLE_WFI_RET
  108. msr SYS_IMP_APL_CYC_OVRD, x1
  109.  
  110. loop_wfi:
  111. isb
  112. wfi
  113. ret
  114.  
  115.  
  116. go:
  117. mov x1, #0x9b200000
  118. movk x1, #0x3, lsl #32
  119.  
  120. mov x0, '!'
  121. str w0, [x1, 0x020]
  122. mov x0, '!'
  123. str w0, [x1, 0x020]
  124. mov x0, '!'
  125. str w0, [x1, 0x020]
  126. mov x0, '!'
  127. str w0, [x1, 0x020]
  128.  
  129. ret
  130. """, code)
  131. iface.writemem(code, util.data)
  132. p.dc_cvau(code, len(util.data))
  133. p.ic_ivau(code, len(util.data))
  134.  
  135. if 0:
  136. p.write32(0x292004008, 0xf3ffafff)
  137. p.write32(0x29200400c, 0xffa1f6ff)
  138. p.write32(0x292004010, 0xfbdfffff)
  139. p.write32(0x292004014, 0x3fffffff)
  140. p.write32(0x292004018, 0xffffffc0)
  141. p.write32(0x29200401c, 0xffffffff)
  142. p.write32(0x292004020, 0x1fff)
  143.  
  144. p.write32(0x292004008, 0)
  145. p.write32(0x29200400c, 0)
  146. p.write32(0x292004010, 0)
  147. p.write32(0x292004014, 0)
  148. p.write32(0x292004018, 0)
  149. p.write32(0x29200401c, 0)
  150. p.write32(0x292004020, 0)
  151.  
  152.  
  153. p.write32(0x290820940, 0xffffffff)
  154. p.write32(0x290820980, 0xffffffff)
  155.  
  156. p.write32(0x293820904, 0xffffffff)
  157. p.write32(0x293820940, 0xffffffff)
  158. p.write32(0x293820944, 0xffffffff)
  159. p.write32(0x293820980, 0xffffffff)
  160. p.write32(0x293820984, 0xffffffff)
  161.  
  162.  
  163. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x80)
  164. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x100)
  165. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x200)
  166. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x400)
  167. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x800)
  168. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x1000)
  169. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x2000)
  170. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x80000)
  171. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x40000)
  172. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x100000)
  173. p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x200000)
  174.  
  175. smc_addr = u.adt["arm-io/smc"].get_reg(0)[0]
  176. smc = SMCClient(u, smc_addr)
  177. smc.start()
  178. smc.start_ep(0x20)
  179. smcep = smc.epmap[0x20]
  180. smcep.write8("NTAP", 1)
  181. smc.work_for(1)
  182.  
  183. dart = DART.from_adt(u, "/arm-io/dart-aop",
  184. iova_range=(u.adt["/arm-io/dart-aop"].vm_base, 0x1000000000))
  185. dart.initialize()
  186.  
  187. aop = AOPClient(u, "/arm-io/aop", dart)
  188. aop.update_bootargs({
  189. 'p0CE': 0x20000,
  190. 'laCn': 0x0,
  191. 'tPOA': 0x1,
  192. "gila": 0x80,
  193. })
  194. aop.verbose = 4
  195.  
  196. p.dapf_init_all()
  197. aop.asc.OUTBOX_CTRL.val = 0x20001
  198. aop.start()
  199. for epno in [0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x27, 0x28]:
  200. aop.start_ep(epno)
  201. aop.work_for(1)
  202.  
  203. p.write32(0x28e100000 + 0x14, p.read32(0x28e100000 + 0x14) | 0x1)
  204.  
  205. print("go")
  206. p.call(util.sleep)
  207.  
Advertisement
Add Comment
Please, Sign In to add comment