zephyr/scripts/dts/extract/default.py
Kumar Gala fc5e23365e dts: Add proper handling for boolean properties
We've never handled boolean properties well, if we had a boolean that
existed we'd generate a define of 'True' and if the boolean didn't exist
than nothing would be generated.  So there was no easy way to tell that
the boolean wasn't defined.

Now if we mark a property as boolean in the yaml, we will generate a
define for it regardless if it exists or not.  If it exists we'll
set the value to 1, and if it doesn't to 0.

Fixes #8376

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-19 07:55:34 -05:00

69 lines
2.1 KiB
Python

#
# Copyright (c) 2018 Bobby Noelte
#
# SPDX-License-Identifier: Apache-2.0
#
from extract.globals import *
from extract.directive import DTDirective
##
# @brief Manage directives in a default way.
#
class DTDefault(DTDirective):
def __init__(self):
pass
##
# @brief Extract directives in a default way
#
# @param node_address Address of node owning the clockxxx definition.
# @param yaml YAML definition for the owning node.
# @param prop property name
# @param prop type (string, boolean, etc)
# @param def_label Define label string of node owning the directive.
#
def extract(self, node_address, yaml, prop, prop_type, def_label):
prop_def = {}
prop_alias = {}
if prop_type == 'boolean':
if prop in reduced[node_address]['props'].keys():
prop_values = 1
else:
prop_values = 0
else:
prop_values = reduced[node_address]['props'][prop]
if isinstance(prop_values, list):
for i, prop_value in enumerate(prop_values):
prop_name = convert_string_to_label(prop)
label = def_label + '_' + prop_name
if isinstance(prop_value, str):
prop_value = "\"" + prop_value + "\""
prop_def[label + '_' + str(i)] = prop_value
else:
prop_name = convert_string_to_label(prop)
label = def_label + '_' + prop_name
if prop_values == 'parent-label':
prop_values = find_parent_prop(node_address, 'label')
if isinstance(prop_values, str):
prop_values = "\"" + prop_values + "\""
prop_def[label] = prop_values
# generate defs for node aliases
if node_address in aliases:
for i in aliases[node_address]:
alias_label = convert_string_to_label(i)
alias = alias_label + '_' + prop_name
prop_alias[alias] = label
insert_defs(node_address, prop_def, prop_alias)
##
# @brief Management information for directives handled by default.
default = DTDefault()