Skip to content

Commit

Permalink
Add a dedicated type for address properties
Browse files Browse the repository at this point in the history
There are a few properties which are sized based on "#address-cells" and
"#size-cells". "reg" is of course the most common, but there's a growing
number in /chosen. As these properties need special parsing to decode,
give them a dedicated type.

Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
robherring committed Mar 8, 2024
1 parent 5c8869e commit 08eff8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions dtschema/dtb.py
Expand Up @@ -28,7 +28,8 @@
'uint32': u32,
'int64': s64,
'uint64': u64,
'phandle': u32
'phandle': u32,
'address': u32
}


Expand Down Expand Up @@ -451,15 +452,15 @@ def fixup_interrupts(dt, icells):
i += cells


def fixup_addresses(dt, ac, sc):
def fixup_addresses(validator, dt, ac, sc):
for k, v in dt.items():
if isinstance(v, dict):
if '#address-cells' in dt:
ac = _get_cells_size(dt,'#address-cells')
if '#size-cells' in dt:
sc = _get_cells_size(dt, '#size-cells')
fixup_addresses(v, ac, sc)
elif k == 'reg':
fixup_addresses(validator, v, ac, sc)
elif 'address' in validator.property_get_type(k):
i = 0
dt[k] = []
val = v[0]
Expand All @@ -486,7 +487,7 @@ def fdt_unflatten(validator, dtb):
#print(phandle_loc)
fixup_gpios(dt)
fixup_interrupts(dt, 1)
fixup_addresses(dt, 2, 1)
fixup_addresses(validator, dt, 2, 1)
fixup_phandles(validator, dt)

# pprint.pprint(dt, compact=True)
Expand Down
2 changes: 1 addition & 1 deletion dtschema/schemas/reg.yaml
Expand Up @@ -30,7 +30,7 @@ properties:
- $ref: types.yaml#/definitions/uint32-matrix

reg:
$ref: types.yaml#/definitions/uint32-matrix
$ref: types.yaml#/definitions/address

reg-io-width:
$ref: types.yaml#/definitions/uint32
Expand Down
6 changes: 6 additions & 0 deletions dtschema/schemas/types.yaml
Expand Up @@ -349,3 +349,9 @@ definitions:
const: 0
additionalItems:
$ref: "#/definitions/cell"

address:
$ref: "#/definitions/uint32-matrix"
items:
minItems: 1
maxItems: 5 # At most 3 address cells and 2 size cells
2 changes: 1 addition & 1 deletion dtschema/validator.py
Expand Up @@ -33,7 +33,7 @@ def _merge_dim(dim1, dim2):
return tuple(d)


type_re = re.compile('(flag|u?int(8|16|32|64)(-(array|matrix))?|string(-array)?|phandle(-array)?)')
type_re = re.compile('(address|flag|u?int(8|16|32|64)(-(array|matrix))?|string(-array)?|phandle(-array)?)')


def _extract_prop_type(props, schema, propname, subschema, is_pattern):
Expand Down

0 comments on commit 08eff8e

Please sign in to comment.