Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 1 | # Copyright (c) 2018-2019 Linaro |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019 Nordic Semiconductor ASA |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | import os |
Martí Bolívar | 269f350 | 2020-07-01 12:17:02 -0700 | [diff] [blame] | 7 | import pickle |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 8 | import sys |
| 9 | |
| 10 | ZEPHYR_BASE = os.environ.get("ZEPHYR_BASE") |
| 11 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/dts")) |
| 12 | |
| 13 | import edtlib |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 14 | |
| 15 | # Types we support |
| 16 | # 'string', 'int', 'hex', 'bool' |
| 17 | |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 18 | doc_mode = os.environ.get('KCONFIG_DOC_MODE') == "1" |
Sebastian Bøe | cd43543 | 2019-02-11 15:57:34 +0100 | [diff] [blame] | 19 | |
Ulf Magnusson | ba312fe | 2019-03-20 19:30:29 +0100 | [diff] [blame] | 20 | if not doc_mode: |
Martí Bolívar | 269f350 | 2020-07-01 12:17:02 -0700 | [diff] [blame] | 21 | EDT_PICKLE = os.environ.get("EDT_PICKLE") |
Kumar Gala | 9aefdaf | 2020-04-15 10:32:41 -0500 | [diff] [blame] | 22 | |
Martí Bolívar | 269f350 | 2020-07-01 12:17:02 -0700 | [diff] [blame] | 23 | # The "if" handles a missing dts. |
| 24 | if EDT_PICKLE is not None and os.path.isfile(EDT_PICKLE): |
| 25 | with open(EDT_PICKLE, 'rb') as f: |
| 26 | edt = pickle.load(f) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 27 | else: |
| 28 | edt = None |
| 29 | |
Kumar Gala | 1baf2f3 | 2019-09-04 14:14:26 -0500 | [diff] [blame] | 30 | |
| 31 | def _warn(kconf, msg): |
| 32 | print("{}:{}: WARNING: {}".format(kconf.filename, kconf.linenr, msg)) |
| 33 | |
| 34 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 35 | def _dt_units_to_scale(unit): |
| 36 | if not unit: |
| 37 | return 0 |
| 38 | if unit in {'k', 'K'}: |
| 39 | return 10 |
| 40 | if unit in {'m', 'M'}: |
| 41 | return 20 |
| 42 | if unit in {'g', 'G'}: |
| 43 | return 30 |
| 44 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 45 | |
| 46 | def dt_chosen_label(kconf, _, chosen): |
| 47 | """ |
| 48 | This function takes a 'chosen' property and treats that property as a path |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 49 | to an EDT node. If it finds an EDT node, it will look to see if that node |
| 50 | has a "label" property and return the value of that "label", if not we |
| 51 | return an empty string. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 52 | """ |
| 53 | if doc_mode or edt is None: |
| 54 | return "" |
| 55 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 56 | node = edt.chosen_node(chosen) |
| 57 | if not node: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 58 | return "" |
| 59 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 60 | if "label" not in node.props: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 61 | return "" |
| 62 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 63 | return node.props["label"].val |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 64 | |
| 65 | |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame] | 66 | def dt_chosen_enabled(kconf, _, chosen): |
| 67 | """ |
| 68 | This function returns "y" if /chosen contains a property named 'chosen' |
| 69 | that points to an enabled node, and "n" otherwise |
| 70 | """ |
| 71 | if doc_mode or edt is None: |
| 72 | return "n" |
| 73 | |
| 74 | node = edt.chosen_node(chosen) |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 75 | return "y" if node and node.status == "okay" else "n" |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame] | 76 | |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 77 | |
Martí Bolívar | 7ff3ebc | 2020-04-23 12:28:06 -0700 | [diff] [blame] | 78 | def dt_chosen_path(kconf, _, chosen): |
| 79 | """ |
| 80 | This function takes a /chosen node property and returns the path |
| 81 | to the node in the property value, or the empty string. |
| 82 | """ |
| 83 | if doc_mode or edt is None: |
| 84 | return "n" |
| 85 | |
| 86 | node = edt.chosen_node(chosen) |
| 87 | |
| 88 | return node.path if node else "" |
| 89 | |
| 90 | |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 91 | def dt_node_enabled(kconf, name, node): |
| 92 | """ |
| 93 | This function is used to test if a node is enabled (has status |
| 94 | 'okay') or not. |
| 95 | |
| 96 | The 'node' argument is a string which is either a path or an |
| 97 | alias, or both, depending on 'name'. |
| 98 | |
| 99 | If 'name' is 'dt_path_enabled', 'node' is an alias or a path. If |
| 100 | 'name' is 'dt_alias_enabled, 'node' is an alias. |
| 101 | """ |
| 102 | |
| 103 | if doc_mode or edt is None: |
| 104 | return "n" |
| 105 | |
| 106 | if name == "dt_alias_enabled": |
| 107 | if node.startswith("/"): |
| 108 | # EDT.get_node() works with either aliases or paths. If we |
| 109 | # are specifically being asked about an alias, reject paths. |
| 110 | return "n" |
| 111 | else: |
| 112 | # Make sure this is being called appropriately. |
| 113 | assert name == "dt_path_enabled" |
| 114 | |
| 115 | try: |
| 116 | node = edt.get_node(node) |
| 117 | except edtlib.EDTError: |
| 118 | return "n" |
| 119 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 120 | return "y" if node and node.status == "okay" else "n" |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 121 | |
| 122 | |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 123 | def dt_nodelabel_enabled(kconf, _, label): |
| 124 | """ |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 125 | This function is like dt_node_enabled(), but the 'label' argument |
| 126 | should be a node label, like "foo" is here: |
| 127 | |
| 128 | foo: some-node { ... }; |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 129 | """ |
| 130 | if doc_mode or edt is None: |
| 131 | return "n" |
| 132 | |
Martí Bolívar | 0682c46 | 2020-04-22 17:59:23 -0700 | [diff] [blame] | 133 | node = edt.label2node.get(label) |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 134 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 135 | return "y" if node and node.status == "okay" else "n" |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 136 | |
| 137 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 138 | def _node_reg_addr(node, index, unit): |
| 139 | if not node: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 140 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 141 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 142 | if not node.regs: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 143 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 144 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 145 | if int(index) >= len(node.regs): |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 146 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 147 | |
Kumar Gala | 8af311a | 2020-03-13 12:43:56 -0500 | [diff] [blame] | 148 | if node.regs[int(index)].addr is None: |
| 149 | return 0 |
| 150 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 151 | return node.regs[int(index)].addr >> _dt_units_to_scale(unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 152 | |
| 153 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 154 | def _node_reg_size(node, index, unit): |
| 155 | if not node: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 156 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 157 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 158 | if not node.regs: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 159 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 160 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 161 | if int(index) >= len(node.regs): |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 162 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 163 | |
Kumar Gala | 8af311a | 2020-03-13 12:43:56 -0500 | [diff] [blame] | 164 | if node.regs[int(index)].size is None: |
| 165 | return 0 |
| 166 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 167 | return node.regs[int(index)].size >> _dt_units_to_scale(unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 168 | |
| 169 | |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 170 | def _node_int_prop(node, prop): |
| 171 | if not node: |
| 172 | return 0 |
| 173 | |
| 174 | if prop not in node.props: |
| 175 | return 0 |
| 176 | |
| 177 | if node.props[prop].type != "int": |
| 178 | return 0 |
| 179 | |
| 180 | return node.props[prop].val |
| 181 | |
| 182 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 183 | def _dt_chosen_reg_addr(kconf, chosen, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 184 | """ |
| 185 | This function takes a 'chosen' property and treats that property as a path |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 186 | to an EDT node. If it finds an EDT node, it will look to see if that |
| 187 | nodnode has a register at the given 'index' and return the address value of |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 188 | that reg, if not we return 0. |
| 189 | |
| 190 | The function will divide the value based on 'unit': |
| 191 | None No division |
| 192 | 'k' or 'K' divide by 1024 (1 << 10) |
| 193 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 194 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 195 | """ |
| 196 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 197 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 198 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 199 | node = edt.chosen_node(chosen) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 200 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 201 | return _node_reg_addr(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 202 | |
| 203 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 204 | def _dt_chosen_reg_size(kconf, chosen, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 205 | """ |
| 206 | This function takes a 'chosen' property and treats that property as a path |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 207 | to an EDT node. If it finds an EDT node, it will look to see if that node |
| 208 | has a register at the given 'index' and return the size value of that reg, |
| 209 | if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 210 | |
| 211 | The function will divide the value based on 'unit': |
| 212 | None No division |
| 213 | 'k' or 'K' divide by 1024 (1 << 10) |
| 214 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 215 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 216 | """ |
| 217 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 218 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 219 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 220 | node = edt.chosen_node(chosen) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 221 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 222 | return _node_reg_size(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 223 | |
| 224 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 225 | def dt_chosen_reg(kconf, name, chosen, index=0, unit=None): |
| 226 | """ |
| 227 | This function just routes to the proper function and converts |
| 228 | the result to either a string int or string hex value. |
| 229 | """ |
| 230 | if name == "dt_chosen_reg_size_int": |
| 231 | return str(_dt_chosen_reg_size(kconf, chosen, index, unit)) |
| 232 | if name == "dt_chosen_reg_size_hex": |
| 233 | return hex(_dt_chosen_reg_size(kconf, chosen, index, unit)) |
| 234 | if name == "dt_chosen_reg_addr_int": |
| 235 | return str(_dt_chosen_reg_addr(kconf, chosen, index, unit)) |
| 236 | if name == "dt_chosen_reg_addr_hex": |
| 237 | return hex(_dt_chosen_reg_addr(kconf, chosen, index, unit)) |
| 238 | |
| 239 | |
| 240 | def _dt_node_reg_addr(kconf, path, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 241 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 242 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 243 | finds an EDT node, it will look to see if that node has a register at the |
| 244 | given 'index' and return the address value of that reg, if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 245 | |
| 246 | The function will divide the value based on 'unit': |
| 247 | None No division |
| 248 | 'k' or 'K' divide by 1024 (1 << 10) |
| 249 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 250 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 251 | """ |
| 252 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 253 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 254 | |
| 255 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 256 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 257 | except edtlib.EDTError: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 258 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 259 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 260 | return _node_reg_addr(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 261 | |
| 262 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 263 | def _dt_node_reg_size(kconf, path, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 264 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 265 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 266 | finds an EDT node, it will look to see if that node has a register at the |
| 267 | given 'index' and return the size value of that reg, if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 268 | |
| 269 | The function will divide the value based on 'unit': |
| 270 | None No division |
| 271 | 'k' or 'K' divide by 1024 (1 << 10) |
| 272 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 273 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 274 | """ |
| 275 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 276 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 277 | |
| 278 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 279 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 280 | except edtlib.EDTError: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 281 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 282 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 283 | return _node_reg_size(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 284 | |
| 285 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 286 | def dt_node_reg(kconf, name, path, index=0, unit=None): |
| 287 | """ |
| 288 | This function just routes to the proper function and converts |
| 289 | the result to either a string int or string hex value. |
| 290 | """ |
| 291 | if name == "dt_node_reg_size_int": |
| 292 | return str(_dt_node_reg_size(kconf, path, index, unit)) |
| 293 | if name == "dt_node_reg_size_hex": |
| 294 | return hex(_dt_node_reg_size(kconf, path, index, unit)) |
| 295 | if name == "dt_node_reg_addr_int": |
| 296 | return str(_dt_node_reg_addr(kconf, path, index, unit)) |
| 297 | if name == "dt_node_reg_addr_hex": |
| 298 | return hex(_dt_node_reg_addr(kconf, path, index, unit)) |
| 299 | |
| 300 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 301 | def dt_node_has_bool_prop(kconf, _, path, prop): |
| 302 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 303 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 304 | finds an EDT node, it will look to see if that node has a boolean property |
| 305 | by the name of 'prop'. If the 'prop' exists it will return "y" otherwise |
| 306 | we return "n". |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 307 | """ |
| 308 | if doc_mode or edt is None: |
| 309 | return "n" |
| 310 | |
| 311 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 312 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 313 | except edtlib.EDTError: |
| 314 | return "n" |
| 315 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 316 | if prop not in node.props: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 317 | return "n" |
| 318 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 319 | if node.props[prop].type != "boolean": |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 320 | return "n" |
| 321 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 322 | if node.props[prop].val: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 323 | return "y" |
| 324 | |
| 325 | return "n" |
| 326 | |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame^] | 327 | def dt_node_has_prop(kconf, _, label, prop): |
| 328 | """ |
| 329 | This function takes a 'label' and looks for an EDT node for that label. If |
| 330 | it finds an EDT node, it will look to see if that node has a property |
| 331 | by the name of 'prop'. If the 'prop' exists it will return "y" otherwise |
| 332 | we return "n". |
| 333 | """ |
| 334 | |
| 335 | if doc_mode or edt is None: |
| 336 | return "n" |
| 337 | |
| 338 | try: |
| 339 | node = edt.label2node.get(label) |
| 340 | except edtlib.EDTError: |
| 341 | return "n" |
| 342 | |
| 343 | if node is None: |
| 344 | return "n" |
| 345 | |
| 346 | if prop in node.props: |
| 347 | return "y" |
| 348 | |
| 349 | return "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 350 | |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 351 | def dt_node_int_prop(kconf, name, path, prop): |
| 352 | """ |
| 353 | This function takes a 'path' and property name ('prop') looks for an EDT |
| 354 | node at that path. If it finds an EDT node, it will look to see if that |
| 355 | node has a property called 'prop' and if that 'prop' is an integer type |
| 356 | will return the value of the property 'prop' as either a string int or |
| 357 | string hex value, if not we return 0. |
| 358 | """ |
| 359 | |
| 360 | if doc_mode or edt is None: |
| 361 | return "0" |
| 362 | |
| 363 | try: |
| 364 | node = edt.get_node(path) |
| 365 | except edtlib.EDTError: |
| 366 | return "0" |
| 367 | |
| 368 | if name == "dt_node_int_prop_int": |
| 369 | return str(_node_int_prop(node, prop)) |
| 370 | if name == "dt_node_int_prop_hex": |
| 371 | return hex(_node_int_prop(node, prop)) |
| 372 | |
| 373 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 374 | def dt_compat_enabled(kconf, _, compat): |
| 375 | """ |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 376 | This function takes a 'compat' and returns "y" if we find a status "okay" |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 377 | compatible node in the EDT otherwise we return "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 378 | """ |
| 379 | if doc_mode or edt is None: |
| 380 | return "n" |
| 381 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 382 | return "y" if compat in edt.compat2okay else "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 383 | |
| 384 | |
Martí Bolívar | 3cd4f6c | 2020-04-10 15:37:58 -0700 | [diff] [blame] | 385 | def dt_compat_on_bus(kconf, _, compat, bus): |
| 386 | """ |
| 387 | This function takes a 'compat' and returns "y" if we find an "enabled" |
| 388 | compatible node in the EDT which is on bus 'bus'. It returns "n" otherwise. |
| 389 | """ |
| 390 | if doc_mode or edt is None: |
| 391 | return "n" |
| 392 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 393 | for node in edt.compat2okay[compat]: |
Martí Bolívar | 3cd4f6c | 2020-04-10 15:37:58 -0700 | [diff] [blame] | 394 | if node.on_bus is not None and node.on_bus == bus: |
| 395 | return "y" |
| 396 | |
| 397 | return "n" |
| 398 | |
| 399 | |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 400 | def dt_nodelabel_has_compat(kconf, _, label, compat): |
| 401 | """ |
| 402 | This function takes a 'label' and returns "y" if an "enabled" node with |
| 403 | such label can be found in the EDT and that node is compatible with the |
| 404 | provided 'compat', otherwise it returns "n". |
| 405 | """ |
| 406 | if doc_mode or edt is None: |
| 407 | return "n" |
| 408 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 409 | for node in edt.compat2okay[compat]: |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 410 | if label in node.labels: |
| 411 | return "y" |
| 412 | |
| 413 | return "n" |
| 414 | |
| 415 | |
Martí Bolívar | 1fff235 | 2020-04-22 18:06:18 -0700 | [diff] [blame] | 416 | def dt_nodelabel_path(kconf, _, label): |
| 417 | """ |
| 418 | This function takes a node label (not a label property) and |
| 419 | returns the path to the node which has that label, or an empty |
| 420 | string if there is no such node. |
| 421 | """ |
| 422 | if doc_mode or edt is None: |
| 423 | return "" |
| 424 | |
| 425 | node = edt.label2node.get(label) |
| 426 | |
| 427 | return node.path if node else "" |
| 428 | |
| 429 | |
Erwan Gouriou | 17537c7 | 2019-11-22 10:06:57 +0100 | [diff] [blame] | 430 | def shields_list_contains(kconf, _, shield): |
| 431 | """ |
| 432 | Return "n" if cmake environment variable 'SHIELD_AS_LIST' doesn't exist. |
| 433 | Return "y" if 'shield' is present list obtained after 'SHIELD_AS_LIST' |
| 434 | has been split using ";" as a separator and "n" otherwise. |
| 435 | """ |
| 436 | try: |
| 437 | list = os.environ['SHIELD_AS_LIST'] |
| 438 | except KeyError: |
| 439 | return "n" |
| 440 | |
| 441 | return "y" if shield in list.split(";") else "n" |
| 442 | |
| 443 | |
Martí Bolívar | 006319f | 2020-07-21 15:20:18 -0700 | [diff] [blame] | 444 | # Keys in this dict are the function names as they appear |
| 445 | # in Kconfig files. The values are tuples in this form: |
| 446 | # |
| 447 | # (python_function, minimum_number_of_args, maximum_number_of_args) |
| 448 | # |
| 449 | # Each python function is given a kconf object and its name in the |
| 450 | # Kconfig file, followed by arguments from the Kconfig file. |
| 451 | # |
| 452 | # See the kconfiglib documentation for more details. |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 453 | functions = { |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 454 | "dt_compat_enabled": (dt_compat_enabled, 1, 1), |
Martí Bolívar | 3cd4f6c | 2020-04-10 15:37:58 -0700 | [diff] [blame] | 455 | "dt_compat_on_bus": (dt_compat_on_bus, 2, 2), |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 456 | "dt_chosen_label": (dt_chosen_label, 1, 1), |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame] | 457 | "dt_chosen_enabled": (dt_chosen_enabled, 1, 1), |
Martí Bolívar | 7ff3ebc | 2020-04-23 12:28:06 -0700 | [diff] [blame] | 458 | "dt_chosen_path": (dt_chosen_path, 1, 1), |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 459 | "dt_path_enabled": (dt_node_enabled, 1, 1), |
| 460 | "dt_alias_enabled": (dt_node_enabled, 1, 1), |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 461 | "dt_nodelabel_enabled": (dt_nodelabel_enabled, 1, 1), |
Ulf Magnusson | b4e1807 | 2019-12-23 11:07:27 +0100 | [diff] [blame] | 462 | "dt_chosen_reg_addr_int": (dt_chosen_reg, 1, 3), |
| 463 | "dt_chosen_reg_addr_hex": (dt_chosen_reg, 1, 3), |
| 464 | "dt_chosen_reg_size_int": (dt_chosen_reg, 1, 3), |
| 465 | "dt_chosen_reg_size_hex": (dt_chosen_reg, 1, 3), |
| 466 | "dt_node_reg_addr_int": (dt_node_reg, 1, 3), |
| 467 | "dt_node_reg_addr_hex": (dt_node_reg, 1, 3), |
| 468 | "dt_node_reg_size_int": (dt_node_reg, 1, 3), |
| 469 | "dt_node_reg_size_hex": (dt_node_reg, 1, 3), |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 470 | "dt_node_has_bool_prop": (dt_node_has_bool_prop, 2, 2), |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame^] | 471 | "dt_node_has_prop": (dt_node_has_prop, 2, 2), |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 472 | "dt_node_int_prop_int": (dt_node_int_prop, 2, 2), |
| 473 | "dt_node_int_prop_hex": (dt_node_int_prop, 2, 2), |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 474 | "dt_nodelabel_has_compat": (dt_nodelabel_has_compat, 2, 2), |
Martí Bolívar | 1fff235 | 2020-04-22 18:06:18 -0700 | [diff] [blame] | 475 | "dt_nodelabel_path": (dt_nodelabel_path, 1, 1), |
Erwan Gouriou | 17537c7 | 2019-11-22 10:06:57 +0100 | [diff] [blame] | 476 | "shields_list_contains": (shields_list_contains, 1, 1), |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 477 | } |