From e124c5c7901091c6a627ed3a4737637fbacc32b0 Mon Sep 17 00:00:00 2001 From: zleoyu Date: Wed, 1 Jun 2022 17:48:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BF=AE=E6=94=B9rk3568.dtsi?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zleoyu Change-Id: I298a8a32a411cb6467b54c219c8bb783cdeaccbe --- modifyDtsi.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 modifyDtsi.py diff --git a/modifyDtsi.py b/modifyDtsi.py new file mode 100755 index 0000000..5551e1b --- /dev/null +++ b/modifyDtsi.py @@ -0,0 +1,89 @@ +from ast import Delete +import sys, os + +class Modify(): + def __init__(self, filePath) -> None: + self.filePath = filePath + self.lines = [] + + fp = open(self.filePath, 'r') + for line in fp: + self.lines.append(line) + fp.close() + + def saveAndClose(self): + s = ''.join(self.lines) + self.lines.clear() + fp = open(self.filePath, 'w') + fp.write(s) + fp.close() + + def positionSearch(self, positionText, startLineNum = 0): + linesLen = len(self.lines) + for lineNum in range(startLineNum + 1, linesLen): + if(positionText in self.lines[lineNum]): + return lineNum + return -1 + + def addItem(self, newText, positionInedx, rowNume): + assert rowNume >= 0,"rowNum含义为“要将newText添加到positionSearch所定位的条目下的第几行”,可以等于0及添加到当前行,将当前行往下挤,但不可以为负数,如需要在positionSearch所定位的条目上方添加复数行,请按顺序调用addItem函数,且rowNum都填入0" + item = '' + if("is not set" in newText): + item = newText[2:-11] + else: + item = newText[:-2] + + # 如果要添加的内容已经存在则直接返回 + for line in self.lines: + if(item in line): + if ((item + "=y" in line) or (item + " is not set" in line)): + print("Already has this item: " + item) + return + + assert positionInedx >= 0, "If want to add an item, first 'positionInedx' must be >= 0" + lineNum = positionInedx + rowNume + self.lines.insert(lineNum, newText+'\n') + if(rowNume <= 0): + positionInedx += 1 + print("Add item: "+item) + + def deleteLines(self, startLineIndex, endLineIndex): + for i in range(endLineIndex - startLineIndex): + self.lines.pop(startLineIndex) + + +if __name__ == "__main__": + path = sys.argv[1] + modify = Modify(path) + print("Start to modifying file", sys.argv[1]) + + test = [' compatible = "rockchip, rk3568-mali", "arm,mali-bifrost";', + ' reg = <0x0 0xfde60000 0x0 0x20000>;', + '', + ' interrupts = ,', + ' ,', + ' ;', + ' interrupt-names = "job", "mmu", "gpu";', + ' clocks = <&scmi_clk 1>, <&cru CLK_GPU>;', + ' clock-names = "core", "bus";', + ' operating-points-v2 = <&gpu_opp_table>;', + '', + ' #cooling-cells = <2>;', + ' power-domains = <&power RK3568_PD_GPU>;', + ' status = "disabled";'] + + if(modify.positionSearch("gpu_power_model: power-model",0) == -1): + print("rk3568.dtsi arealy modified") + exit() + + positionInedx1 = modify.positionSearch("gpu: gpu@fde60000",0) + if(positionInedx1 >= 0): + positionInedx2 = modify.positionSearch("};",positionInedx1) + modify.deleteLines(positionInedx1 + 1, positionInedx2 + 1) + + for i in range(len(test)): + modify.addItem(test[i], positionInedx1, i + 1) + + modify.saveAndClose() + + print("Succese") \ No newline at end of file -- Gitee