Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 67aa7a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions modifydevicetree.py
Expand Up @@ -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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion readdevicetree.py
Expand Up @@ -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__":
Expand Down

0 comments on commit 67aa7a5

Please sign in to comment.