From ed7f2e0833c25fdc67e0d2c1e6d6915275407569 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Thu, 29 May 2025 10:05:10 +0200 Subject: [PATCH] scripts: dts: dtlib: preserve order of properties in DTS output Ensure that the order of properties in the output DTS file matches the order in which they are defined in the DTS source files by moving props to the end of the dictionary when they are accessed. Signed-off-by: Luca Burelli --- scripts/dts/python-devicetree/src/devicetree/dtlib.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/dts/python-devicetree/src/devicetree/dtlib.py b/scripts/dts/python-devicetree/src/devicetree/dtlib.py index e987ad5d9e9..e4c339da3c9 100644 --- a/scripts/dts/python-devicetree/src/devicetree/dtlib.py +++ b/scripts/dts/python-devicetree/src/devicetree/dtlib.py @@ -179,12 +179,13 @@ class Node: def _get_prop(self, name: str) -> 'Property': # Returns the property named 'name' on the node, creating it if it - # doesn't already exist + # doesn't already exist. Move the entry to the end of the props + # dictionary so the order is preserved in the output DTS file. - prop = self.props.get(name) + prop = self.props.pop(name, None) if not prop: prop = Property(self, name) - self.props[name] = prop + self.props[name] = prop return prop def _del(self) -> None: