Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
with
12 additions
and
1 deletion.
-
+11
−0
modifydevicetree.py
-
+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__": |
|
|