@@ -687,7 +687,7 @@ def str2ident(s):
687
687
.upper ()
688
688
689
689
690
- def out_node (node , ident , val , name_alias = None ):
690
+ def out_node (node , ident , val , name_alias = None , deprecation_msg = None ):
691
691
# Writes a
692
692
#
693
693
# <node prefix>_<ident> = <val>
@@ -704,6 +704,9 @@ def out_node(node, ident, val, name_alias=None):
704
704
#
705
705
# 'name_alias' is used for reg-names and the like.
706
706
#
707
+ # If a 'deprecation_msg' string is passed, the generated identifiers will
708
+ # generate a warning if used, via __WARN(<deprecation_msg>)).
709
+ #
707
710
# Returns the identifier used for the macro that provides the value
708
711
# for 'ident' within 'node', e.g. DT_MFG_MODEL_CTL_GPIOS_PIN.
709
712
@@ -714,25 +717,25 @@ def out_node(node, ident, val, name_alias=None):
714
717
aliases .append (f"{ node_prefix } _{ name_alias } " )
715
718
aliases += [f"{ alias } _{ name_alias } " for alias in node_aliases (node )]
716
719
717
- return out (f"{ node_prefix } _{ ident } " , val , aliases )
720
+ return out (f"{ node_prefix } _{ ident } " , val , aliases , deprecation_msg )
718
721
719
722
720
- def out_node_s (node , ident , s , name_alias = None ):
723
+ def out_node_s (node , ident , s , name_alias = None , deprecation_msg = None ):
721
724
# Like out_node(), but emits 's' as a string literal
722
725
#
723
726
# Returns the generated macro name for 'ident'.
724
727
725
- return out_node (node , ident , quote_str (s ), name_alias )
728
+ return out_node (node , ident , quote_str (s ), name_alias , deprecation_msg )
726
729
727
730
728
- def out_node_init (node , ident , elms , name_alias = None ):
731
+ def out_node_init (node , ident , elms , name_alias = None , deprecation_msg = None ):
729
732
# Like out_node(), but generates an {e1, e2, ...} initializer with the
730
733
# elements in the iterable 'elms'.
731
734
#
732
735
# Returns the generated macro name for 'ident'.
733
736
734
737
return out_node (node , ident , "{" + ", " .join (map (str , elms )) + "}" ,
735
- name_alias )
738
+ name_alias , deprecation_msg )
736
739
737
740
738
741
def out_s (ident , val ):
@@ -744,17 +747,19 @@ def out_s(ident, val):
744
747
return out (ident , quote_str (val ))
745
748
746
749
747
- def out (ident , val , aliases = ()):
750
+ def out (ident , val , aliases = (), deprecation_msg = None ):
748
751
# Writes '#define <ident> <val>' to the header and '<ident>=<val>' to the
749
752
# the configuration file.
750
753
#
751
754
# Also writes any aliases listed in 'aliases' (an iterable). For the
752
755
# header, these look like '#define <alias> <ident>'. For the configuration
753
756
# file, the value is just repeated as '<alias>=<val>' for each alias.
754
757
#
758
+ # See out_node() for the meaning of 'deprecation_msg'.
759
+ #
755
760
# Returns the generated macro name for 'ident'.
756
761
757
- print ( f"#define DT_ { ident :40 } { val } " , file = header_file )
762
+ out_define ( ident , val , deprecation_msg , header_file )
758
763
primary_ident = f"DT_{ ident } "
759
764
760
765
# Exclude things that aren't single token values from .conf. At
@@ -767,7 +772,7 @@ def out(ident, val, aliases=()):
767
772
768
773
for alias in aliases :
769
774
if alias != ident :
770
- print ( f"#define DT_ { alias :40 } DT_{ ident } " , file = header_file )
775
+ out_define ( alias , " DT_" + ident , deprecation_msg , header_file )
771
776
if output_to_conf :
772
777
# For the configuration file, the value is just repeated for all
773
778
# the aliases
@@ -776,6 +781,17 @@ def out(ident, val, aliases=()):
776
781
return primary_ident
777
782
778
783
784
+ def out_define (ident , val , deprecation_msg , out_file ):
785
+ # out() helper for writing a #define. See out_node() for the meaning of
786
+ # 'deprecation_msg'.
787
+
788
+ s = f"#define DT_{ ident :40} "
789
+ if deprecation_msg :
790
+ s += fr' __WARN("{ deprecation_msg } ")'
791
+ s += f" { val } "
792
+ print (s , file = out_file )
793
+
794
+
779
795
def out_comment (s , blank_before = True ):
780
796
# Writes 's' as a comment to the header and configuration file. 's' is
781
797
# allowed to have multiple lines. blank_before=True adds a blank line
0 commit comments