Permalink
Browse files

set chip-epoch and security-domain in device tree by replacing two un…

…used variables, support reading device trees outside an im4p
  • Loading branch information...
zhuowei committed Jul 18, 2018
1 parent 41b4813 commit 67aa7a5bf4bd68d351d09556dabdc59d2b479893
Showing with 12 additions and 1 deletion.
  1. +11 −0 modifydevicetree.py
  2. +1 −1 readdevicetree.py
@@ -18,6 +18,9 @@ def writenode(nodebytes, nodeoffset, nodedepth):
ptr += writenode(nodebytes, nodeoffset + ptr, nodedepth + 1)
return ptr
def padStringNull(instr, lenstr=32):
return instr.encode("ascii") + b"\x00"*(lenstr - len(instr))
def writeproperty(nodebytes, nodeoffset, nodedepth):
kPropNameLength = 32
propname = nodebytes[nodeoffset:nodeoffset + kPropNameLength].rstrip(b"\x00").decode("utf-8")
@@ -32,6 +35,14 @@ def writeproperty(nodebytes, nodeoffset, nodedepth):
if propname == "random-seed":
print("setting random seed")
w32(nodebytes, nodeoffset + ptr, 0xdeadf00d)
if propname == "dram-vendor-id":
print("Removing dram-vendor-id")
nodebytes[nodeoffset:nodeoffset + kPropNameLength] = padStringNull("chip-epoch")
nodebytes[nodeoffset + ptr:nodeoffset + ptr + proplen] = b"\x00" * proplen
if propname == "display-corner-radius":
print("Removing display-corner-radius")
nodebytes[nodeoffset:nodeoffset + kPropNameLength] = padStringNull("security-domain")
nodebytes[nodeoffset + ptr:nodeoffset + ptr + proplen] = b"\x00" * proplen
ptr += proplen
ptr = (ptr + 0x3) & ~0x3 #round up to nearest 4
return ptr
@@ -50,7 +50,7 @@ def writeproperty(nodebytes, nodeoffset, nodedepth):
def printone(filename):
with open(filename, "rb") as infile:
indata = infile.read()
devicetreebytes = devicetreefromim4p(indata)
devicetreebytes = devicetreefromim4p(indata) if indata[0x7:0x7+4] == b"IM4P" else indata
writenode(devicetreebytes, 0, 0)
if __name__ == "__main__":

0 comments on commit 67aa7a5

Please sign in to comment.