Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2018-2019 Linaro |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 3 | # Copyright (c) 2019 Nordic Semiconductor ASA |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | |
| 7 | import os |
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 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 20 | dt_defines = {} |
Ulf Magnusson | ba312fe | 2019-03-20 19:30:29 +0100 | [diff] [blame] | 21 | if not doc_mode: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 22 | DTS_POST_CPP = os.environ["DTS_POST_CPP"] |
Peter A. Bigot | 372a4fe | 2019-09-14 11:21:14 -0500 | [diff] [blame] | 23 | BINDINGS_DIRS = os.environ.get("DTS_ROOT_BINDINGS") |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 24 | |
| 25 | # if a board port doesn't use DTS than these might not be set |
Peter A. Bigot | 372a4fe | 2019-09-14 11:21:14 -0500 | [diff] [blame] | 26 | if os.path.isfile(DTS_POST_CPP) and BINDINGS_DIRS is not None: |
Sebastian Bøe | ba287d2 | 2019-09-26 17:45:47 +0200 | [diff] [blame] | 27 | edt = edtlib.EDT(DTS_POST_CPP, BINDINGS_DIRS.split("?")) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 28 | else: |
| 29 | edt = None |
| 30 | |
Carles Cufi | c2d5e7b | 2019-02-19 19:48:35 +0100 | [diff] [blame] | 31 | # The env var 'GENERATED_DTS_BOARD_CONF' must be set unless we are in |
| 32 | # doc mode |
| 33 | GENERATED_DTS_BOARD_CONF = os.environ['GENERATED_DTS_BOARD_CONF'] |
| 34 | if os.path.isfile(GENERATED_DTS_BOARD_CONF): |
| 35 | with open(GENERATED_DTS_BOARD_CONF, 'r', encoding='utf-8') as fd: |
| 36 | for line in fd: |
| 37 | if '=' in line: |
Ulf Magnusson | 86b0c22 | 2019-04-08 14:13:39 +0200 | [diff] [blame] | 38 | define, val = line.split('=', 1) |
Carles Cufi | c2d5e7b | 2019-02-19 19:48:35 +0100 | [diff] [blame] | 39 | dt_defines[define] = val.strip() |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 40 | |
Kumar Gala | 1baf2f3 | 2019-09-04 14:14:26 -0500 | [diff] [blame] | 41 | |
| 42 | def _warn(kconf, msg): |
| 43 | print("{}:{}: WARNING: {}".format(kconf.filename, kconf.linenr, msg)) |
| 44 | |
| 45 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 46 | def _dt_units_to_scale(unit): |
| 47 | if not unit: |
| 48 | return 0 |
| 49 | if unit in {'k', 'K'}: |
| 50 | return 10 |
| 51 | if unit in {'m', 'M'}: |
| 52 | return 20 |
| 53 | if unit in {'g', 'G'}: |
| 54 | return 30 |
| 55 | |
| 56 | def dt_int_val(kconf, _, name, unit=None): |
| 57 | """ |
| 58 | This function looks up 'name' in the DTS generated "conf" style database |
Erwan Gouriou | 7fce83f | 2019-02-12 09:44:14 +0100 | [diff] [blame] | 59 | (generated_dts_board.conf in <build_dir>/zephyr/include/generated/) |
David B. Kinder | 1cc8bbb | 2019-02-08 13:20:21 -0800 | [diff] [blame] | 60 | and if it's found it will return the value as an decimal integer. The |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 61 | function will divide the value based on 'unit': |
| 62 | None No division |
| 63 | 'k' or 'K' divide by 1024 (1 << 10) |
| 64 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 65 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 66 | """ |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 67 | if doc_mode or name not in dt_defines: |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 68 | return "0" |
| 69 | |
Kumar Gala | 1baf2f3 | 2019-09-04 14:14:26 -0500 | [diff] [blame] | 70 | _warn(kconf, "dt_int_val is deprecated.") |
| 71 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 72 | d = dt_defines[name] |
| 73 | if d.startswith(('0x', '0X')): |
| 74 | d = int(d, 16) |
| 75 | else: |
| 76 | d = int(d) |
| 77 | d >>= _dt_units_to_scale(unit) |
| 78 | |
| 79 | return str(d) |
| 80 | |
| 81 | def dt_hex_val(kconf, _, name, unit=None): |
| 82 | """ |
| 83 | This function looks up 'name' in the DTS generated "conf" style database |
Erwan Gouriou | 7fce83f | 2019-02-12 09:44:14 +0100 | [diff] [blame] | 84 | (generated_dts_board.conf in <build_dir>/zephyr/include/generated/) |
David B. Kinder | 1cc8bbb | 2019-02-08 13:20:21 -0800 | [diff] [blame] | 85 | and if it's found it will return the value as an hex integer. The |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 86 | function will divide the value based on 'unit': |
| 87 | None No division |
| 88 | 'k' or 'K' divide by 1024 (1 << 10) |
| 89 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 90 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 91 | """ |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 92 | if doc_mode or name not in dt_defines: |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 93 | return "0x0" |
| 94 | |
Kumar Gala | 1baf2f3 | 2019-09-04 14:14:26 -0500 | [diff] [blame] | 95 | _warn(kconf, "dt_hex_val is deprecated.") |
| 96 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 97 | d = dt_defines[name] |
| 98 | if d.startswith(('0x', '0X')): |
| 99 | d = int(d, 16) |
| 100 | else: |
| 101 | d = int(d) |
| 102 | d >>= _dt_units_to_scale(unit) |
| 103 | |
| 104 | return hex(d) |
| 105 | |
Kumar Gala | 2579ade | 2019-02-08 08:25:21 -0600 | [diff] [blame] | 106 | def dt_str_val(kconf, _, name): |
| 107 | """ |
| 108 | This function looks up 'name' in the DTS generated "conf" style database |
Erwan Gouriou | 7fce83f | 2019-02-12 09:44:14 +0100 | [diff] [blame] | 109 | (generated_dts_board.conf in <build_dir>/zephyr/include/generated/) |
David B. Kinder | 1cc8bbb | 2019-02-08 13:20:21 -0800 | [diff] [blame] | 110 | and if it's found it will return the value as string. If it's not found we |
Kumar Gala | f2ef52f | 2019-02-08 10:59:49 -0600 | [diff] [blame] | 111 | return an empty string. |
Kumar Gala | 2579ade | 2019-02-08 08:25:21 -0600 | [diff] [blame] | 112 | """ |
| 113 | if doc_mode or name not in dt_defines: |
| 114 | return "" |
| 115 | |
Kumar Gala | 1baf2f3 | 2019-09-04 14:14:26 -0500 | [diff] [blame] | 116 | _warn(kconf, "dt_str_val is deprecated.") |
| 117 | |
Kumar Gala | f2ef52f | 2019-02-08 10:59:49 -0600 | [diff] [blame] | 118 | return dt_defines[name].strip('"') |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 119 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 120 | |
| 121 | def dt_chosen_label(kconf, _, chosen): |
| 122 | """ |
| 123 | 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] | 124 | to an EDT node. If it finds an EDT node, it will look to see if that node |
| 125 | has a "label" property and return the value of that "label", if not we |
| 126 | return an empty string. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 127 | """ |
| 128 | if doc_mode or edt is None: |
| 129 | return "" |
| 130 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 131 | node = edt.chosen_node(chosen) |
| 132 | if not node: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 133 | return "" |
| 134 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 135 | if "label" not in node.props: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 136 | return "" |
| 137 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 138 | return node.props["label"].val |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 139 | |
| 140 | |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame^] | 141 | def dt_chosen_enabled(kconf, _, chosen): |
| 142 | """ |
| 143 | This function returns "y" if /chosen contains a property named 'chosen' |
| 144 | that points to an enabled node, and "n" otherwise |
| 145 | """ |
| 146 | if doc_mode or edt is None: |
| 147 | return "n" |
| 148 | |
| 149 | node = edt.chosen_node(chosen) |
| 150 | return "y" if node and node.enabled else "n" |
| 151 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 152 | def _node_reg_addr(node, index, unit): |
| 153 | if not node: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 154 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 155 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 156 | if not node.regs: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 157 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 158 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 159 | if int(index) >= len(node.regs): |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 160 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 161 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 162 | return node.regs[int(index)].addr >> _dt_units_to_scale(unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 163 | |
| 164 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 165 | def _node_reg_size(node, index, unit): |
| 166 | if not node: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 167 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 168 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 169 | if not node.regs: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 170 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 171 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 172 | if int(index) >= len(node.regs): |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 173 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 174 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 175 | return node.regs[int(index)].size >> _dt_units_to_scale(unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 176 | |
| 177 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 178 | def _dt_chosen_reg_addr(kconf, chosen, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 179 | """ |
| 180 | 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] | 181 | to an EDT node. If it finds an EDT node, it will look to see if that |
| 182 | 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] | 183 | that reg, if not we return 0. |
| 184 | |
| 185 | The function will divide the value based on 'unit': |
| 186 | None No division |
| 187 | 'k' or 'K' divide by 1024 (1 << 10) |
| 188 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 189 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 190 | """ |
| 191 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 192 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 193 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 194 | node = edt.chosen_node(chosen) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 195 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 196 | return _node_reg_addr(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 197 | |
| 198 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 199 | def _dt_chosen_reg_size(kconf, chosen, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 200 | """ |
| 201 | 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] | 202 | to an EDT node. If it finds an EDT node, it will look to see if that node |
| 203 | has a register at the given 'index' and return the size value of that reg, |
| 204 | if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 205 | |
| 206 | The function will divide the value based on 'unit': |
| 207 | None No division |
| 208 | 'k' or 'K' divide by 1024 (1 << 10) |
| 209 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 210 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 211 | """ |
| 212 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 213 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 214 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 215 | node = edt.chosen_node(chosen) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 216 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 217 | return _node_reg_size(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 218 | |
| 219 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 220 | def dt_chosen_reg(kconf, name, chosen, index=0, unit=None): |
| 221 | """ |
| 222 | This function just routes to the proper function and converts |
| 223 | the result to either a string int or string hex value. |
| 224 | """ |
| 225 | if name == "dt_chosen_reg_size_int": |
| 226 | return str(_dt_chosen_reg_size(kconf, chosen, index, unit)) |
| 227 | if name == "dt_chosen_reg_size_hex": |
| 228 | return hex(_dt_chosen_reg_size(kconf, chosen, index, unit)) |
| 229 | if name == "dt_chosen_reg_addr_int": |
| 230 | return str(_dt_chosen_reg_addr(kconf, chosen, index, unit)) |
| 231 | if name == "dt_chosen_reg_addr_hex": |
| 232 | return hex(_dt_chosen_reg_addr(kconf, chosen, index, unit)) |
| 233 | |
| 234 | |
| 235 | def _dt_node_reg_addr(kconf, path, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 236 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 237 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 238 | finds an EDT node, it will look to see if that node has a register at the |
| 239 | 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] | 240 | |
| 241 | The function will divide the value based on 'unit': |
| 242 | None No division |
| 243 | 'k' or 'K' divide by 1024 (1 << 10) |
| 244 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 245 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 246 | """ |
| 247 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 248 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 249 | |
| 250 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 251 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 252 | except edtlib.EDTError: |
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 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 255 | return _node_reg_addr(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 256 | |
| 257 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 258 | def _dt_node_reg_size(kconf, path, index=0, unit=None): |
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 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 261 | finds an EDT node, it will look to see if that node has a register at the |
| 262 | 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] | 263 | |
| 264 | The function will divide the value based on 'unit': |
| 265 | None No division |
| 266 | 'k' or 'K' divide by 1024 (1 << 10) |
| 267 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 268 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 269 | """ |
| 270 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 271 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 272 | |
| 273 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 274 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 275 | except edtlib.EDTError: |
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 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 278 | return _node_reg_size(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 279 | |
| 280 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 281 | def dt_node_reg(kconf, name, path, index=0, unit=None): |
| 282 | """ |
| 283 | This function just routes to the proper function and converts |
| 284 | the result to either a string int or string hex value. |
| 285 | """ |
| 286 | if name == "dt_node_reg_size_int": |
| 287 | return str(_dt_node_reg_size(kconf, path, index, unit)) |
| 288 | if name == "dt_node_reg_size_hex": |
| 289 | return hex(_dt_node_reg_size(kconf, path, index, unit)) |
| 290 | if name == "dt_node_reg_addr_int": |
| 291 | return str(_dt_node_reg_addr(kconf, path, index, unit)) |
| 292 | if name == "dt_node_reg_addr_hex": |
| 293 | return hex(_dt_node_reg_addr(kconf, path, index, unit)) |
| 294 | |
| 295 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 296 | def dt_node_has_bool_prop(kconf, _, path, prop): |
| 297 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 298 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 299 | finds an EDT node, it will look to see if that node has a boolean property |
| 300 | by the name of 'prop'. If the 'prop' exists it will return "y" otherwise |
| 301 | we return "n". |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 302 | """ |
| 303 | if doc_mode or edt is None: |
| 304 | return "n" |
| 305 | |
| 306 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 307 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 308 | except edtlib.EDTError: |
| 309 | return "n" |
| 310 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 311 | if prop not in node.props: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 312 | return "n" |
| 313 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 314 | if node.props[prop].type != "boolean": |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 315 | return "n" |
| 316 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 317 | if node.props[prop].val: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 318 | return "y" |
| 319 | |
| 320 | return "n" |
| 321 | |
| 322 | |
| 323 | def dt_compat_enabled(kconf, _, compat): |
| 324 | """ |
| 325 | This function takes a 'compat' and returns "y" if we find an "enabled" |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 326 | compatible node in the EDT otherwise we return "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 327 | """ |
| 328 | if doc_mode or edt is None: |
| 329 | return "n" |
| 330 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 331 | for node in edt.nodes: |
| 332 | if compat in node.compats and node.enabled: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 333 | return "y" |
| 334 | |
| 335 | return "n" |
| 336 | |
| 337 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 338 | functions = { |
| 339 | "dt_int_val": (dt_int_val, 1, 2), |
| 340 | "dt_hex_val": (dt_hex_val, 1, 2), |
Kumar Gala | 2579ade | 2019-02-08 08:25:21 -0600 | [diff] [blame] | 341 | "dt_str_val": (dt_str_val, 1, 1), |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 342 | "dt_compat_enabled": (dt_compat_enabled, 1, 1), |
| 343 | "dt_chosen_label": (dt_chosen_label, 1, 1), |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame^] | 344 | "dt_chosen_enabled": (dt_chosen_enabled, 1, 1), |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 345 | "dt_chosen_reg_addr_int": (dt_chosen_reg, 1, 4), |
| 346 | "dt_chosen_reg_addr_hex": (dt_chosen_reg, 1, 4), |
| 347 | "dt_chosen_reg_size_int": (dt_chosen_reg, 1, 4), |
| 348 | "dt_chosen_reg_size_hex": (dt_chosen_reg, 1, 4), |
| 349 | "dt_node_reg_addr_int": (dt_node_reg, 1, 4), |
| 350 | "dt_node_reg_addr_hex": (dt_node_reg, 1, 4), |
| 351 | "dt_node_reg_size_int": (dt_node_reg, 1, 4), |
| 352 | "dt_node_reg_size_hex": (dt_node_reg, 1, 4), |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 353 | "dt_node_has_bool_prop": (dt_node_has_bool_prop, 2, 2), |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 354 | } |