improve OF_PLATDATA support
Subsystems (7)
cover improve OF_PLATDATA support
When using OF_PLATDATA dtbs are converted to C structs in order to save space as we can remove both dtbs and libraries from TPL/SPL binaries.
This patchset tries to improve its support by overcoming some limitations in the current implementation
First, the support for scan and check for valid driver/aliases is added in order to generate U_BOOT_DEVICE entries with valid driver names.
Secondly, the way information about linked noded (phandle) is generated in C structs is improved in order to make it easier to get a device associated to its data.
Lastly the the suport for the property cd-gpios is added, which is used to configure the card detection gpio on MMC is added.
This implementation is based in discussion in [1], [2] and [3]
[1] https://patchwork.ozlabs.org/patch/1249198/
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=167495&state=*
[3] https://patchwork.ozlabs.org/project/uboot/list/?series=176759&state=*
Walter Lozano (10):
dtoc: add support to scan drivers
dtoc: add option to disable warnings
dm: doc: update of-plat with the suppor for driver aliases
core: drop const for struct driver_info
core: extend struct driver_info to point to device
dtoc: extend dtoc to use struct driver_info when linking nodes
dm: doc: update of-plat with new phandle support
dtoc: update tests to match new platdata
dtoc: update dtb_platdata to support cd-gpios
dtoc add test for cd-gpios
doc/driver-model/of-plat.rst | 38 +++- drivers/clk/clk-uclass.c | 11 +- drivers/core/device.c | 28 ++- drivers/core/root.c | 6 +- drivers/misc/irq-uclass.c | 10 +- drivers/mmc/ftsdc010_mci.c | 2 +- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mmc/rockchip_sdhci.c | 2 +- drivers/ram/rockchip/sdram_rk3399.c | 2 +- drivers/spi/rk_spi.c | 2 +- include/clk.h | 4 +- include/dm/device-internal.h | 2 +- include/dm/device.h | 21 +++ include/dm/platdata.h | 14 ++ tools/dtoc/dtb_platdata.py | 129 +++++++++++-- tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 +++++ tools/dtoc/test_dtoc.py | 218 +++++++++++++++------- 17 files changed, 415 insertions(+), 118 deletions(-) create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts
Signature · 1 line
2.20.1
PATCH 1/10 dtoc: add support to scan drivers
Currently dtoc scans dtbs to convert them to struct platdata and to generate U_BOOT_DEVICE entries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.
In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an U_BOOT_DEVICE entry will try to use a name not valid.
Additionally, in order to add more flexibility to the solution, adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry.
--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)
include/dm/device.h +7 -0
@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device *
tools/dtoc/dtb_platdata.py +79 -4
137 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 1/10 dtoc: add support to scan drivers
Hi Walter,
Quoted 57 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sys from dtoc import fdt
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 4 lines
tools/dtoc/dtb_platdata.py +1
-0@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible strings
key: The driver name, i.e. the part between brackets in U_BOOT_DRIVER(xx) ??
value: ...
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver names
key:
vaue:
Quoted 5 lines
tools/dtoc/dtb_platdata.py +0
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 10 lines
tools/dtoc/dtb_platdata.py +8
-0self._lines = [] self._aliases = {} + self._drivers = [] + self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _drivers
performing
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.
s/ rising/, printing/
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)
Can you update this comment to explain what is returned when it is not found?
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))
This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Also the warning is not really actionable. It needs to add mention of U_BOOT_DEVICE and ...ALIAS.
In future we can scan the compatible strings and tell the user what changes to make, I suppose.
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 182
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ compat_c = compat_c_old + else: # pragma: no cover
Need to fix the coverage here
Quoted 10 lines
tools/dtoc/dtb_platdata.py +3
-0+ aliases_c = [compat_c_old] + aliases_c + + return compat_c, aliases_c def setup_output(self, fname): """Set up the output destination@@ -243,6 +277,46 @@ class DtbPlatdata(object): return PhandleInfo(max_args, args) return None
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 289
Quoted 10 lines
tools/dtoc/dtb_platdata.py +10
-0+ def scan_driver(self, fn): + """Scan a driver file to build a list of driver names and aliases + + This procedure will populate self._drivers and self._driver_aliases + + Args + fn: Driver filename to scan + """ + with open(fn) as fd: +
drop blank line
Quoted 15 lines
tools/dtoc/dtb_platdata.py +15
-0+ buff = fd.read() + + # The following re will search for driver names declared as + # U_BOOT_DRIVER(driver_name) + drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff) + + for driver in drivers: + self._drivers.append(driver) + + # The following re will search for driver aliases declared as + # U_BOOT_DRIVER_ALIAS(alias, driver_name) + driver_aliases = re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', buff) + + for alias in driver_aliases: # pragma: no cover + if len(alias) != 2:
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 314
Quoted 10 lines
tools/dtoc/dtb_platdata.py +10
-0+ continue + self._driver_aliases[alias[1]] = alias[0] + + def scan_drivers(self): + """Scan the driver folders to build a list of driver names and aliases + + This procedure will populate self._drivers and self._driver_aliases + + """ + for (dirpath, dirnames, filenames) in os.walk('./'):
This doesn't work for out-of-tree cases (make O=xxx). You may need to pass $(srctree) to dtc as an argument.
Quoted 52 lines
tools/dtoc/dtb_platdata.py +10
-5+ for fn in filenames: + if not fn.endswith('.c'): + continue + self.scan_driver(dirpath + '/' + fn) + def scan_dtb(self): """Scan the device tree to obtain a tree of nodes and properties@@ -353,7 +427,7 @@ class DtbPlatdata(object): """ structs = {} for node in self._valid_nodes: - node_name, _ = get_compat_name(node) + node_name, _ = self.get_normalized_compat_name(node) fields = {} # Get a list of all the valid properties in this node.@@ -377,14 +451,14 @@ class DtbPlatdata(object): upto = 0 for node in self._valid_nodes: - node_name, _ = get_compat_name(node) + node_name, _ = self.get_normalized_compat_name(node) struct = structs[node_name] for name, prop in node.props.items(): if name not in PROP_IGNORE_LIST and name[0] != '#': prop.Widen(struct[name]) upto += 1 - struct_name, aliases = get_compat_name(node) + struct_name, aliases = self.get_normalized_compat_name(node) for alias in aliases: self._aliases[alias] = struct_name@@ -461,7 +535,7 @@ class DtbPlatdata(object): Args: node: node to output """ - struct_name, _ = get_compat_name(node) + struct_name, _ = self.get_normalized_compat_name(node) var_name = conv_name_to_c(node.name) self.buf('static const struct %s%s %s%s = {\n' % (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))@@ -562,6 +636,7 @@ def run_steps(args, dtb_file, include_disabled, output): raise ValueError('Please specify a command: struct, platdata') plat = DtbPlatdata(dtb_file, include_disabled) + plat.scan_drivers() plat.scan_dtb() plat.scan_tree() plat.scan_reg_sizes() --
Quoted 2 lines
2.20.1
Regards,
Simon
PATCH 1/10 dtoc: add support to scan drivers
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sys
Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...
Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:
OK.
Quoted 17 lines
Quoted 6 lines
tools/dtoc/dtb_platdata.py +0
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = Nonetools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 10 lines
tools/dtoc/dtb_platdata.py +8
-0self._lines = [] self._aliases = {} + self._drivers = [] + self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 3 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 2 lines
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 9 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Regarding this, maybe we should have a list of driver names we don't expect to support, like simple_bus. For this to work probably the best approach is to have a config option similar to CONFIG_OF_REMOVE_PROPS, so each config can add their owns.
Quoted 2 lines
Also the warning is not really actionable. It needs to add mention of
U_BOOT_DEVICEand ...ALIAS.
I agree with you. Thanks.
Quoted 3 lines
In future we can scan the compatible strings and tell the user what changes to make, I suppose.
Yes, it will be a great improvement!
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 182
Quoted 3 lines
tools/dtoc/dtb_platdata.py +2
-0+ compat_c = compat_c_old + else: # pragma: no coverNeed to fix the coverage here
Noted. I will a few more tests.
Quoted 11 lines
Quoted 11 lines
tools/dtoc/dtb_platdata.py +3
-0+ aliases_c = [compat_c_old] + aliases_c + + return compat_c, aliases_c def setup_output(self, fname): """Set up the output destination@@ -243,6 +277,46 @@ class DtbPlatdata(object): return PhandleInfo(max_args, args) return None
Quoted 11 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 289
Quoted 10 lines
tools/dtoc/dtb_platdata.py +10
-0+ def scan_driver(self, fn): + """Scan a driver file to build a list of driver names and aliases + + This procedure will populate self._drivers and self._driver_aliases + + Args + fn: Driver filename to scan + """ + with open(fn) as fd: +drop blank line
OK.
Quoted 19 lines
Quoted 19 lines
tools/dtoc/dtb_platdata.py +19
-0+ buff = fd.read() + + # The following re will search for driver names declared as + # U_BOOT_DRIVER(driver_name) + drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff) + + for driver in drivers: + self._drivers.append(driver) + + # The following re will search for driver aliases declared as + # U_BOOT_DRIVER_ALIAS(alias, driver_name) + driver_aliases = re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', buff) + + for alias in driver_aliases: # pragma: no cover + if len(alias) != 2: + continue + self._driver_aliases[alias[1]] = alias[0] + + def scan_drivers(self):
Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 314
Quoted 6 lines
tools/dtoc/dtb_platdata.py +6
-0+ """Scan the driver folders to build a list of driver names and aliases + + This procedure will populate self._drivers and self._driver_aliases + + """ + for (dirpath, dirnames, filenames) in os.walk('./'):This doesn't work for out-of-tree cases (make O=xxx). You may need to pass $(srctree) to dtc as an argument.
Thanks for pointing at this.
Quoted 46 lines
Quoted 46 lines
tools/dtoc/dtb_platdata.py +9
-4+ for fn in filenames: + if not fn.endswith('.c'): + continue + self.scan_driver(dirpath + '/' + fn) + def scan_dtb(self): """Scan the device tree to obtain a tree of nodes and properties@@ -353,7 +427,7 @@ class DtbPlatdata(object): """ structs = {} for node in self._valid_nodes: - node_name, _ = get_compat_name(node) + node_name, _ = self.get_normalized_compat_name(node) fields = {} # Get a list of all the valid properties in this node.@@ -377,14 +451,14 @@ class DtbPlatdata(object): upto = 0 for node in self._valid_nodes: - node_name, _ = get_compat_name(node) + node_name, _ = self.get_normalized_compat_name(node) struct = structs[node_name] for name, prop in node.props.items(): if name not in PROP_IGNORE_LIST and name[0] != '#': prop.Widen(struct[name]) upto += 1 - struct_name, aliases = get_compat_name(node) + struct_name, aliases = self.get_normalized_compat_name(node) for alias in aliases: self._aliases[alias] = struct_name@@ -461,7 +535,7 @@ class DtbPlatdata(object): Args: node: node to output """ - struct_name, _ = get_compat_name(node) + struct_name, _ = self.get_normalized_compat_name(node) var_name = conv_name_to_c(node.name) self.buf('static const struct %s%s %s%s = {\n' % (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))@@ -562,6 +636,7 @@ def run_steps(args, dtb_file, include_disabled, output): raise ValueError('Please specify a command: struct, platdata')
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-1plat = DtbPlatdata(dtb_file, include_disabled) + plat.scan_drivers() plat.scan_dtb() plat.scan_tree() plat.scan_reg_sizes() --2.20.1
Thanks once again for your review
Regards,
Walter
PATCH 1/10 dtoc: add support to scan drivers
Hi Simon,
Quoted 135 lines · Walter Lozano
Hi Simon,
Quoted 63 lines · Simon Glass
Hi Walter,
Quoted 59 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver
names. This allows to rise a warning in the case that anU_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an
easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICE
entry.Signed-off-by Walter Lozano <[email protected]>---
?include/dm/device.h??????? |? 7 ++++
?tools/dtoc/dtb_platdata.py| 83
++++++++++++++++++++++++++++++++++++--
? 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver { ? #define DM_GET_DRIVER(__name) \ ???????? ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +? /**
?? *dev_get_platdata()- Get the platform data for a device ?? *tools/dtoc/dtb_platdata.py +0
-0@@ -13,6 +13,8 @@ static data.? import collections
? import copytools/dtoc/dtb_platdata.py +2
-0+import os +import re? import sys
Quoted 11 lines
Quoted 8 lines
? from dtoc import fdt
tools/dtoc/dtb_platdata.py +0
-0@@ -140,6 +142,9 @@ class DtbPlatdata(object):?????????
_include_disabled: true to include nodes marked status = "disabled"
?????????_outfile: The current output file (sys.stdout or a real file) ?????????_lines: Stashed list of output lines for outputting in the future
+???????_aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)? ??
value: ...Noted.
Quoted 4 lines
Quoted 2 lines
+???????
_drivers: List of valid driver names found indrivers/+???????_driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 11 lines
Quoted 11 lines
????? """
????? def__init__(self, dtb_fname, include_disabled):
????????? self._fdt = Nonetools/dtoc/dtb_platdata.py +0
-0@@ -149,6 +154,35 @@ class DtbPlatdata(object):????????? self._outfile = None
????????? self._lines = []
????????? self._aliases = {}
+??????? self._drivers = []
+??????? self._driver_aliases = {}
+Quoted 8 lines
Quoted 7 lines
+??? def
get_normalized_compat_name(self, node):
+??????? """Get a node's normalized compat name
+
+??????? Returns a valid driver name by retrieving node's first compatible
+??????? string as a C identifier and perfomrming a check against_driversperforming
Noted.
Quoted 4 lines
Quoted 3 lines
+??????? and a lookup in
driver_aliasesrising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 11 lines
Quoted 11 lines
+
+??????? Args:
+??????????? node: Node object to check
+??????? Return:
+??????????? Tuple:
+??????????????? Driver name associated with the first compatible string
+??????????????? List of C identifiers for all the other compatible strings
+??????????????????? (possibly empty)Quoted 2 lines
Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 11 lines
Quoted 8 lines
+??????? """
+???????compat_c,aliases_c=get_compat_name(node)+??????? ifcompat_cnot in self._drivers:
+???????????compat_c_old=compat_c
+???????????compat_c=self._driver_aliases.get(compat_c)+??????????? if notcompat_c:
+???????????????print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.
I've been thinking about this issue, I think it would be better to only print the warning if build is issue with
make V=1
What do you think?
Quoted 138 lines
Quoted 3 lines
Also the warning is not really actionable. It needs to add mention of
U_BOOT_DEVICEand ...ALIAS.I agree with you. Thanks.
Quoted 3 lines
In future we can scan the compatible strings and tell the user what changes to make, I suppose.
Yes, it will be a great improvement!
Quoted 4 lines
Quoted 3 lines
+???????????????
compat_c=compat_c_old
+??????????? else: # pragma: no coverNeed to fix the coverage here
Noted. I will a few more tests.
Quoted 11 lines
Quoted 11 lines
+???????????????
aliases_c= [compat_c_old] +aliases_c+
+??????? returncompat_c,aliases_c????? def
setup_output(self, fname):
????????? """Set up the output destinationtools/dtoc/dtb_platdata.py +0
-0@@ -243,6 +277,46 @@ class DtbPlatdata(object): ????????????? return PhandleInfo(max_args, args)????????? return None
Quoted 13 lines
tools/dtoc/dtb_platdata.py
Quoted 12 lines
+??? def
scan_driver(self, fn):
+??????? """Scan a driver file to build a list of driver names and aliases
+
+??????? This procedure will populate self._drivers and self._driver_aliasestools/dtoc/dtb_platdata.py +6
-0+ +??????? Args +??????????? fn: Driver filename to scan +??????? """ +??????? with open(fn) as fd: +drop blank line
OK.
Quoted 24 lines
Quoted 24 lines
+??????????? buff =
fd.read()
+
+??????????? # The following re will search for driver names declared as
+??????????? #U_BOOT_DRIVER(driver_name)
+??????????? drivers =re.findall('U_BOOT_DRIVER\((.*)\)', buff)tools/dtoc/dtb_platdata.py +5
-0+ +??????????? for driver in drivers: +??????????????? self._drivers.append(driver) + +??????????? # The following re will search for driver aliasesdeclared as
+??????????? #U_BOOT_DRIVER_ALIAS(alias, driver_name)+???????????driver_aliases=re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', buff)tools/dtoc/dtb_platdata.py +8
-0+ +??????????? for alias in driver_aliases: # pragma: no cover +??????????????? if len(alias) != 2: +??????????????????? continue +??????????????? self._driver_aliases[alias[1]] = alias[0] + +??? def scan_drivers(self): +??????? """Scan the driver folders to build a list of driver namesand aliases
Quoted 8 lines
Quoted 6 lines
+
+??????? This procedure will populate self._drivers and self._driver_aliases
+
+??????? """
+??????? for (dirpath, dirnames, filenames) inos.walk('./'):This doesn't work for out-of-tree cases (make O=xxx). You may need to pass $(srctree) to dtc as an argument.
Thanks for pointing at this.
Quoted 50 lines
Quoted 50 lines
+??????????? for fn in filenames:
+??????????????? if notfn.endswith('.c'):
+??????????????????? continue
+???????????????self.scan_driver(dirpath + '/' + fn)+
????? defscan_dtb(self):
????????? """Scan the device tree to obtain a tree of nodes and propertiestools/dtoc/dtb_platdata.py +0
-0@@ -353,7 +427,7 @@ class DtbPlatdata(object):????????? """
????????? structs = {}
????????? for node in self._valid_nodes:
-???????????node_name, _ =get_compat_name(node)+???????????node_name, _ =self.get_normalized_compat_name(node)????????????? fields = {}????????????? # Get a list of all the valid properties in this node.
tools/dtoc/dtb_platdata.py +0
-0@@ -377,14 +451,14 @@ class DtbPlatdata(object):????????? upto = 0
????????? for node in self._valid_nodes:
-???????????node_name, _ =get_compat_name(node)+???????????node_name, _ =self.get_normalized_compat_name(node)????????????? struct = structs[node_name]
????????????? for name, prop innode.props.items():
????????????????? if name not inPROP_IGNORE_LISTand name[0] != '#':
?????????????????????prop.Widen(struct[name])????????????? upto += 1-???????????
struct_name, aliases =get_compat_name(node)+???????????struct_name, aliases =self.get_normalized_compat_name(node)????????????? for alias in aliases:
????????????????? self._aliases[alias] =struct_nametools/dtoc/dtb_platdata.py +0
-0@@ -461,7 +535,7 @@ class DtbPlatdata(object):????????? Args:
????????????? node: node to output
????????? """
-???????struct_name, _ =get_compat_name(node)
+???????struct_name, _ =self.get_normalized_compat_name(node)?????????var_name=conv_name_to_c(node.name)
????????? self.buf('static const struct %s%s %s%s = {\n' % ?????????????????? (STRUCT_PREFIX,struct_name,VAL_PREFIX,var_name))tools/dtoc/dtb_platdata.py +0
-0@@ -562,6 +636,7 @@ def run_steps(args, dtb_file, include_disabled,output):
????????? raiseValueError('Please specify a command: struct, platdata')Quoted 8 lines
Quoted 8 lines
????? plat =
DtbPlatdata(dtb_file, include_disabled)+???plat.scan_drivers()
?????plat.scan_dtb()
?????plat.scan_tree()
?????plat.scan_reg_sizes()Signature · 1 line
2.20.1Thanks once again for your review
Regards,
Walter
PATCH 1/10 dtoc: add support to scan drivers
Hi Walter,
Quoted 40 lines · Walter Lozano
Hi Simon,
Quoted 36 lines · Walter Lozano
Hi Simon,
Quoted 33 lines · Simon Glass
Hi Walter,
Quoted 29 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver
names. This allows to rise a warning in the case that anU_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an
easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICE
entry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)
[..]
Quoted 18 lines
Quoted 13 lines
Quoted 11 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in thedriver list' % (
compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.
Quoted 6 lines
I've been thinking about this issue, I think it would be better to only print the warning if build is issue with
make V=1
What do you think?
Can we not fix the warnings?
Regards,
Simon
PATCH 1/10 dtoc: add support to scan drivers
In reply to Walter LozanoHi Walter,
Quoted 120 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 17 lines
Quoted 6 lines
tools/dtoc/dtb_platdata.py +0
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = Nonetools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 10 lines
tools/dtoc/dtb_platdata.py +8
-0self._lines = [] self._aliases = {} + self._drivers = [] + self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 3 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 2 lines
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 9 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.
Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
Regards,
Simon
PATCH 1/10 dtoc: add support to scan drivers
Hi Simon
Quoted 118 lines · Simon Glass
Hi Walter,
Quoted 115 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} + self._drivers = []Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 2 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 9 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 6 lines
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
I don't fully understand your idea. As I see, the warning should help to spot that you will be trying to create a U_BOOT_DEVICE without a proper driver name, which means that compatible string does not match a driver name. The most probably reason for this is that driver doesn't fully support of-platdata, or at least an U_BOOT_DRIVER_ALIAS is missing.
From my understanding by adding a another macro to indicate that a
driver cannot be used, or even better to add a macro which tells that a driver supports of-platdata, will give us a cleaner dt-struct, which will be nice, however my first sentence still makes sense.
Could you clarify?
Also I have mentioned
Quoted 8 lines
Quoted 6 lines
I've been thinking about this issue, I think it would be better to only print the warning if build is issue with
make V=1
What do you think?
Can we not fix the warnings?
So it is not clear to me which idea is better from your point if view.
Regards,
Walter
PATCH 1/10 dtoc: add support to scan drivers
Hi Walter,
Quoted 135 lines · Walter Lozano
Hi Simon
Quoted 118 lines · Simon Glass
Hi Walter,
Quoted 115 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} + self._drivers = []Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 2 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 9 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 6 lines
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
I don't fully understand your idea. As I see, the warning should help to spot that you will be trying to create a
U_BOOT_DEVICEwithout a proper driver name, which means that compatible string does not match a driver name. The most probably reason for this is that driver doesn't fully support of-platdata, or at least anU_BOOT_DRIVER_ALIASis missing.
Quoted 6 lines
From my understanding by adding a another macro to indicate that a
driver cannot be used, or even better to add a macro which tells that a driver supports of-platdata, will give us a cleaner dt-struct, which will be nice, however my first sentence still makes sense.Could you clarify?
I just mean that you should fix all the warnings, so that none are printed in the normal case. Then people can see the problems they create. Perhaps then it could even be an error rather than a warning?
Quoted 6 lines
Also I have mentioned
Quoted 3 lines
Quoted 3 lines
I've been thinking about this issue, I think it would be better to only print the warning if build is issue with
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
make V=1
What do you think?
Can we not fix the warnings?
So it is not clear to me which idea is better from your point if view.
I don't think V=1 helps. Then you suppress the warning for most people. If it isn't important, we shouldn't print it. But see above - hoping these warnings can be fixed by renaming drivers.
Regards,
Simon
PATCH 1/10 dtoc: add support to scan drivers
Hi Simon,
Quoted 140 lines · Simon Glass
Hi Walter,
Quoted 137 lines · Walter Lozano
Hi Simon
Quoted 117 lines · Simon Glass
Hi Walter,
Quoted 114 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} + self._drivers = []Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 2 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 9 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 6 lines
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
I don't fully understand your idea. As I see, the warning should help to spot that you will be trying to create a
U_BOOT_DEVICEwithout a proper driver name, which means that compatible string does not match a driver name. The most probably reason for this is that driver doesn't fully support of-platdata, or at least anU_BOOT_DRIVER_ALIASis missing.From my understanding by adding a another macro to indicate that a
driver cannot be used, or even better to add a macro which tells that a driver supports of-platdata, will give us a cleaner dt-struct, which will be nice, however my first sentence still makes sense.
Quoted 5 lines
Quoted 1 line
Could you clarify?
I just mean that you should fix all the warnings, so that none are printed in the normal case. Then people can see the problems they create. Perhaps then it could even be an error rather than a warning?
Thanks for taking the time to explain your point. Let me put an example in order to check if we agree.
Currently, using sandbox_spl_defconfig several warnings arise, for instance
WARNING: the driver sandbox_serial was not found in the driver list
the driver is driver/serial/sandbox.c
The reason for this warning is that in sandbox_serial is not declared neither as a driver nor as an alias. In this case, this device won't work with of-platdata as it could not be bound. Am I correct?
To disable the warning is to rename the driver or to add an alias as
U_BOOT_DRIVER_ALIAS(serial_sandbox, sandbox_serial)
Would you like me to add U_BOOT_DRIVER_ALIAS for these kind of cases?
However removing the warning without properly testing the driver with of-platdata might hide runtime issues, don't you think so?
Also, if you feel that this discussion will take time, I have no problem in moving the warning to a different patchset, to avoid delay your work. I totally open to your suggestions.
Quoted 5 lines
Quoted 5 lines
Also I have mentioned
Quoted 3 lines
Quoted 3 lines
I've been thinking about this issue, I think it would be better to only print the warning if build is issue with
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
make V=1
What do you think?
Can we not fix the warnings?
So it is not clear to me which idea is better from your point if view.
I don't think V=1 helps. Then you suppress the warning for most people. If it isn't important, we shouldn't print it. But see above - hoping these warnings can be fixed by renaming drivers.
Yes, I understand, thanks for clarifying?
Regards,
Walter
PATCH 1/10 dtoc: add support to scan drivers
Hi Walter,
Quoted 162 lines · Walter Lozano
Hi Simon,
Quoted 140 lines · Simon Glass
Hi Walter,
Quoted 137 lines · Walter Lozano
Hi Simon
Quoted 117 lines · Simon Glass
Hi Walter,
Quoted 114 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} + self._drivers = []Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 2 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 9 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 6 lines
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
I don't fully understand your idea. As I see, the warning should help to spot that you will be trying to create a
U_BOOT_DEVICEwithout a proper driver name, which means that compatible string does not match a driver name. The most probably reason for this is that driver doesn't fully support of-platdata, or at least anU_BOOT_DRIVER_ALIASis missing.From my understanding by adding a another macro to indicate that a
driver cannot be used, or even better to add a macro which tells that a driver supports of-platdata, will give us a cleaner dt-struct, which will be nice, however my first sentence still makes sense.Quoted 5 lines
Quoted 1 line
Could you clarify?
I just mean that you should fix all the warnings, so that none are printed in the normal case. Then people can see the problems they create. Perhaps then it could even be an error rather than a warning?
Thanks for taking the time to explain your point. Let me put an example in order to check if we agree.
Currently, using
sandbox_spl_defconfigseveral warnings arise, for instanceWARNING: the driver
sandbox_serialwas not found in the driver listthe driver is
driver/serial/sandbox.cThe reason for this warning is that in
sandbox_serialis not declared neither as a driver nor as an alias. In this case, this device won't work with of-platdata as it could not be bound. Am I correct?
Quoted 5 lines
To disable the warning is to rename the driver or to add an alias as
U_BOOT_DRIVER_ALIAS(serial_sandbox, sandbox_serial)Would you like me to add
U_BOOT_DRIVER_ALIASfor these kind of cases?
I think it would be better to rename the driver. The names are a bit arbitrary anyway at present.
Quoted 3 lines
However removing the warning without properly testing the driver with of-platdata might hide runtime issues, don't you think so?
Well you can only make it better, I suspect, since you are correcting the name.
Quoted 4 lines
Also, if you feel that this discussion will take time, I have no problem in moving the warning to a different patchset, to avoid delay your work. I totally open to your suggestions.
Sure I suppose we could start with what you have, with the warnings, and then submit a fixup afterwards.
Regards,
Simon
PATCH 1/10 dtoc: add support to scan drivers
Quoted 164 lines · Simon Glass
Hi Walter,
Quoted 161 lines · Walter Lozano
Hi Simon,
Quoted 140 lines · Simon Glass
Hi Walter,
Quoted 137 lines · Walter Lozano
Hi Simon
Quoted 117 lines · Simon Glass
Hi Walter,
Quoted 114 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} + self._drivers = []Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 2 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 9 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 6 lines
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
I don't fully understand your idea. As I see, the warning should help to spot that you will be trying to create a
U_BOOT_DEVICEwithout a proper driver name, which means that compatible string does not match a driver name. The most probably reason for this is that driver doesn't fully support of-platdata, or at least anU_BOOT_DRIVER_ALIASis missing.From my understanding by adding a another macro to indicate that a
driver cannot be used, or even better to add a macro which tells that a driver supports of-platdata, will give us a cleaner dt-struct, which will be nice, however my first sentence still makes sense.Quoted 5 lines
Quoted 1 line
Could you clarify?
I just mean that you should fix all the warnings, so that none are printed in the normal case. Then people can see the problems they create. Perhaps then it could even be an error rather than a warning?
Thanks for taking the time to explain your point. Let me put an example in order to check if we agree.
Currently, using
sandbox_spl_defconfigseveral warnings arise, for instanceWARNING: the driver
sandbox_serialwas not found in the driver listthe driver is
driver/serial/sandbox.cThe reason for this warning is that in
sandbox_serialis not declared neither as a driver nor as an alias. In this case, this device won't work with of-platdata as it could not be bound. Am I correct?
Quoted 8 lines
Quoted 5 lines
To disable the warning is to rename the driver or to add an alias as
U_BOOT_DRIVER_ALIAS(serial_sandbox, sandbox_serial)Would you like me to add
U_BOOT_DRIVER_ALIASfor these kind of cases?I think it would be better to rename the driver. The names are a bit arbitrary anyway at present.
Yes, I agree. Actually I rename some drivers for iMX6 for that reason. Let me share some examples in order to check if we agree
drivers/gpio/rk_gpio.c +2 -2
@@ -172,8 +172,8 @@ static const struct udevice_id rockchip_gpio_ids[] = { { } }; -U_BOOT_DRIVER (gpio_rockchip) = { - .name ="gpio_rockchip" , +U_BOOT_DRIVER (rockchip_gpio_bank) = { + .name ="rockchip_gpio_bank" , .id =UCLASS_GPIO , .of_match = rockchip_gpio_ids, .ops = &gpio_rockchip_ops,
drivers/gpio/sandbox.c +2 -2
@@ -243,8 +243,8 @@ static const struct udevice_id sandbox_gpio_ids[] = { { } }; -U_BOOT_DRIVER (gpio_sandbox) = { - .name ="gpio_sandbox" , +U_BOOT_DRIVER (sandbox_gpio) = { + .name ="sandbox_gpio" , .id =UCLASS_GPIO , .of_match = sandbox_gpio_ids, .ofdata_to_platdata = sandbox_gpio_ofdata_to_platdata,
drivers/pinctrl/rockchip/pinctrl-rk3288.c +1 -1
@@ -240,7 +240,7 @@ static const struct udevice_id rk3288_pinctrl_ids[] = { { } }; -U_BOOT_DRIVER (pinctrl_rk3288) = { +U_BOOT_DRIVER (rockchip_rk3288_pinctrl) = { .name ="rockchip_rk3288_pinctrl" , .id =UCLASS_PINCTRL , .of_match = rk3288_pinctrl_ids,
drivers/power/pmic/rk8xx.c +2 -2
@@ -182,8 +182,8 @@ static const struct udevice_id rk8xx_ids[] = { { } }; -U_BOOT_DRIVER (pmic_rk8xx) = { - .name ="rk8xx pmic" , +U_BOOT_DRIVER (rockchip_rk805) = { + .name ="rockchip_rk805" , .id =UCLASS_PMIC , .of_match = rk8xx_ids, #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
Quoted 9 lines
Quoted 2 lines
However removing the warning without properly testing the driver with of-platdata might hide runtime issues, don't you think so?
Well you can only make it better, I suspect, since you are correcting the name.
Quoted 3 lines
Also, if you feel that this discussion will take time, I have no problem in moving the warning to a different patchset, to avoid delay your work. I totally open to your suggestions.
Sure I suppose we could start with what you have, with the warnings, and then submit a fixup afterwards.
I have no problem, let's see if we can agree in this patchset in order to keep improving things.
Regards.
Walter
PATCH 1/10 dtoc: add support to scan drivers
Hi Walter,
Quoted 228 lines · Walter Lozano
Quoted 164 lines · Simon Glass
Hi Walter,
Quoted 161 lines · Walter Lozano
Hi Simon,
Quoted 140 lines · Simon Glass
Hi Walter,
Quoted 137 lines · Walter Lozano
Hi Simon
Quoted 117 lines · Simon Glass
Hi Walter,
Quoted 114 lines · Walter Lozano
Hi Simon,
Quoted 57 lines · Simon Glass
Hi Walter,
Quoted 54 lines · Walter Lozano
Currently dtoc scans dtbs to convert them to struct platdata and to generate
U_BOOT_DEVICEentries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an
U_BOOT_DEVICEentry will try to use a name not valid.Additionally, in order to add more flexibility to the solution, adds the
U_BOOT_DRIVER_ALIASmacro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates theU_BOOT_DEVICEentry.Signed-off-by Walter Lozano <[email protected]>--- include/dm/device.h | 7 ++++ tools/dtoc/dtb_platdata.py | 83 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 4 deletions(-)include/dm/device.h +7
-0@@ -282,6 +282,13 @@ struct driver {#define DM_GET_DRIVER (__name) \ ll_entry_get(struct driver, __name, driver) +/** +* Declare a macro to state a alias for a driver name. This macro will +* produce no code but its information will be parsed by tools like +* dtoc +*/ +#define U_BOOT_DRIVER_ALIAS (__name, __alias) +/** * dev_get_platdata() - Get the platform data for a device * tools/dtoc/dtb_platdata.py +2
-0@@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sysQuoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 145
Quoted 6 lines
tools/dtoc/dtb_platdata.py +1
-0from dtoc import fdt@@ -140,6 +142,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future + _aliases: Dict that hold aliases for compatible stringskey: The driver name, i.e. the part between brackets in
U_BOOT_DRIVER(xx)??
value: ...Noted.
Quoted 4 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 147
Quoted 2 lines
tools/dtoc/dtb_platdata.py +2
-0+ _drivers: List of valid driver names found in drivers/ + _driver_aliases: Dict that holds aliases for driver nameskey:
vaue:OK.
Quoted 8 lines
Quoted 8 lines
tools/dtoc/dtb_platdata.py +1
-0""" def __init__(self, dtb_fname, include_disabled): self._fdt = None@@ -149,6 +154,35 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} + self._drivers = []Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 164
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ self._driver_aliases = {} + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's first compatible + string as a C identifier and perfomrming a check against _driversperforming
Noted.
Quoted 2 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 165
Quoted 1 line
tools/dtoc/dtb_platdata.py +1
-0+ and a lookup in driver_aliases rising a warning in case of failure.s/ rising/, printing/
OK.
Quoted 9 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 173
Quoted 8 lines
tools/dtoc/dtb_platdata.py +8
-0+ + Args: + node: Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty)Can you update this comment to explain what is returned when it is not found?
Sure.
Quoted 10 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 180
Quoted 7 lines
tools/dtoc/dtb_platdata.py +7
-0+ """ + compat_c, aliases_c = get_compat_name(node) + if compat_c not in self._drivers: + compat_c_old = compat_c + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))This creates lots of warnings at present. Either we need a patch to clean up the differences in the source code, or we need to disable the warning.
Quoted 6 lines
Quoted 4 lines
Regarding this, maybe we should have a list of driver names we don't expect to support, like
simple_bus. For this to work probably the best approach is to have a config option similar toCONFIG_OF_REMOVE_PROPS, so each config can add their owns.Or perhaps have another macro in the source code that indicates that the driver cannot be used with of-platdata and should be ignored?
I don't fully understand your idea. As I see, the warning should help to spot that you will be trying to create a
U_BOOT_DEVICEwithout a proper driver name, which means that compatible string does not match a driver name. The most probably reason for this is that driver doesn't fully support of-platdata, or at least anU_BOOT_DRIVER_ALIASis missing.From my understanding by adding a another macro to indicate that a
driver cannot be used, or even better to add a macro which tells that a driver supports of-platdata, will give us a cleaner dt-struct, which will be nice, however my first sentence still makes sense.Quoted 5 lines
Quoted 1 line
Could you clarify?
I just mean that you should fix all the warnings, so that none are printed in the normal case. Then people can see the problems they create. Perhaps then it could even be an error rather than a warning?
Thanks for taking the time to explain your point. Let me put an example in order to check if we agree.
Currently, using
sandbox_spl_defconfigseveral warnings arise, for instanceWARNING: the driver
sandbox_serialwas not found in the driver listthe driver is
driver/serial/sandbox.cThe reason for this warning is that in
sandbox_serialis not declared neither as a driver nor as an alias. In this case, this device won't work with of-platdata as it could not be bound. Am I correct?Quoted 8 lines
Quoted 5 lines
To disable the warning is to rename the driver or to add an alias as
U_BOOT_DRIVER_ALIAS(serial_sandbox, sandbox_serial)Would you like me to add
U_BOOT_DRIVER_ALIASfor these kind of cases?I think it would be better to rename the driver. The names are a bit arbitrary anyway at present.
Yes, I agree. Actually I rename some drivers for iMX6 for that reason. Let me share some examples in order to check if we agree
drivers/gpio/rk_gpio.c +2
-2@@ -172,8 +172,8 @@ static const struct udevice_id rockchip_gpio_ids[] = { { } }; -U_BOOT_DRIVER (gpio_rockchip) = { - .name ="gpio_rockchip" , +U_BOOT_DRIVER (rockchip_gpio_bank) = { + .name ="rockchip_gpio_bank" , .id =UCLASS_GPIO , .of_match = rockchip_gpio_ids, .ops = &gpio_rockchip_ops,drivers/gpio/sandbox.c +2
-2@@ -243,8 +243,8 @@ static const struct udevice_id sandbox_gpio_ids[] = { { } }; -U_BOOT_DRIVER (gpio_sandbox) = { - .name ="gpio_sandbox" , +U_BOOT_DRIVER (sandbox_gpio) = { + .name ="sandbox_gpio" , .id =UCLASS_GPIO , .of_match = sandbox_gpio_ids, .ofdata_to_platdata = sandbox_gpio_ofdata_to_platdata,drivers/pinctrl/rockchip/pinctrl-rk3288.c +1
-1@@ -240,7 +240,7 @@ static const struct udevice_id rk3288_pinctrl_ids[] = { { } }; -U_BOOT_DRIVER (pinctrl_rk3288) = { +U_BOOT_DRIVER (rockchip_rk3288_pinctrl) = { .name ="rockchip_rk3288_pinctrl" , .id =UCLASS_PINCTRL , .of_match = rk3288_pinctrl_ids,drivers/power/pmic/rk8xx.c +0
-0
drivers/power/pmic/rk8xx.c static const struct udevice_id rk8xx_ids[] = { · line 189
Quoted 10 lines
drivers/power/pmic/rk8xx.c +2
-2@@ -182,8 +182,8 @@ static const struct udevice_id rk8xx_ids[] = { { } }; -U_BOOT_DRIVER (pmic_rk8xx) = { - .name ="rk8xx pmic" , +U_BOOT_DRIVER (rockchip_rk805) = { + .name ="rockchip_rk805" , .id =UCLASS_PMIC , .of_match = rk8xx_ids, #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
Yes that seems OK.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
However removing the warning without properly testing the driver with of-platdata might hide runtime issues, don't you think so?
Well you can only make it better, I suspect, since you are correcting the name.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Also, if you feel that this discussion will take time, I have no problem in moving the warning to a different patchset, to avoid delay your work. I totally open to your suggestions.
Sure I suppose we could start with what you have, with the warnings, and then submit a fixup afterwards.
I have no problem, let's see if we can agree in this patchset in order to keep improving things.
OK.
Regards,
Simon
PATCH 2/10 dtoc: add option to disable warnings
In reply to Walter LozanoAs dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names.
This patch adds an option to disable those warning, which is only intended for running tests.
--- tools/dtoc/dtb_platdata.py | 11 +++++--- tools/dtoc/test_dtoc.py | 54 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 31 deletions(-)
tools/dtoc/dtb_platdata.py +7 -4
@@ -141,17 +141,19 @@ class DtbPlatdata(object): _valid_nodes: A list of Node object with compatible strings _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) + _warning_disabled: true to disable warnings about driver names not found _lines: Stashed list of output lines for outputting in the future _aliases: Dict that hold aliases for compatible strings _drivers: List of valid driver names found in drivers/ _driver_aliases: Dict that holds aliases for driver names """ - def __init__(self, dtb_fname, include_disabled): + def __init__(self, dtb_fname, include_disabled, warning_disable): self._fdt = None self._dtb_fname = dtb_fname self._valid_nodes = None self._include_disabled = include_disabled self._outfile = None + self._warning_disable = warning_disable self._lines = [] self._aliases = {} self._drivers = []
@@ -177,7 +179,8 @@ class DtbPlatdata(object): compat_c_old = compat_c compat_c = self._driver_aliases.get(compat_c) if not compat_c: - print('WARNING: the driver %s was not found in the driver list' % (compat_c_old)) + if not self._warning_disable: # pragma: no cover + print('WARNING: the driver %s was not found in the driver list' % (compat_c_old)) compat_c = compat_c_old else: # pragma: no cover aliases_c = [compat_c_old] + aliases_c
@@ -623,7 +626,7 @@ class DtbPlatdata(object): nodes_to_output.remove(node) -def run_steps(args, dtb_file, include_disabled, output): +def run_steps(args, dtb_file, include_disabled, output, warning_disable = False): """Run all the steps of the dtoc tool Args:
@@ -635,7 +638,7 @@ def run_steps(args, dtb_file, include_disabled, output): if not args: raise ValueError('Please specify a command: struct, platdata') - plat = DtbPlatdata(dtb_file, include_disabled) + plat = DtbPlatdata(dtb_file, include_disabled, warning_disable) plat.scan_drivers() plat.scan_dtb() plat.scan_tree()
tools/dtoc/test_dtoc.py +27 -27
211 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 2/10 dtoc: add option to disable warnings
Hi Walter,
Quoted 40 lines · Walter Lozano
As dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names.
This patch adds an option to disable those warning, which is only intended for running tests.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/dtb_platdata.py | 11 +++++--- tools/dtoc/test_dtoc.py | 54 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 31 deletions(-)tools/dtoc/dtb_platdata.py +3
-1@@ -141,17 +141,19 @@ class DtbPlatdata(object): _valid_nodes: A list of Node object with compatible strings _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) + _warning_disabled: true to disable warnings about driver names not found _lines: Stashed list of output lines for outputting in the future _aliases: Dict that hold aliases for compatible strings _drivers: List of valid driver names found in drivers/ _driver_aliases: Dict that holds aliases for driver names """ - def __init__(self, dtb_fname, include_disabled): + def __init__(self, dtb_fname, include_disabled, warning_disable): self._fdt = None self._dtb_fname = dtb_fname self._valid_nodes = None self._include_disabled = include_disabled self._outfile = None + self._warning_disable = warning_disable self._lines = [] self._aliases = {} self._drivers = []
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 182
Quoted 5 lines
tools/dtoc/dtb_platdata.py +1
-1@@ -177,7 +179,8 @@ class DtbPlatdata(object): compat_c_old = compat_c compat_c = self._driver_aliases.get(compat_c) if not compat_c: - print('WARNING: the driver %s was not found in the driver list' % (compat_c_old)) + if not self._warning_disable: # pragma: no cover
Need coverage for this.
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 629
Quoted 10 lines
tools/dtoc/dtb_platdata.py +2
-1+ print('WARNING: the driver %s was not found in the driver list' % (compat_c_old)) compat_c = compat_c_old else: # pragma: no cover aliases_c = [compat_c_old] + aliases_c@@ -623,7 +626,7 @@ class DtbPlatdata(object): nodes_to_output.remove(node) -def run_steps(args, dtb_file, include_disabled, output): +def run_steps(args, dtb_file, include_disabled, output, warning_disable = False):
no spaces around =
Quoted 18 lines
tools/dtoc/dtb_platdata.py +1
-1"""Run all the steps of the dtoc tool Args:@@ -635,7 +638,7 @@ def run_steps(args, dtb_file, include_disabled, output): if not args: raise ValueError('Please specify a command: struct, platdata') - plat = DtbPlatdata(dtb_file, include_disabled) + plat = DtbPlatdata(dtb_file, include_disabled, warning_disable) plat.scan_drivers() plat.scan_dtb() plat.scan_tree()tools/dtoc/test_dtoc.py +0
-0@@ -154,12 +154,12 @@ class TestDtoc(unittest.TestCase): """Test output from a device tree file with no nodes"""
tools/dtoc/test_dtoc.py class TestDtoc(unittest.TestCase): · line 162
Quoted 10 lines
tools/dtoc/test_dtoc.py +2
-2dtb_file = get_dtb_file('dtoc_test_empty.dts') output = tools.GetOutputFilename('output') - dtb_platdata.run_steps(['struct'], dtb_file, False, output) + dtb_platdata.run_steps(['struct'], dtb_file, False, output, True) with open(output) as infile: lines = infile.read().splitlines() self.assertEqual(HEADER.splitlines(), lines) - dtb_platdata.run_steps(['platdata'], dtb_file, False, output) + dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True)
Can you create run_test which calls run_steps with that set that to True, to avoid adding the param everywhere in this file?
Regards,
Simon
PATCH 2/10 dtoc: add option to disable warnings
Hi Simon,
Quoted 40 lines · Simon Glass
Hi Walter,
Quoted 37 lines · Walter Lozano
As dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names.
This patch adds an option to disable those warning, which is only intended for running tests.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/dtb_platdata.py | 11 +++++--- tools/dtoc/test_dtoc.py | 54 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 31 deletions(-)tools/dtoc/dtb_platdata.py +3
-1@@ -141,17 +141,19 @@ class DtbPlatdata(object): _valid_nodes: A list of Node object with compatible strings _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) + _warning_disabled: true to disable warnings about driver names not found _lines: Stashed list of output lines for outputting in the future _aliases: Dict that hold aliases for compatible strings _drivers: List of valid driver names found in drivers/ _driver_aliases: Dict that holds aliases for driver names """ - def __init__(self, dtb_fname, include_disabled): + def __init__(self, dtb_fname, include_disabled, warning_disable): self._fdt = None self._dtb_fname = dtb_fname self._valid_nodes = None self._include_disabled = include_disabled self._outfile = None + self._warning_disable = warning_disable self._lines = [] self._aliases = {}
Quoted 8 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 182
Quoted 7 lines
tools/dtoc/dtb_platdata.py +1
-1self._drivers = []@@ -177,7 +179,8 @@ class DtbPlatdata(object): compat_c_old = compat_c compat_c = self._driver_aliases.get(compat_c) if not compat_c: - print('WARNING: the driver %s was not found in the driver list' % (compat_c_old)) + if not self._warning_disable: # pragma: no coverNeed coverage for this.
No problem!
Quoted 9 lines
Quoted 9 lines
tools/dtoc/dtb_platdata.py +1
-0+ print('WARNING: the driver %s was not found in the driver list' % (compat_c_old)) compat_c = compat_c_old else: # pragma: no cover aliases_c = [compat_c_old] + aliases_c@@ -623,7 +626,7 @@ class DtbPlatdata(object): nodes_to_output.remove(node)
Quoted 3 lines
tools/dtoc/dtb_platdata.py class DtbPlatdata(object): · line 629
Quoted 2 lines
tools/dtoc/dtb_platdata.py +1
-1-def run_steps(args, dtb_file, include_disabled, output): +def run_steps(args, dtb_file, include_disabled, output, warning_disable = False):no spaces around =
Sure.
Quoted 26 lines
Quoted 26 lines
tools/dtoc/dtb_platdata.py +1
-1"""Run all the steps of the dtoc tool Args:@@ -635,7 +638,7 @@ def run_steps(args, dtb_file, include_disabled, output): if not args: raise ValueError('Please specify a command: struct, platdata') - plat = DtbPlatdata(dtb_file, include_disabled) + plat = DtbPlatdata(dtb_file, include_disabled, warning_disable) plat.scan_drivers() plat.scan_dtb() plat.scan_tree()tools/dtoc/test_dtoc.py +1
-1@@ -154,12 +154,12 @@ class TestDtoc(unittest.TestCase): """Test output from a device tree file with no nodes""" dtb_file = get_dtb_file('dtoc_test_empty.dts') output = tools.GetOutputFilename('output') - dtb_platdata.run_steps(['struct'], dtb_file, False, output) + dtb_platdata.run_steps(['struct'], dtb_file, False, output, True) with open(output) as infile: lines = infile.read().splitlines() self.assertEqual(HEADER.splitlines(), lines)
Quoted 4 lines
tools/dtoc/test_dtoc.py class TestDtoc(unittest.TestCase): · line 162
Quoted 2 lines
tools/dtoc/test_dtoc.py +1
-1- dtb_platdata.run_steps(['platdata'], dtb_file, False, output) + dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True)Can you create
run_testwhich callsrun_stepswith that set that to True, to avoid adding the param everywhere in this file?
Sure, no problem. Thanks!
Regards,
Walter
PATCH 3/10 dm: doc: update of-plat with the suppor for driver aliases
In reply to Walter LozanoUpdate the documentation with the support for driver aliases using U_BOOT_DRIVER_ALIAS.
--- doc/driver-model/of-plat.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
doc/driver-model/of-plat.rst +13 -1
@@ -183,6 +183,17 @@ via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a it to a valid name for C) is needed, so a dedicated driver is required for each 'compatible' string. +In order to make this a bit more flexible U_BOOT_DRIVER_ALIAS macro can be +used to declare an alias for a driver name, typically a 'compatible' string. +This macro produces no code, but it is by dtoc tool. + +During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS +to build a list of valid driver names and driver aliases. If the 'compatible' +string used for a device does not not match a valid driver name, it will be +checked against the list of driver aliases in order to get the right driver +name to use. If in this step there is no match found a warning is issued to +avoid run-time failures. + Where a node has multiple compatible strings, a #define is used to make them equivalent, e.g.:
@@ -269,7 +280,7 @@ For example: }; U_BOOT_DRIVER(mmc_drv) = { - .name = "vendor_mmc", /* matches compatible string */ + .name = "mmc_drv", .id = UCLASS_MMC, .of_match = mmc_ids, .ofdata_to_platdata = mmc_ofdata_to_platdata,
@@ -278,6 +289,7 @@ For example: .platdata_auto_alloc_size = sizeof(struct mmc_platdata), }; + U_BOOT_DRIVER_ALIAS(vendor_mmc, mmc_drv) /* matches compatible string */ Note that struct mmc_platdata is defined in the C file, not in a header. This is to avoid needing to include dt-structs.h in a header file. The idea is to
Signature · 1 line
2.20.1
PATCH 3/10 dm: doc: update of-plat with the suppor for driver aliases
Quoted 9 lines · Walter Lozano
Update the documentation with the support for driver aliases using
U_BOOT_DRIVER_ALIAS.Signed-off-by Walter Lozano <[email protected]>--- doc/driver-model/of-plat.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
PATCH 4/10 core: drop const for struct driver_info
In reply to Walter LozanoIn order to prepare for a new support of phandle when OF_PLATDATA is used drop the const for struct driver_info as this struct will need to be updated on runtime.
--- drivers/core/device.c | 2 +- drivers/core/root.c | 2 +- include/dm/device-internal.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/core/device.c +1 -1
@@ -246,7 +246,7 @@ int device_bind_ofnode(struct udevice *parent, const struct driver *drv, }int device_bind_by_name (struct udevice *parent,bool pre_reloc_only, -const struct driver_info *info,struct udevice **devp) +struct driver_info *info,struct udevice **devp) {struct driver *drv;uint platdata_size =0 ;
drivers/core/root.c +1 -1
@@ -25,7 +25,7 @@DECLARE_GLOBAL_DATA_PTR ; -static const struct driver_info root_info = { +static struct driver_info root_info = { .name ="root_driver" , };
include/dm/device-internal.h +1 -1
@@ -81,7 +81,7 @@ int device_bind_with_driver_data(struct udevice *parent,* @return 0 if OK, -ve on error */ int device_bind_by_name (struct udevice *parent,bool pre_reloc_only, -const struct driver_info *info,struct udevice **devp); +struct driver_info *info,struct udevice **devp);/** * device_ofdata_to_platdata() - Read platform data for a device
Signature · 1 line
2.20.1
PATCH 4/10 core: drop const for struct driver_info
Quoted 11 lines · Walter Lozano
In order to prepare for a new support of phandle when
OF_PLATDATAis used drop the const for structdriver_infoas this struct will need to be updated on runtime.Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 2 +- drivers/core/root.c | 2 +- include/dm/device-internal.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
PATCH 5/10 core: extend struct driver_info to point to device
In reply to Walter LozanoCurrently when creating an U_BOOT_DEVICE entry a struct driver_info is declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its struct driver_info.
This patch extends struct driver_info adding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its struct driver_info.
--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)
drivers/core/device.c +23 -3
@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ; drv =lists_driver_lookup_name (info->name);if (!drv)
@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif -return device_bind_common (parent, drv, info->name, - (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif + +return ret; }static void *alloc_priv (int size,uint flags)
@@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); } +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp) +{ +struct udevice *dev; + + dev = info->dev; + +return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); +} +#endif +int device_find_first_child (const struct udevice *parent,struct udevice **devp) {if (list_empty (&parent->child_head)) {
drivers/core/root.c +4 -0
@@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only) {int ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +populate_phandle_data (); +#endif + ret =dm_init (IS_ENABLED (CONFIG_OF_LIVE ));if (ret) {debug ("dm_init() failed: %d\n" , ret);
include/dm/device.h +14 -0
@@ -538,6 +538,20 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp);*/ int device_get_global_by_ofnode (ofnode node,struct udevice **devp); +/** +* device_get_by_driver_info() - Get a device based on driver_info +* +* Locates a device by its struct driver_info. +* +* The device is probed to activate it ready for use. +* +* @info: Struct driver_info +* @devp: Returns pointer to device if found, otherwise this is set to NULL +* @return 0 if OK, -ve on error +*/ +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp); +/** * device_find_first_child() - Find the first child of a device *
include/dm/platdata.h +14 -0
@@ -22,12 +22,14 @@* @name: Driver name * @platdata: Driver-specific platform data * @platdata_size: Size of platform data structure +* @dev: Device created from this structure data */ struct driver_info {const char *name;const void *platdata;#if CONFIG_IS_ENABLED (OF_PLATDATA )uint platdata_size; +struct udevice *dev;#endif };
@@ -43,4 +45,16 @@ struct driver_info {#define U_BOOT_DEVICES (__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info) +/* Get a pointer to a given driver */ +#define DM_GET_DEVICE (__name) \ + ll_entry_get(struct driver_info, __name, driver_info) + +/** +* populate_phandle_data() - Populates phandle data in platda +* +* This populates phandle data with an U_BOOT_DEVICE entry get by +* DM_GET_DEVICE. The implementation of this function will be done +* by dtoc when parsing dtb. +*/ +void populate_phandle_data (void );#endif
Signature · 1 line
2.20.1
PATCH 5/10 core: extend struct driver_info to point to device
Quoted 34 lines · Walter Lozano
Currently when creating an
U_BOOT_DEVICEentry a structdriver_infois declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its structdriver_info.This patch extends struct
driver_infoadding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its structdriver_info.Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)drivers/core/device.c +1
-1@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ; drv =lists_driver_lookup_name (info->name);if (!drv)@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif - return device_bind_common(parent, drv, info->name,
drivers/core/device.c int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, · line 271
Quoted 10 lines
drivers/core/device.c +8
-2- (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif
I have tried to test this using sandbox_spl_defconfig but I've received a segmentation fault when trying to update info->dev, however this code works on iMX6.
Could it be some kind of protection? Any thoughts?
Quoted 100 lines
drivers/core/device.c +14
-0+ +return ret; }static void *alloc_priv (int size,uint flags)@@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); } +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp) +{ +struct udevice *dev; + + dev = info->dev; + +return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); +} +#endif +int device_find_first_child (const struct udevice *parent,struct udevice **devp) {if (list_empty (&parent->child_head)) {drivers/core/root.c +4
-0@@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only) {int ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +populate_phandle_data (); +#endif + ret =dm_init (IS_ENABLED (CONFIG_OF_LIVE ));if (ret) {debug ("dm_init() failed: %d\n" , ret);include/dm/device.h +14
-0@@ -538,6 +538,20 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp);*/ int device_get_global_by_ofnode (ofnode node,struct udevice **devp); +/** +* device_get_by_driver_info() - Get a device based on driver_info +* +* Locates a device by its struct driver_info. +* +* The device is probed to activate it ready for use. +* +* @info: Struct driver_info +* @devp: Returns pointer to device if found, otherwise this is set to NULL +* @return 0 if OK, -ve on error +*/ +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp); +/** * device_find_first_child() - Find the first child of a device * include/dm/platdata.h +14
-0@@ -22,12 +22,14 @@* @name: Driver name * @platdata: Driver-specific platform data * @platdata_size: Size of platform data structure +* @dev: Device created from this structure data */ struct driver_info {const char *name;const void *platdata;#if CONFIG_IS_ENABLED (OF_PLATDATA )uint platdata_size; +struct udevice *dev;#endif };@@ -43,4 +45,16 @@ struct driver_info {#define U_BOOT_DEVICES (__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info) +/* Get a pointer to a given driver */ +#define DM_GET_DEVICE (__name) \ + ll_entry_get(struct driver_info, __name, driver_info) + +/** +* populate_phandle_data() - Populates phandle data in platda +* +* This populates phandle data with an U_BOOT_DEVICE entry get by +* DM_GET_DEVICE. The implementation of this function will be done +* by dtoc when parsing dtb. +*/ +void populate_phandle_data (void );#endif
PATCH 5/10 core: extend struct driver_info to point to device
Hi Walter,
Quoted 52 lines · Walter Lozano
Quoted 34 lines · Walter Lozano
Currently when creating an
U_BOOT_DEVICEentry a structdriver_infois declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its structdriver_info.This patch extends struct
driver_infoadding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its structdriver_info.Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)drivers/core/device.c +1
-1@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ; drv =lists_driver_lookup_name (info->name);if (!drv)@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif - return device_bind_common(parent, drv, info->name,drivers/core/device.c int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, · line 271
Quoted 10 lines
drivers/core/device.c +8
-2- (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif I have tried to test this using
sandbox_spl_defconfigbut I've received a segmentation fault when trying to updateinfo->dev, however this code works on iMX6.
Quoted 1 line
Could it be some kind of protection? Any thoughts?
Yes, see u-boot-dm/dtoc-working - arch/sandbox/cpu/u-boot-spl.lds has an attempt to move some of the list stuff into the data region.
[..]
Regards,
Simon
PATCH 5/10 core: extend struct driver_info to point to device
Hi Simon,
Quoted 53 lines · Simon Glass
Hi Walter,
Quoted 50 lines · Walter Lozano
Quoted 34 lines · Walter Lozano
Currently when creating an
U_BOOT_DEVICEentry a structdriver_infois declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its structdriver_info.This patch extends struct
driver_infoadding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its structdriver_info.Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)drivers/core/device.c +1
-1@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ; drv =lists_driver_lookup_name (info->name);if (!drv)@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif - return device_bind_common(parent, drv, info->name,drivers/core/device.c int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, · line 271
Quoted 10 lines
drivers/core/device.c +8
-2- (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif I have tried to test this using
sandbox_spl_defconfigbut I've received a segmentation fault when trying to updateinfo->dev, however this code works on iMX6.
Quoted 3 lines
Quoted 1 line
Could it be some kind of protection? Any thoughts?
Yes, see u-boot-dm/dtoc-working -
arch/sandbox/cpu/u-boot-spl.ldshas an attempt to move some of the list stuff into the data region.
Thanks for confirmed it and also for the quick response. I'm about to start a deeper review to your work about tiny-dm now.
Regards,
Walter
PATCH 5/10 core: extend struct driver_info to point to device
Hi Walter,
Quoted 57 lines · Walter Lozano
Hi Simon,
Quoted 53 lines · Simon Glass
Hi Walter,
Quoted 50 lines · Walter Lozano
Quoted 34 lines · Walter Lozano
Currently when creating an
U_BOOT_DEVICEentry a structdriver_infois declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its structdriver_info.This patch extends struct
driver_infoadding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its structdriver_info.Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)drivers/core/device.c +1
-1@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ; drv =lists_driver_lookup_name (info->name);if (!drv)@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif - return device_bind_common(parent, drv, info->name,drivers/core/device.c int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, · line 271
Quoted 10 lines
drivers/core/device.c +8
-2- (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif I have tried to test this using
sandbox_spl_defconfigbut I've received a segmentation fault when trying to updateinfo->dev, however this code works on iMX6.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Could it be some kind of protection? Any thoughts?
Yes, see u-boot-dm/dtoc-working -
arch/sandbox/cpu/u-boot-spl.ldshas an attempt to move some of the list stuff into the data region.Thanks for confirmed it and also for the quick response. I'm about to start a deeper review to your work about tiny-dm now.
OK, but don't take too much notice of it as it is very rough.
One other thing that might be interesting is that I found a way to put links in data structures:
#define DM_DECL_TINY_DRIVER(__name) \ll_entry_decl(struct tiny_drv, __name, tiny_drv)
/*
* Get a pointer to a given tiny driver, for use in data structures. This
* requires that the symbol be declared with DM_DECL_TINY_DRIVER() first */
#define DM_REF_TINY_DRIVER(__name) \ll_entry_ref(struct tiny_drv, __name, tiny_drv)
Regards,
Simon
PATCH 5/10 core: extend struct driver_info to point to device
In reply to Walter LozanoHi Walter,
Quoted 10 lines · Walter Lozano
Currently when creating an
U_BOOT_DEVICEentry a structdriver_infois declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its structdriver_info.This patch extends struct
driver_infoadding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its structdriver_info.
Quoted 7 lines
Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)
Nits below
drivers/core/device.c int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, · line 253
Quoted 10 lines
drivers/core/device.c +1
-0@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ;
Can you drop = 0 ?
Quoted 63 lines
drivers/core/device.c +22
-3drv =lists_driver_lookup_name (info->name);if (!drv)@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif -return device_bind_common (parent, drv, info->name, - (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif + +return ret; }static void *alloc_priv (int size,uint flags)@@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); } +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp) +{ +struct udevice *dev; + + dev = info->dev; + +return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); +} +#endif +int device_find_first_child (const struct udevice *parent,struct udevice **devp) {if (list_empty (&parent->child_head)) {drivers/core/root.c +4
-0@@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only) {int ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +populate_phandle_data (); +#endif + ret =dm_init (IS_ENABLED (CONFIG_OF_LIVE ));if (ret) {debug ("dm_init() failed: %d\n" , ret);include/dm/device.h +0
-0@@ -538,6 +538,20 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp);*/
include/dm/device.h int device_find_global_by_ofnode(ofnode node, struct udevice **devp); · line 548
Quoted 10 lines
include/dm/device.h +8
-0int device_get_global_by_ofnode (ofnode node,struct udevice **devp); +/** +* device_get_by_driver_info() - Get a device based on driver_info +* +* Locates a device by its struct driver_info. +* +* The device is probed to activate it ready for use. +* +* @info: Struct driver_info
Here you should mention using DM_GET_DRIVER() to find it.
Quoted 34 lines
include/dm/device.h +6
-0+* @devp: Returns pointer to device if found, otherwise this is set to NULL +* @return 0 if OK, -ve on error +*/ +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp); +/** * device_find_first_child() - Find the first child of a device * include/dm/platdata.h +4
-0@@ -22,12 +22,14 @@* @name: Driver name * @platdata: Driver-specific platform data * @platdata_size: Size of platform data structure +* @dev: Device created from this structure data */ struct driver_info {const char *name;const void *platdata;#if CONFIG_IS_ENABLED (OF_PLATDATA )uint platdata_size; +struct udevice *dev;#endif };@@ -43,4 +45,16 @@ struct driver_info {#define U_BOOT_DEVICES (__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info) +/* Get a pointer to a given driver */ +#define DM_GET_DEVICE (__name) \
include/dm/platdata.h struct driver_info { · line 59
Quoted 10 lines
include/dm/platdata.h +10
-0+ ll_entry_get(struct driver_info, __name, driver_info) + +/** +* populate_phandle_data() - Populates phandle data in platda +* +* This populates phandle data with an U_BOOT_DEVICE entry get by +* DM_GET_DEVICE. The implementation of this function will be done +* by dtoc when parsing dtb. +*/ +void populate_phandle_data (void );
dm_populate_phandle_data()
Quoted 4 lines
include/dm/platdata.h +0
-1#endif --2.20.1
Regards,
Simon
PATCH 5/10 core: extend struct driver_info to point to device
Quoted 19 lines · Simon Glass
Hi Walter,
Quoted 9 lines · Walter Lozano
Currently when creating an
U_BOOT_DEVICEentry a structdriver_infois declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its structdriver_info.This patch extends struct
driver_infoadding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its structdriver_info.Quoted 7 lines
Signed-off-by Walter Lozano <[email protected]>--- drivers/core/device.c | 26 +++++++++++++++++++++++--- drivers/core/root.c | 4 ++++ include/dm/device.h | 14 ++++++++++++++ include/dm/platdata.h | 14 ++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-)
Quoted 3 lines
Reviewed-by Simon Glass <[email protected]>Nits below
Thanks for taking the time!
Quoted 10 lines
drivers/core/device.c int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, · line 253
Quoted 9 lines
drivers/core/device.c +1
-0@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, {struct driver *drv;uint platdata_size =0 ; +int ret =0 ;Can you drop = 0 ?
Noted!
Quoted 65 lines
Quoted 65 lines
drivers/core/device.c +22
-3drv =lists_driver_lookup_name (info->name);if (!drv)@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,#if CONFIG_IS_ENABLED (OF_PLATDATA ) platdata_size = info->platdata_size;#endif -return device_bind_common (parent, drv, info->name, - (void *)info->platdata,0 ,ofnode_null (), platdata_size, - devp); + ret =device_bind_common (parent, drv, info->name, + (void *)info->platdata,0 ,ofnode_null (), + platdata_size, devp); +if (ret) +return ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) + info->dev = *devp; +#endif + +return ret; }static void *alloc_priv (int size,uint flags)@@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); } +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp) +{ +struct udevice *dev; + + dev = info->dev; + +return device_get_device_tail (dev, dev ?0 : -ENOENT , devp); +} +#endif +int device_find_first_child (const struct udevice *parent,struct udevice **devp) {if (list_empty (&parent->child_head)) {drivers/core/root.c +4
-0@@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only) {int ret; +#if CONFIG_IS_ENABLED (OF_PLATDATA ) +populate_phandle_data (); +#endif + ret =dm_init (IS_ENABLED (CONFIG_OF_LIVE ));if (ret) {debug ("dm_init() failed: %d\n" , ret);include/dm/device.h +0
-0@@ -538,6 +538,20 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp);*/ int device_get_global_by_ofnode (ofnode node,struct udevice **devp);
Quoted 9 lines
include/dm/device.h int device_find_global_by_ofnode(ofnode node, struct udevice **devp); · line 548
Quoted 8 lines
include/dm/device.h +8
-0+/** +* device_get_by_driver_info() - Get a device based on driver_info +* +* Locates a device by its struct driver_info. +* +* The device is probed to activate it ready for use. +* +* @info: Struct driver_info Here you should mention using
DM_GET_DRIVER()to find it.
OK, I'll add a reference.
Quoted 32 lines
Quoted 32 lines
include/dm/device.h +6
-0+* @devp: Returns pointer to device if found, otherwise this is set to NULL +* @return 0 if OK, -ve on error +*/ +int device_get_by_driver_info (const struct driver_info *info, +struct udevice **devp); +/** * device_find_first_child() - Find the first child of a device * include/dm/platdata.h +2
-0@@ -22,12 +22,14 @@* @name: Driver name * @platdata: Driver-specific platform data * @platdata_size: Size of platform data structure +* @dev: Device created from this structure data */ struct driver_info {const char *name;const void *platdata;#if CONFIG_IS_ENABLED (OF_PLATDATA )uint platdata_size; +struct udevice *dev;#endif };@@ -43,4 +45,16 @@ struct driver_info {#define U_BOOT_DEVICES (__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info)
Quoted 13 lines
include/dm/platdata.h struct driver_info { · line 59
Quoted 12 lines
include/dm/platdata.h +12
-0+/* Get a pointer to a given driver */ +#define DM_GET_DEVICE (__name) \ + ll_entry_get(struct driver_info, __name, driver_info) + +/** +* populate_phandle_data() - Populates phandle data in platda +* +* This populates phandle data with an U_BOOT_DEVICE entry get by +* DM_GET_DEVICE. The implementation of this function will be done +* by dtoc when parsing dtb. +*/ +void populate_phandle_data (void );
dm_populate_phandle_data()
Sure!
Quoted 5 lines
Quoted 5 lines
include/dm/platdata.h +0
-1#endif --2.20.1
Regards,
Walter
PATCH 6/10 dtoc: extend dtoc to use struct driver_info when linking nodes
In reply to Walter LozanoIn the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information.
This patch extends dtoc to use struct driver_info when populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions like clk_get_by_index_platdata() which made use of the previous approach.
--- drivers/clk/clk-uclass.c | 11 +++++------ drivers/misc/irq-uclass.c | 10 ++++------ drivers/mmc/ftsdc010_mci.c | 2 +- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mmc/rockchip_sdhci.c | 2 +- drivers/ram/rockchip/sdram_rk3399.c | 2 +- drivers/spi/rk_spi.c | 2 +- include/clk.h | 4 ++-- tools/dtoc/dtb_platdata.py | 24 +++++++++++++++++++++--- 9 files changed, 37 insertions(+), 22 deletions(-)
drivers/clk/clk-uclass.c +5 -6
@@ -25,17 +25,16 @@ static inline const struct clk_ops *clk_dev_ops(struct udevice *dev)#if CONFIG_IS_ENABLED (OF_CONTROL )# if CONFIG_IS_ENABLED (OF_PLATDATA ) -int clk_get_by_index_platdata (struct udevice *dev,int index, -struct phandle_1_arg *cells,struct clk *clk) +int clk_get_by_driver_info (struct udevice *dev,struct phandle_1_arg *cells, +struct clk *clk) {int ret; -if (index !=0 ) -return -ENOSYS ; - ret =uclass_get_device (UCLASS_CLK ,0 , &clk->dev); + ret =device_get_by_driver_info ((struct driver_info *)cells->node, + &clk->dev);if (ret)return ret; - clk->id = cells[0 ].arg[0 ]; + clk->id = cells->arg[0 ];return 0 ; }
drivers/misc/irq-uclass.c +4 -6
@@ -63,17 +63,15 @@ int irq_read_and_clear(struct irq *irq) }#if CONFIG_IS_ENABLED (OF_PLATDATA ) -int irq_get_by_index_platdata (struct udevice *dev,int index, -struct phandle_1_arg *cells,struct irq *irq) +int irq_get_by_driver_info (struct udevice *dev, +struct phandle_1_arg *cells,struct irq *irq) {int ret; -if (index !=0 ) -return -ENOSYS ; - ret =uclass_get_device (UCLASS_IRQ ,0 , &irq->dev); + ret =device_get_by_driver_info (cells->node, &irq->dev);if (ret)return ret; - irq->id = cells[0 ].arg[0 ]; + irq->id = cells->arg[0 ];return 0 ; }
drivers/mmc/ftsdc010_mci.c +1 -1
@@ -437,7 +437,7 @@ static int ftsdc010_mmc_probe(struct udevice *dev) chip->priv = dev; chip->dev_index =1 ;memcpy (priv->minmax, dtplat->clock_freq_min_max,sizeof (priv->minmax)); - ret =clk_get_by_index_platdata (dev,0 , dtplat->clocks, &priv->clk); + ret =clk_get_by_driver_info (dev, dtplat->clocks, &priv->clk);if (ret <0 )return ret;#endif
drivers/mmc/rockchip_dw_mmc.c +1 -1
@@ -120,7 +120,7 @@ static int rockchip_dwmmc_probe(struct udevice *dev) priv->minmax[0 ] =400000 ;/* 400 kHz */ priv->minmax[1 ] = dtplat->max_frequency; - ret =clk_get_by_index_platdata (dev,0 , dtplat->clocks, &priv->clk); + ret =clk_get_by_driver_info (dev, dtplat->clocks, &priv->clk);if (ret <0 )return ret;#else
drivers/mmc/rockchip_sdhci.c +1 -1
@@ -46,7 +46,7 @@ static int arasan_sdhci_probe(struct udevice *dev) host->name = dev->name; host->ioaddr =map_sysmem (dtplat->reg[0 ], dtplat->reg[1 ]); max_frequency = dtplat->max_frequency; - ret =clk_get_by_index_platdata (dev,0 , dtplat->clocks, &clk); + ret =clk_get_by_driver_info (dev, dtplat->clocks, &clk);#else max_frequency =dev_read_u32_default (dev,"max-frequency" ,0 ); ret =clk_get_by_index (dev,0 , &clk);
drivers/ram/rockchip/sdram_rk3399.c +1 -1
@@ -3125,7 +3125,7 @@ static int rk3399_dmc_init(struct udevice *dev) priv->cic, priv->pmugrf, priv->pmusgrf, priv->pmucru, priv->pmu);#if CONFIG_IS_ENABLED (OF_PLATDATA ) - ret =clk_get_by_index_platdata (dev,0 , dtplat->clocks, &priv->ddr_clk); + ret =clk_get_by_driver_info (dev, dtplat->clocks, &priv->ddr_clk);#else ret =clk_get_by_index (dev,0 , &priv->ddr_clk);#endif
drivers/spi/rk_spi.c +1 -1
@@ -181,7 +181,7 @@ static int conv_of_platdata(struct udevice *dev) plat->base = dtplat->reg[0 ]; plat->frequency =20000000 ; - ret =clk_get_by_index_platdata (dev,0 , dtplat->clocks, &priv->clk); + ret =clk_get_by_driver_info (dev, dtplat->clocks, &priv->clk);if (ret <0 )return ret; dev->req_seq =0 ;
include/clk.h +2 -2
@@ -89,8 +89,8 @@ struct clk_bulk {#if CONFIG_IS_ENABLED (OF_CONTROL ) &&CONFIG_IS_ENABLED (CLK )struct phandle_1_arg ; -int clk_get_by_index_platdata (struct udevice *dev,int index, -struct phandle_1_arg *cells,struct clk *clk); +int clk_get_by_driver_info (struct udevice *dev, +struct phandle_1_arg *cells,struct clk *clk);/** * clk_get_by_index - Get/request a clock by integer index.
tools/dtoc/dtb_platdata.py +21 -3
@@ -146,6 +146,7 @@ class DtbPlatdata(object): _aliases: Dict that hold aliases for compatible strings _drivers: List of valid driver names found in drivers/ _driver_aliases: Dict that holds aliases for driver names + _links: List of links to be included in populate_phandle_data """ def __init__(self, dtb_fname, include_disabled, warning_disable): self._fdt = None
@@ -158,6 +159,7 @@ class DtbPlatdata(object): self._aliases = {} self._drivers = [] self._driver_aliases = {} + self._links = [] def get_normalized_compat_name(self, node): """Get a node's normalized compat name
@@ -540,7 +542,7 @@ class DtbPlatdata(object): """ struct_name, _ = self.get_normalized_compat_name(node) var_name = conv_name_to_c(node.name) - self.buf('static const struct %s%s %s%s = {\n' % + self.buf('static struct %s%s %s%s = {\n' % (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) for pname in sorted(node.props): prop = node.props[pname]
@@ -559,6 +561,7 @@ class DtbPlatdata(object): if info: # Process the list as pairs of (phandle, id) pos = 0 + item = 0 for args in info.args: phandle_cell = prop.value[pos] phandle = fdt_util.fdt32_to_cpu(phandle_cell)
@@ -568,8 +571,14 @@ class DtbPlatdata(object): for i in range(args): arg_values.append(str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i]))) pos += 1 + args - vals.append('\t{&%s%s, {%s}}' % (VAL_PREFIX, name, - ', '.join(arg_values))) + # node member is filled with NULL as the real value + # will be update at run-time by populate_phandle_data() + vals.append('\t{NULL, {%s}}' % (', '.join(arg_values))) + var_node = '%s%s.%s[%d].node' % (VAL_PREFIX, var_name, member_name, item) + # Save the the link information to be use to define + # populate_phandle_data + self._links.append({'var_node': var_node, 'dev_name': name}) + item += 1 for val in vals: self.buf('\n\t\t%s,' % val) else:
@@ -625,6 +634,15 @@ class DtbPlatdata(object): self.output_node(node) nodes_to_output.remove(node) + # Define populate_phandle_data which will add the linking between + # nodes using DM_GET_DEVICE + # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx) + self.buf('void populate_phandle_data(void) {\n') + for l in self._links: + self.buf('\t%s = DM_GET_DEVICE(%s);\n' % (l['var_node'], l['dev_name'])) + self.buf('}\n') + + self.out(''.join(self.get_buf())) def run_steps(args, dtb_file, include_disabled, output, warning_disable = False): """Run all the steps of the dtoc tool
Signature · 1 line
2.20.1
PATCH 6/10 dtoc: extend dtoc to use struct driver_info when linking nodes
Quoted 13 lines · Walter Lozano
In the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information.
This patch extends dtoc to use struct
driver_infowhen populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions likeclk_get_by_index_platdata()which made use of the previous approach.Signed-off-by Walter Lozano <[email protected]>
Quoted 12 lines
--- drivers/clk/clk-uclass.c | 11 +++++------ drivers/misc/irq-uclass.c | 10 ++++------ drivers/mmc/ftsdc010_mci.c | 2 +- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mmc/rockchip_sdhci.c | 2 +- drivers/ram/rockchip/sdram_rk3399.c | 2 +- drivers/spi/rk_spi.c | 2 +- include/clk.h | 4 ++-- tools/dtoc/dtb_platdata.py | 24 +++++++++++++++++++++--- 9 files changed, 37 insertions(+), 22 deletions(-)
PATCH 7/10 dm: doc: update of-plat with new phandle support
In reply to Walter LozanoUpdate documentation to reflect the new phandle support when OF_PLATDATA is used. Now phandles are implemented as pointers to U_BOOT_DEVICE, which makes it possible to get a pointer to the actual device.
--- doc/driver-model/of-plat.rst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
doc/driver-model/of-plat.rst +16 -8
@@ -69,9 +69,8 @@ strictly necessary. Notable problems include: - Correct relations between nodes are not implemented. This means that parent/child relations (like bus device iteration) do not work yet. Some phandles (those that are recognised as such) are converted into - a pointer to platform data. This pointer can potentially be used to - access the referenced device (by searching for the pointer value). - This feature is not yet implemented, however. + a pointer to struct driver_info. This pointer can be used to access + the referenced device. How it works
@@ -146,10 +145,10 @@ and the following device declaration: .clock_freq_min_max = {0x61a80, 0x8f0d180}, .vmmc_supply = 0xb, .num_slots = 0x1, - .clocks = {{&dtv_clock_controller_at_ff760000, 456}, - {&dtv_clock_controller_at_ff760000, 68}, - {&dtv_clock_controller_at_ff760000, 114}, - {&dtv_clock_controller_at_ff760000, 118}}, + .clocks = {{NULL, 456}, + {NULL, 68}, + {NULL, 114}, + {NULL, 118}}, .cap_mmc_highspeed = true, .disable_wp = true, .bus_width = 0x4,
@@ -164,6 +163,13 @@ and the following device declaration: .platdata_size = sizeof(dtv_dwmmc_at_ff0c0000), }; + void populate_phandle_data(void) { + dtv_dwmmc_at_ff0c0000.clocks[0].node = DM_GET_DEVICE(clock_controller_at_ff760000); + dtv_dwmmc_at_ff0c0000.clocks[1].node = DM_GET_DEVICE(clock_controller_at_ff760000); + dtv_dwmmc_at_ff0c0000.clocks[2].node = DM_GET_DEVICE(clock_controller_at_ff760000); + dtv_dwmmc_at_ff0c0000.clocks[3].node = DM_GET_DEVICE(clock_controller_at_ff760000); + } + The device is then instantiated at run-time and the platform data can be accessed using:
@@ -329,7 +335,9 @@ prevents them being used inadvertently. All usage must be bracketed with #if CONFIG_IS_ENABLED(OF_PLATDATA). The dt-platdata.c file contains the device declarations and is is built in -spl/dt-platdata.c. +spl/dt-platdata.c. It additionally contains the definition of +populate_phandle_data() which is responsible of filling the phandle +information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE The beginnings of a libfdt Python module are provided. So far this only implements a subset of the features.
Signature · 1 line
2.20.1
PATCH 7/10 dm: doc: update of-plat with new phandle support
Quoted 9 lines · Walter Lozano
Update documentation to reflect the new phandle support when
OF_PLATDATAis used. Now phandles are implemented as pointers toU_BOOT_DEVICE, which makes it possible to get a pointer to the actual device.Signed-off-by Walter Lozano <[email protected]>--- doc/driver-model/of-plat.rst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
But note dm_populate_...
I would like it to be easy to see what module/subsystem a function belongs to.
PATCH 7/10 dm: doc: update of-plat with new phandle support
Hi Simon,
Quoted 9 lines · Simon Glass
Quoted 8 lines · Walter Lozano
Update documentation to reflect the new phandle support when
OF_PLATDATAis used. Now phandles are implemented as pointers toU_BOOT_DEVICE, which makes it possible to get a pointer to the actual device.Signed-off-by Walter Lozano <[email protected]>--- doc/driver-model/of-plat.rst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
Quoted 5 lines
Reviewed-by Simon Glass <[email protected]>But note
dm_populate_...I would like it to be easy to see what module/subsystem a function belongs to.
Sure, I totally agree.
Thanks again for your deep review.
Regards,
Walter
PATCH 8/10 dtoc: update tests to match new platdata
In reply to Walter LozanoAfter using a new approach to link nodes when OF_PLATDATA is enabled the test cases need to be update.
This patch updates the tests based on this new implementation.
--- tools/dtoc/test_dtoc.py | 95 +++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 41 deletions(-)
tools/dtoc/test_dtoc.py +54 -41
@@ -47,6 +47,9 @@ C_HEADER = '''/* #include <dt-structs.h> ''' +C_EMPTY_POPULATE_PHANDLE_DATA = '''void populate_phandle_data(void) { +} +''' def get_dtb_file(dts_fname, capture_stderr=False):
@@ -162,7 +165,7 @@ class TestDtoc(unittest.TestCase): dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True) with open(output) as infile: lines = infile.read().splitlines() - self.assertEqual(C_HEADER.splitlines() + [''], lines) + self.assertEqual(C_HEADER.splitlines() + [''] + C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines) def test_simple(self): """Test output from some simple nodes with various types of data"""
@@ -197,7 +200,7 @@ struct dtd_sandbox_spl_test_2 { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_sandbox_spl_test dtv_spl_test = { +static struct dtd_sandbox_spl_test dtv_spl_test = { \t.boolval\t\t= true, \t.bytearray\t\t= {0x6, 0x0, 0x0}, \t.byteval\t\t= 0x5,
@@ -215,7 +218,7 @@ U_BOOT_DEVICE(spl_test) = { \t.platdata_size\t= sizeof(dtv_spl_test), }; -static const struct dtd_sandbox_spl_test dtv_spl_test2 = { +static struct dtd_sandbox_spl_test dtv_spl_test2 = { \t.bytearray\t\t= {0x1, 0x23, 0x34}, \t.byteval\t\t= 0x8, \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0},
@@ -231,7 +234,7 @@ U_BOOT_DEVICE(spl_test2) = { \t.platdata_size\t= sizeof(dtv_spl_test2), }; -static const struct dtd_sandbox_spl_test dtv_spl_test3 = { +static struct dtd_sandbox_spl_test dtv_spl_test3 = { \t.stringarray\t\t= {"one", "", ""}, }; U_BOOT_DEVICE(spl_test3) = {
@@ -240,7 +243,7 @@ U_BOOT_DEVICE(spl_test3) = { \t.platdata_size\t= sizeof(dtv_spl_test3), }; -static const struct dtd_sandbox_spl_test_2 dtv_spl_test4 = { +static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = { }; U_BOOT_DEVICE(spl_test4) = { \t.name\t\t= "sandbox_spl_test_2",
@@ -248,7 +251,7 @@ U_BOOT_DEVICE(spl_test4) = { \t.platdata_size\t= sizeof(dtv_spl_test4), }; -static const struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { +static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { }; U_BOOT_DEVICE(i2c_at_0) = { \t.name\t\t= "sandbox_i2c_test",
@@ -256,7 +259,7 @@ U_BOOT_DEVICE(i2c_at_0) = { \t.platdata_size\t= sizeof(dtv_i2c_at_0), }; -static const struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { +static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { \t.low_power\t\t= true, \t.reg\t\t\t= {0x9, 0x0}, };
@@ -266,7 +269,7 @@ U_BOOT_DEVICE(pmic_at_9) = { \t.platdata_size\t= sizeof(dtv_pmic_at_9), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_phandle(self): """Test output from a node containing a phandle reference"""
@@ -288,7 +291,7 @@ struct dtd_target { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_target dtv_phandle_target = { +static struct dtd_target dtv_phandle_target = { \t.intval\t\t\t= 0x0, }; U_BOOT_DEVICE(phandle_target) = {
@@ -297,7 +300,7 @@ U_BOOT_DEVICE(phandle_target) = { \t.platdata_size\t= sizeof(dtv_phandle_target), }; -static const struct dtd_target dtv_phandle2_target = { +static struct dtd_target dtv_phandle2_target = { \t.intval\t\t\t= 0x1, }; U_BOOT_DEVICE(phandle2_target) = {
@@ -306,7 +309,7 @@ U_BOOT_DEVICE(phandle2_target) = { \t.platdata_size\t= sizeof(dtv_phandle2_target), }; -static const struct dtd_target dtv_phandle3_target = { +static struct dtd_target dtv_phandle3_target = { \t.intval\t\t\t= 0x2, }; U_BOOT_DEVICE(phandle3_target) = {
@@ -315,12 +318,12 @@ U_BOOT_DEVICE(phandle3_target) = { \t.platdata_size\t= sizeof(dtv_phandle3_target), }; -static const struct dtd_source dtv_phandle_source = { +static struct dtd_source dtv_phandle_source = { \t.clocks\t\t\t= { -\t\t\t{&dtv_phandle_target, {}}, -\t\t\t{&dtv_phandle2_target, {11}}, -\t\t\t{&dtv_phandle3_target, {12, 13}}, -\t\t\t{&dtv_phandle_target, {}},}, +\t\t\t{NULL, {}}, +\t\t\t{NULL, {11}}, +\t\t\t{NULL, {12, 13}}, +\t\t\t{NULL, {}},}, }; U_BOOT_DEVICE(phandle_source) = { \t.name\t\t= "source",
@@ -328,9 +331,9 @@ U_BOOT_DEVICE(phandle_source) = { \t.platdata_size\t= sizeof(dtv_phandle_source), }; -static const struct dtd_source dtv_phandle_source2 = { +static struct dtd_source dtv_phandle_source2 = { \t.clocks\t\t\t= { -\t\t\t{&dtv_phandle_target, {}},}, +\t\t\t{NULL, {}},}, }; U_BOOT_DEVICE(phandle_source2) = { \t.name\t\t= "source",
@@ -338,6 +341,13 @@ U_BOOT_DEVICE(phandle_source2) = { \t.platdata_size\t= sizeof(dtv_phandle_source2), }; +void populate_phandle_data(void) { +\tdtv_phandle_source.clocks[0].node = DM_GET_DEVICE(phandle_target); +\tdtv_phandle_source.clocks[1].node = DM_GET_DEVICE(phandle2_target); +\tdtv_phandle_source.clocks[2].node = DM_GET_DEVICE(phandle3_target); +\tdtv_phandle_source.clocks[3].node = DM_GET_DEVICE(phandle_target); +\tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target); +} ''', data) def test_phandle_single(self):
@@ -364,7 +374,7 @@ struct dtd_target { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_target dtv_phandle_target = { +static struct dtd_target dtv_phandle_target = { }; U_BOOT_DEVICE(phandle_target) = { \t.name\t\t= "target",
@@ -372,9 +382,9 @@ U_BOOT_DEVICE(phandle_target) = { \t.platdata_size\t= sizeof(dtv_phandle_target), }; -static const struct dtd_source dtv_phandle_source2 = { +static struct dtd_source dtv_phandle_source2 = { \t.clocks\t\t\t= { -\t\t\t{&dtv_phandle_target, {}},}, +\t\t\t{NULL, {}},}, }; U_BOOT_DEVICE(phandle_source2) = { \t.name\t\t= "source",
@@ -382,6 +392,9 @@ U_BOOT_DEVICE(phandle_source2) = { \t.platdata_size\t= sizeof(dtv_phandle_source2), }; +void populate_phandle_data(void) { +\tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target); +} ''', data) def test_phandle_bad(self):
@@ -423,7 +436,7 @@ struct dtd_compat1 { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_compat1 dtv_spl_test = { +static struct dtd_compat1 dtv_spl_test = { \t.intval\t\t\t= 0x1, }; U_BOOT_DEVICE(spl_test) = {
@@ -432,7 +445,7 @@ U_BOOT_DEVICE(spl_test) = { \t.platdata_size\t= sizeof(dtv_spl_test), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_addresses64(self): """Test output from a node with a 'reg' property with na=2, ns=2"""
@@ -457,7 +470,7 @@ struct dtd_test3 { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_test1 dtv_test1 = { +static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; U_BOOT_DEVICE(test1) = {
@@ -466,7 +479,7 @@ U_BOOT_DEVICE(test1) = { \t.platdata_size\t= sizeof(dtv_test1), }; -static const struct dtd_test2 dtv_test2 = { +static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, }; U_BOOT_DEVICE(test2) = {
@@ -475,7 +488,7 @@ U_BOOT_DEVICE(test2) = { \t.platdata_size\t= sizeof(dtv_test2), }; -static const struct dtd_test3 dtv_test3 = { +static struct dtd_test3 dtv_test3 = { \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, }; U_BOOT_DEVICE(test3) = {
@@ -484,7 +497,7 @@ U_BOOT_DEVICE(test3) = { \t.platdata_size\t= sizeof(dtv_test3), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_addresses32(self): """Test output from a node with a 'reg' property with na=1, ns=1"""
@@ -506,7 +519,7 @@ struct dtd_test2 { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_test1 dtv_test1 = { +static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; U_BOOT_DEVICE(test1) = {
@@ -515,7 +528,7 @@ U_BOOT_DEVICE(test1) = { \t.platdata_size\t= sizeof(dtv_test1), }; -static const struct dtd_test2 dtv_test2 = { +static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, }; U_BOOT_DEVICE(test2) = {
@@ -524,7 +537,7 @@ U_BOOT_DEVICE(test2) = { \t.platdata_size\t= sizeof(dtv_test2), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_addresses64_32(self): """Test output from a node with a 'reg' property with na=2, ns=1"""
@@ -549,7 +562,7 @@ struct dtd_test3 { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_test1 dtv_test1 = { +static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x123400000000, 0x5678}, }; U_BOOT_DEVICE(test1) = {
@@ -558,7 +571,7 @@ U_BOOT_DEVICE(test1) = { \t.platdata_size\t= sizeof(dtv_test1), }; -static const struct dtd_test2 dtv_test2 = { +static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, }; U_BOOT_DEVICE(test2) = {
@@ -567,7 +580,7 @@ U_BOOT_DEVICE(test2) = { \t.platdata_size\t= sizeof(dtv_test2), }; -static const struct dtd_test3 dtv_test3 = { +static struct dtd_test3 dtv_test3 = { \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, }; U_BOOT_DEVICE(test3) = {
@@ -576,7 +589,7 @@ U_BOOT_DEVICE(test3) = { \t.platdata_size\t= sizeof(dtv_test3), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_addresses32_64(self): """Test output from a node with a 'reg' property with na=1, ns=2"""
@@ -601,7 +614,7 @@ struct dtd_test3 { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_test1 dtv_test1 = { +static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x567800000000}, }; U_BOOT_DEVICE(test1) = {
@@ -610,7 +623,7 @@ U_BOOT_DEVICE(test1) = { \t.platdata_size\t= sizeof(dtv_test1), }; -static const struct dtd_test2 dtv_test2 = { +static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, }; U_BOOT_DEVICE(test2) = {
@@ -619,7 +632,7 @@ U_BOOT_DEVICE(test2) = { \t.platdata_size\t= sizeof(dtv_test2), }; -static const struct dtd_test3 dtv_test3 = { +static struct dtd_test3 dtv_test3 = { \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, }; U_BOOT_DEVICE(test3) = {
@@ -628,7 +641,7 @@ U_BOOT_DEVICE(test3) = { \t.platdata_size\t= sizeof(dtv_test3), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_bad_reg(self): """Test that a reg property with an invalid type generates an error"""
@@ -668,7 +681,7 @@ struct dtd_sandbox_spl_test { with open(output) as infile: data = infile.read() self._CheckStrings(C_HEADER + ''' -static const struct dtd_sandbox_spl_test dtv_spl_test = { +static struct dtd_sandbox_spl_test dtv_spl_test = { \t.intval\t\t\t= 0x1, }; U_BOOT_DEVICE(spl_test) = {
@@ -677,7 +690,7 @@ U_BOOT_DEVICE(spl_test) = { \t.platdata_size\t= sizeof(dtv_spl_test), }; -static const struct dtd_sandbox_spl_test dtv_spl_test2 = { +static struct dtd_sandbox_spl_test dtv_spl_test2 = { \t.intarray\t\t= 0x5, }; U_BOOT_DEVICE(spl_test2) = {
@@ -686,7 +699,7 @@ U_BOOT_DEVICE(spl_test2) = { \t.platdata_size\t= sizeof(dtv_spl_test2), }; -''', data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def testStdout(self): """Test output to stdout"""
Signature · 1 line
2.20.1
PATCH 8/10 dtoc: update tests to match new platdata
Quoted 10 lines · Walter Lozano
After using a new approach to link nodes when
OF_PLATDATAis enabled the test cases need to be update.This patch updates the tests based on this new implementation.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/test_dtoc.py | 95 +++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 41 deletions(-)
PATCH 9/10 dtoc: update dtb_platdata to support cd-gpios
In reply to Walter LozanoCurrently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc.
This patch adds support to cd-gpios property.
--- tools/dtoc/dtb_platdata.py | 13 ++++++++----- tools/dtoc/test_dtoc.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-)
tools/dtoc/dtb_platdata.py +8 -5
@@ -250,7 +250,7 @@ class DtbPlatdata(object): Return: Number of argument cells is this is a phandle, else None """ - if prop.name in ['clocks']: + if prop.name in ['clocks', 'cd-gpios']: if not isinstance(prop.value, list): prop.value = [prop.value] val = prop.value
@@ -270,11 +270,14 @@ class DtbPlatdata(object): if not target: raise ValueError("Cannot parse '%s' in node '%s'" % (prop.name, node_name)) - prop_name = '#clock-cells' - cells = target.props.get(prop_name) + cells = None + for prop_name in ['#clock-cells', '#gpio-cells']: + cells = target.props.get(prop_name) + if cells: + break if not cells: - raise ValueError("Node '%s' has no '%s' property" % - (target.name, prop_name)) + raise ValueError("Node '%s' has no cells property" % + (target.name)) num_args = fdt_util.fdt32_to_cpu(cells.value) max_args = max(max_args, num_args) args.append(num_args)
tools/dtoc/test_dtoc.py +1 -1
@@ -414,7 +414,7 @@ void populate_phandle_data(void) { output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as e: dtb_platdata.run_steps(['struct'], dtb_file, False, output, True) - self.assertIn("Node 'phandle-target' has no '#clock-cells' property", + self.assertIn("Node 'phandle-target' has no cells property", str(e.exception)) def test_aliases(self):
Signature · 1 line
2.20.1
PATCH 9/10 dtoc: update dtb_platdata to support cd-gpios
Quoted 11 lines · Walter Lozano
Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc.
This patch adds support to cd-gpios property.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/dtb_platdata.py | 13 ++++++++----- tools/dtoc/test_dtoc.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-)
But I think you should mention GPIOs, rather than just cd-gpios, as it seems this will add support for any GPIO.
PATCH 9/10 dtoc: update dtb_platdata to support cd-gpios
Hi Simon
Quoted 11 lines · Simon Glass
Quoted 10 lines · Walter Lozano
Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc.
This patch adds support to cd-gpios property.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/dtb_platdata.py | 13 ++++++++----- tools/dtoc/test_dtoc.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-)
Quoted 4 lines
Reviewed-by Simon Glass <[email protected]>But I think you should mention GPIOs, rather than just cd-gpios, as it seems this will add support for any GPIO.
Sorry, probably I am missing something, but in order to support GPIOs in general we need to support a set of properties such as "cs-gpios", "rb-gpios", "gpios" among others.
Do you agree?
Regards,
Walter
PATCH 9/10 dtoc: update dtb_platdata to support cd-gpios
Hi Walter,
Quoted 17 lines · Walter Lozano
Hi Simon
Quoted 13 lines · Simon Glass
Quoted 10 lines · Walter Lozano
Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc.
This patch adds support to cd-gpios property.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/dtb_platdata.py | 13 ++++++++----- tools/dtoc/test_dtoc.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-)Reviewed-by Simon Glass <[email protected]>
Quoted 8 lines
Quoted 2 lines
But I think you should mention GPIOs, rather than just cd-gpios, as it seems this will add support for any GPIO.
Sorry, probably I am missing something, but in order to support GPIOs in general we need to support a set of properties such as "cs-gpios", "rb-gpios", "gpios" among others.
Do you agree?
OK yes I see. I was thinking of supporting any *-gpios but I think what you have here is better for now.
Regards,
Simon
PATCH 10/10 dtoc add test for cd-gpios
In reply to Walter LozanoAdd a test for dtoc taking into account the cd-gpios property.
--- tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 ++++++++++++++ tools/dtoc/test_dtoc.py | 67 +++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts
tools/dtoc/dtoc_test_phandle_cd_gpios.dts new file +42 -0
@@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2020 Collabora Ltd. + */ + +/dts-v1/; + +/ { + phandle: phandle-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <0>; + #gpio-cells = <0>; + }; + + phandle_1: phandle2-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <1>; + #gpio-cells = <1>; + }; + phandle_2: phandle3-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <2>; + #gpio-cells = <2>; + }; + + phandle-source { + u-boot,dm-pre-reloc; + compatible = "source"; + cd-gpios = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>; + }; + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + cd-gpios = <&phandle>; + }; +};
tools/dtoc/test_dtoc.py +67 -0
73 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 10/10 dtoc add test for cd-gpios
Quoted 9 lines · Walter Lozano
Add a test for dtoc taking into account the cd-gpios property.
Signed-off-by Walter Lozano <[email protected]>--- tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 ++++++++++++++ tools/dtoc/test_dtoc.py | 67 +++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts
cover improve OF_PLATDATA support
In reply to Walter LozanoHi Walter,
Quoted 10 lines · Walter Lozano
When using
OF_PLATDATAdtbs are converted to C structs in order to save space as we can remove both dtbs and libraries from TPL/SPL binaries.This patchset tries to improve its support by overcoming some limitations in the current implementation
First, the support for scan and check for valid driver/aliases is added in order to generate
U_BOOT_DEVICEentries with valid driver names.
Quoted 6 lines
Secondly, the way information about linked noded (phandle) is generated in C structs is improved in order to make it easier to get a device associated to its data.
Lastly the the suport for the property cd-gpios is added, which is used to configure the card detection gpio on MMC is added.
Does it impact the footprint? If yes any statistic about how much space has been reduced with respect to current platdata?
Jagan.
cover improve OF_PLATDATA support
Hi Jagan
Quoted 13 lines · Jagan Teki
Hi Walter,
Quoted 9 lines · Walter Lozano
When using
OF_PLATDATAdtbs are converted to C structs in order to save space as we can remove both dtbs and libraries from TPL/SPL binaries.This patchset tries to improve its support by overcoming some limitations in the current implementation
First, the support for scan and check for valid driver/aliases is added in order to generate
U_BOOT_DEVICEentries with valid driver names.
Quoted 9 lines
Quoted 6 lines
Secondly, the way information about linked noded (phandle) is generated in C structs is improved in order to make it easier to get a device associated to its data.
Lastly the the suport for the property cd-gpios is added, which is used to configure the card detection gpio on MMC is added.
Does it impact the footprint? If yes any statistic about how much space has been reduced with respect to current platdata?
This series tries to overcome some of the limitations of the OF_PLATDATA support, it does not provide an improvement to the footprint.
Mainly it makes it easier to implement OF_PLATDATA, by improving the better support to match compatible strings with a driver name and rising warning in case some driver name is not found. Additionally, it implements a way to access the device pointed by a phandle.
However, Simon Glass is working on footprint improvements with the support of tiny DM based on this work.
https://patchwork.ozlabs.org/project/uboot/patch/20200525093539.1.Ibf2d19439cde35e39192a9d4a8dad23539fae2e6 at changeid/
Regards,
Walter