Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # SPDX-License-Identifier: MIT
- import sys, pathlib, time
- sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
- from m1n1.setup import *
- from m1n1 import asm
- from m1n1.fw.smc import SMCClient
- from m1n1.hw.dart import DART
- from m1n1.fw.aop.client import AOPClient
- from m1n1.fw.aop.ipc import *
- p.smp_start_secondaries()
- p.smp_stop_secondaries(True)
- rvbar = p.read64(u.adt["cpus"][0].cpu_impl_reg[0])& 0xffffffffffe
- print(hex(rvbar))
- code = u.malloc(0x1000)
- util = asm.ARMAsm("""
- overwrite:
- isb
- mrs x3, SCTLR_EL1
- bfc x3, #0, #1
- msr SCTLR_EL1, x3
- isb
- mov x3, 0
- .Lloop:
- ldrb w4, [x0, x3]
- strb w4, [x1, x3]
- add x3, x3, #1
- cmp x2, x3
- bne .Lloop
- isb
- mrs x3, SCTLR_EL1
- orr x3, x3, #1
- msr SCTLR_EL1, x3
- isb
- ret
- """, code)
- resp = asm.ARMAsm("""
- go:
- mov x1, #0x9b200000
- movk x1, #0x3, lsl #32
- mov x0, '!'
- str w0, [x1, 0x020]
- mov x0, '!'
- str w0, [x1, 0x020]
- mov x0, '!'
- str w0, [x1, 0x020]
- mov x0, '!'
- str w0, [x1, 0x020]
- ret
- """, rvbar)
- iface.writemem(code, util.data)
- p.dc_cvau(code, len(util.data))
- p.ic_ivau(code, len(util.data))
- code2 = u.malloc(0x1000)
- iface.writemem(code2, resp.data)
- p.dc_cvau(code2, len(resp.data))
- p.ic_ivau(code2, len(resp.data))
- p.call(util.overwrite, code2, rvbar, len(resp.data))
- code = u.malloc(0x1000)
- util = asm.ARMAsm("""
- #define sys_reg(op0, op1, CRn, CRm, op2) s##op0##_##op1##_c##CRn##_c##CRm##_##op2
- #define ULONG(x) (x)
- #define BIT(x) (1UL << (x))
- #define GENMASK(msb, lsb) ((BIT((msb + 1) - (lsb)) - 1) << (lsb))
- #define SYS_IMP_APL_ACC_OVRD sys_reg(3, 5, 15, 6, 0)
- #define ACC_OVRD_PWR_DN_SRM(x) ((ULONG(x)) << 13)
- #define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK GENMASK(16, 15)
- #define ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(x) ((ULONG(x)) << 15)
- #define ACC_OVRD_TRAIN_DOWN_LINK(x) ((ULONG(x)) << 17)
- #define ACC_OVRD_POWER_DOWN_CPM(x) ((ULONG(x)) << 25)
- #define ACC_OVRD_DISABLE_PIO_ON_WFI_CPU BIT(32)
- #define ACC_OVRD_DEEP_SLEEP BIT(34)
- #define SYS_IMP_APL_CYC_OVRD sys_reg(3, 5, 15, 5, 0)
- #define CYC_OVRD_WFI_MODE(x) ((ULONG(x)) << 24)
- #define CYC_OVRD_DISABLE_WFI_RET BIT(0)
- sleep:
- mrs x1, SYS_IMP_APL_ACC_OVRD
- orr x1, x1, #ACC_OVRD_PWR_DN_SRM(3)
- and x1, x1, #~ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP_MASK
- orr x1, x1, #ACC_OVRD_DIS_L2_FLUSH_ACC_SLEEP(2)
- orr x1, x1, #ACC_OVRD_TRAIN_DOWN_LINK(3)
- orr x1, x1, #ACC_OVRD_POWER_DOWN_CPM(3)
- orr x1, x1, #ACC_OVRD_DISABLE_PIO_ON_WFI_CPU
- orr x1, x1, #ACC_OVRD_DEEP_SLEEP
- msr SYS_IMP_APL_ACC_OVRD, x1
- mrs x1, SYS_IMP_APL_CYC_OVRD
- orr x1, x1, #CYC_OVRD_WFI_MODE(3)
- orr x1, x1, #CYC_OVRD_DISABLE_WFI_RET
- msr SYS_IMP_APL_CYC_OVRD, x1
- loop_wfi:
- isb
- wfi
- ret
- go:
- mov x1, #0x9b200000
- movk x1, #0x3, lsl #32
- mov x0, '!'
- str w0, [x1, 0x020]
- mov x0, '!'
- str w0, [x1, 0x020]
- mov x0, '!'
- str w0, [x1, 0x020]
- mov x0, '!'
- str w0, [x1, 0x020]
- ret
- """, code)
- iface.writemem(code, util.data)
- p.dc_cvau(code, len(util.data))
- p.ic_ivau(code, len(util.data))
- if 0:
- p.write32(0x292004008, 0xf3ffafff)
- p.write32(0x29200400c, 0xffa1f6ff)
- p.write32(0x292004010, 0xfbdfffff)
- p.write32(0x292004014, 0x3fffffff)
- p.write32(0x292004018, 0xffffffc0)
- p.write32(0x29200401c, 0xffffffff)
- p.write32(0x292004020, 0x1fff)
- p.write32(0x292004008, 0)
- p.write32(0x29200400c, 0)
- p.write32(0x292004010, 0)
- p.write32(0x292004014, 0)
- p.write32(0x292004018, 0)
- p.write32(0x29200401c, 0)
- p.write32(0x292004020, 0)
- p.write32(0x290820940, 0xffffffff)
- p.write32(0x290820980, 0xffffffff)
- p.write32(0x293820904, 0xffffffff)
- p.write32(0x293820940, 0xffffffff)
- p.write32(0x293820944, 0xffffffff)
- p.write32(0x293820980, 0xffffffff)
- p.write32(0x293820984, 0xffffffff)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x80)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x100)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x200)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x400)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x800)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x1000)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x2000)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x80000)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x40000)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x100000)
- p.write32(0x28e100000 + 0x2000 + 0x4000 + 0x200 * 3 + 0x5c, 0x200000)
- smc_addr = u.adt["arm-io/smc"].get_reg(0)[0]
- smc = SMCClient(u, smc_addr)
- smc.start()
- smc.start_ep(0x20)
- smcep = smc.epmap[0x20]
- smcep.write8("NTAP", 1)
- smc.work_for(1)
- dart = DART.from_adt(u, "/arm-io/dart-aop",
- iova_range=(u.adt["/arm-io/dart-aop"].vm_base, 0x1000000000))
- dart.initialize()
- aop = AOPClient(u, "/arm-io/aop", dart)
- aop.update_bootargs({
- 'p0CE': 0x20000,
- 'laCn': 0x0,
- 'tPOA': 0x1,
- "gila": 0x80,
- })
- aop.verbose = 4
- p.dapf_init_all()
- aop.asc.OUTBOX_CTRL.val = 0x20001
- aop.start()
- for epno in [0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x27, 0x28]:
- aop.start_ep(epno)
- aop.work_for(1)
- p.write32(0x28e100000 + 0x14, p.read32(0x28e100000 + 0x14) | 0x1)
- print("go")
- p.call(util.sleep)
Advertisement
Add Comment
Please, Sign In to add comment