Фиксы, я хзлол

пытаеся выйти из лупа pbl что бы перейти в sbl1 а далее в uefi->mainos
This commit is contained in:
SashegDev
2026-09-15 20:17:16 +00:00
parent 06d2f87545
commit 14cf9b455a
2 changed files with 231 additions and 0 deletions
+224
View File
@@ -4023,6 +4023,230 @@ def main():
save(d, 'img0_b47.elf') save(d, 'img0_b47.elf')
# b48 = b47 + S12-wrapper blx->bl (stay Thumb, kill mode switch):
# S12 blob rewritten Thumb keep-only in scaffold (no blx target change).
# BLX2BL convention: set bit12 of 2nd halfword.
# b47 = b46 minus slide-retarget (it derails early solo):
# the 0x8006D2E->slide->PBL-stub restart is load-bearing (re-runs
# SBL1-entry + fresh regs); NOPing the slide kills boot. Reverted.
# b46 = b45 + skip desert call (0x8007790 bl EB0A -> NOPs):
# b44/b45 proved any desert entry derails on zero tables; caller
# discards r0 right after (mov r0,sb), single call site. NOPS-table
# rationale: unmodellable init with ignored result.
# b45 = b44 + r5-lock break (0x800EB84 movs r5,#1 -> NOP):
# call-C (ARM helper) returns 0 on zero-state, forcing r5=1 which
# bypasses the table switch into D-spin forever. With r5==0 the
# switch runs ([sl] currently defaults to epilogue); S20 decides.
# b44 = b43 + slide-hijack fix: case-arm at 0x8006D2E does
# b.n 0x8006832 into zero padding; the slide runs up into OUR PBL
# stub (0x80068C0) which re-runs boot regs and jumps to sbl_main
# every ~500 insns. Real target is first nonzero code at 0x80069FE
# (return-0 helper); retarget the branch there, skipping the mines.
# b43 = b42 revert (frameless hangs: tail bx lr loops on
# stale lr). The push is load-bearing (saves caller return for S12
# keep-path). PBL contract instead: keep returns to tail, default
# diverts (S12 scaffold change, no image bytes for that part).
# b42 = b41 + frameless S12-wrapper (push/pop removed):
# tail pop read garbage pc (->0x0/0x407) on misaligned sp: +8B x27/K.
# S12 needs no pushed lr (both paths bx lr to wrapper tail); r4
# untouched by blob; r0=0 via tail movs. Wrapper now sp-neutral.
# b41 = b40 + desert-call retarget (0x8007790 bl EB90 -> EB0A):
# mid-function entry skipped the 48B prologue push; epilogue pop.w
# then over-popped 48B per S20 visit (100B/Kinsn creep, S20-rerun trap).
# Via prologue the frame balances and S20-pop returns to the caller.
# b40 = b39 + S12-wrapper pop restore (0x8007B66 bx ip -> pop):
# b25 chained the wrapper pop to bx ip; with S12 preserving sp the
# frame is intact, while bx ip orphaned 8B per call (105M sp-smash).
# Content below = b39 body with the 0x8007B66 hunk reverted to pop.
# naked clock leaf never sets r3 (stale stacked return addr,
# observed 0x8007975); the store writes 0xffff over live code,
# faulting the next fetch there. Peripheral write, nothing in emu
# reads it back (polls use scaffolded [0x73A100]). Same rationale
# as the b17 stm NOP. 2B->2B, no eating.
d = bytearray(base)
for va, (a, b) in BLX2BL.items():
set4(d, va, b)
for va, exp, new in [
(0x802F664, 'e4f77efc', 'c046c046'),
(0x802F672, 'e6f7bbfa', 'c046c046'),
(0x802F678, 'e9f7fef9', 'c046c046'),
(0x801B71E, '9847fee7', 'c046c046'),
(0x8008396, 'fef780f9', 'c046c046'),
(0x8016184, 'fdf790fc', 'c046c046'),
(0x801B76C, '280b0508', '00000708'),
(0x8017AFC, 'bde8fc87', 'eef74fb8'),
(0x802F690, '9847fee7', 'c046c046'),
(0x801671C, '9847fee7', 'c046c046'),
(0x8013BAC, 'f8bd0a4a', 'f3f730b8'),
(0x801B6BE, 'bde8f081', 'ebf7c3ba'),
(0x8016720, '10bd0000', 'f0f7b2ba'),
(0x8034810, 'bde8fc87', 'd2f76eba'),
(0x8007798, 'bde8f08f', 'fff7c3ba'),
(0x8016334, 'f0f7a4ff', 'c046c046'),
(0x8016342, 'f0f79eef', 'f0f79dbf'),
(0x802F9A0, 'ffe70648', 'd7f7c4b9'),
(0x802F9B2, 'fee78817', 'd7f7bbb9'),
(0x802F9A2, 'c4b943f2', 'd7f7c3b9'),
(0x800EB96, 'bde8fe8f', 'f8f7cfb8'),
(0x8007916, 'bde8f09f', 'fff720ba'),
]:
assert hx(d, va) == exp, (hex(va), hx(d, va))
set4(d, va, new)
# Full bl idiom at 0x8006682 (bl + pop, 6B) -> NOPs (see b18).
o = off(0x8006682)
assert d[o:o + 6].hex() == '00f001f807bd', hx(d, 0x8006682, 6)
d[o:o + 6] = bytes.fromhex('c046c046c046')
o = off(0x8013AA8)
assert d[o:o + 4].hex() == '07f026be', hx(d, 0x8013AA8)
d[o:o + 4] = bytes.fromhex('c046c046')
o = off(0x8013BA6)
assert d[o:o + 2].hex() == 'b888', (hex(0x8013BA6), hx(d, 0x8013BA6, 2))
d[o:o + 2] = bytes.fromhex('ff20')
# b40: S12-wrapper pop RESTORED (revert b25 chain at this site).
# b25 sent pop to bx ip because the pop read scratch; with S12
# preserving sp the frame is intact, while bx ip orphaned 8B per
# call and smashed sp into text at 105M. S16 keeps serving B66.
o = off(0x8007B66)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x8007B66, 2)
# Clock S11 (see b24).
o = off(0x800E988)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x800E988, 2)
d[o:o + 2] = bytes.fromhex('7047')
# Poll re-init skip (see b27).
o = off(0x8007748)
assert d[o:o + 2].hex() == '96b1', hx(d, 0x8007748, 2)
d[o:o + 2] = bytes.fromhex('14e0')
# Poll-epilogue add NOP (see b28).
o = off(0x8007794)
assert d[o:o + 2].hex() == '07b0', hx(d, 0x8007794, 2)
d[o:o + 2] = bytes.fromhex('c046')
# Partition wrap-check (see b33).
o = off(0x801844E)
assert d[o:o + 2].hex() == '04d3', hx(d, 0x801844E, 2)
d[o:o + 2] = bytes.fromhex('04e0')
# Hang-site neutralize (see b34).
o = off(0x8018458)
assert d[o:o + 2].hex() == 'fee7', hx(d, 0x8018458, 2)
d[o:o + 2] = bytes.fromhex('ffe7')
# Clock-store NOP: str r1,[r3] (2B 1960) -> mov r8,r8 (2B c046).
o = off(0x800E986)
assert d[o:o + 2].hex() == '1960', hx(d, 0x800E986, 2)
d[o:o + 2] = bytes.fromhex('c046')
# b41 retarget.
o = off(0x8007790)
assert d[o:o + 4].hex() == '07f0fef9', hx(d, 0x8007790)
d[o:o + 4] = bytes.fromhex('07f0bbfb')
# b42 frameless wrapper.
o = off(0x8007B5E)
assert d[o:o + 2].hex() == '10b5', hx(d, 0x8007B5E, 2)
d[o:o + 2] = bytes.fromhex('c046')
o = off(0x8007B66)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x8007B66, 2)
d[o:o + 2] = bytes.fromhex('7047')
# b43 revert frameless.
o = off(0x8007B5E)
assert d[o:o + 2].hex() == 'c046', hx(d, 0x8007B5E, 2)
d[o:o + 2] = bytes.fromhex('10b5')
o = off(0x8007B66)
assert d[o:o + 2].hex() == '7047', hx(d, 0x8007B66, 2)
d[o:o + 2] = bytes.fromhex('10bd')
# b45 r5-lock break.
o = off(0x800EB84)
assert d[o:o + 2].hex() == '0125', hx(d, 0x800EB84, 2)
d[o:o + 2] = bytes.fromhex('c046')
# b46 skip desert.
o = off(0x8007790)
assert d[o:o + 4].hex() == '07f0bbfb', hx(d, 0x8007790)
d[o:o + 4] = bytes.fromhex('c046c046')
# b48 blx->bl.
o = off(0x8007B60)
assert d[o:o + 4].hex() == 'fef700ef', hx(d, 0x8007B60)
d[o:o + 4] = bytes.fromhex('fef700ff')
save(d, 'img0_b48.elf')
+7
View File
@@ -229,6 +229,10 @@ def main():
_spd[0] = _spn _spd[0] = _spn
if _tpop is not None and _prev[0] == 0x8007B66 and len(_tpop) < 3000: if _tpop is not None and _prev[0] == 0x8007B66 and len(_tpop) < 3000:
_tpop.append((count[0], addr)) _tpop.append((count[0], addr))
_inin = 0x08006964 <= addr < 0x080069F0
if _inin and not _s12in[0]:
_s12n[0] += 1
_s12in[0] = _inin
if count[0] % 200000 == 0: if count[0] % 200000 == 0:
from unicorn.arm_const import UC_ARM_REG_SP as _SX from unicorn.arm_const import UC_ARM_REG_SP as _SX
_RR = mu.reg_read _RR = mu.reg_read
@@ -468,6 +472,8 @@ def main():
from unicorn.arm_const import UC_ARM_REG_PC as _PC from unicorn.arm_const import UC_ARM_REG_PC as _PC
_nulllog = [] _nulllog = []
_nstale = [0] _nstale = [0]
_s12n = [0]
_s12in = [False]
_nsrc = {} _nsrc = {}
_halt_on_null = "--haltonnull" in sys.argv _halt_on_null = "--haltonnull" in sys.argv
@@ -825,6 +831,7 @@ def main():
print(f" insn#{n} {pc:#x} sp={sp:#x}") print(f" insn#{n} {pc:#x} sp={sp:#x}")
if _nulllog: if _nulllog:
print('null-stale-diverts:', _nstale[0]) print('null-stale-diverts:', _nstale[0])
print('s12-entries:', _s12n[0])
print('null-src-top:', sorted(_nsrc.items(), key=lambda kv: -kv[1])[:10]) print('null-src-top:', sorted(_nsrc.items(), key=lambda kv: -kv[1])[:10])
print(f"null-entries: {len(_nulllog)}") print(f"null-entries: {len(_nulllog)}")
for n, r, lr, sp in _nulllog: for n, r, lr, sp in _nulllog: