Devicetree bug fixes and documentation for v3.17
Several bug fix commits for issues found in the v3.17 rc series. Most of these are minor in that they aren't actively dangerous, but they have been seen in the wild. The one important fix is7dbe5849fb
, "of: make sure of_alias is initialized before accessing it", without which some powerpc platforms will fail to find stdout for the console. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJUJBUMAAoJEMWQL496c2LNsaoP/2bnCom6lwkcqA5n1DMVd59/ ntUMykyKexAC0LSOpYg3tP9LRWhtgmEKpOWwziE4Kh0rzvIXxgEnqrSq3dRttlL/ JZs3afQ+r277NLUdSkMAyF62Xiw9A4P1cb86oFdTpjVJiVgiH16B5Fib6R0PpmO/ QQGEDTntXHizf94IUJWG2QXmh02Jna2QJl3vj7rl3B2ppVLg8Vu7pWMxKtZI7rPH lkSfgQc0Scusu/Y1LlHM0RHbYF2TeSUh9p1QYmK2UvM7A2XNcV/HoeK3p/iHi8lr RvuiqTwGOWDZAcCpKBo1R6PcXlxHrbpaxzdgBzy1B+kgFMZpu5yuqTfRmoMFz0Sa g0W/INYaaTKxUjsnIzfZUzTe7FVqjY5jAvoW5Ut2Cfx7ZRsNiuvRWoQjr0WSJ22Q 8IB2rh4Ma4n3vQMJBYxsuUwVSJPlENdS/XukRHj+YOY/ijH5ftUEFRMNhstk258u tGUy9HHeneQQBrJl2x553fZonP/u/AIr8rX8KFkPLlPAaw5FHKgkA6HoAaYikpt7 GeCcLq/+f2uYFm1x83oIhgaqElLUL1Rq7emD9fJS9DlfT08Iivjeg5Hof/9DdLWN epc+LRsCra0CDTK3c8bJm2v0nD/VyZ9jqC68J+Ng9tP+DlGXFsngqqH4q+RnWF/W kiSn/pM11fjM/xYu1dci =NS4A -----END PGP SIGNATURE----- Merge tag 'devicetree-for-linus' of git://git.secretlab.ca/git/linux Pull devicetree bug fixes and documentation from Grant Likely: "Several bug fix commits for issues found in the v3.17 rc series. Most of these are minor in that they aren't actively dangerous, but they have been seen in the wild. The one important fix is commit7dbe5849fb
("of: make sure of_alias is initialized before accessing it"), without which some powerpc platforms will fail to find stdout for the console" * tag 'devicetree-for-linus' of git://git.secretlab.ca/git/linux: of/fdt: fix memory range check of: Fix memory block alignment in early_init_dt_add_memory_arch() of: make sure of_alias is initialized before accessing it of: Documentation regarding attaching OF Selftest testdata of: Disabling OF functions that use sysfs if CONFIG_SYSFS disabled of: correct of_console_check()'s return value
This commit is contained in:
Коммит
4d3afba349
|
@ -0,0 +1,211 @@
|
|||
Open Firmware Device Tree Selftest
|
||||
----------------------------------
|
||||
|
||||
Author: Gaurav Minocha <gaurav.minocha.os@gmail.com>
|
||||
|
||||
1. Introduction
|
||||
|
||||
This document explains how the test data required for executing OF selftest
|
||||
is attached to the live tree dynamically, independent of the machine's
|
||||
architecture.
|
||||
|
||||
It is recommended to read the following documents before moving ahead.
|
||||
|
||||
[1] Documentation/devicetree/usage-model.txt
|
||||
[2] http://www.devicetree.org/Device_Tree_Usage
|
||||
|
||||
OF Selftest has been designed to test the interface (include/linux/of.h)
|
||||
provided to device driver developers to fetch the device information..etc.
|
||||
from the unflattened device tree data structure. This interface is used by
|
||||
most of the device drivers in various use cases.
|
||||
|
||||
|
||||
2. Test-data
|
||||
|
||||
The Device Tree Source file (drivers/of/testcase-data/testcases.dts) contains
|
||||
the test data required for executing the unit tests automated in
|
||||
drivers/of/selftests.c. Currently, following Device Tree Source Include files
|
||||
(.dtsi) are included in testcase.dts:
|
||||
|
||||
drivers/of/testcase-data/tests-interrupts.dtsi
|
||||
drivers/of/testcase-data/tests-platform.dtsi
|
||||
drivers/of/testcase-data/tests-phandle.dtsi
|
||||
drivers/of/testcase-data/tests-match.dtsi
|
||||
|
||||
When the kernel is build with OF_SELFTEST enabled, then the following make rule
|
||||
|
||||
$(obj)/%.dtb: $(src)/%.dts FORCE
|
||||
$(call if_changed_dep, dtc)
|
||||
|
||||
is used to compile the DT source file (testcase.dts) into a binary blob
|
||||
(testcase.dtb), also referred as flattened DT.
|
||||
|
||||
After that, using the following rule the binary blob above is wrapped as an
|
||||
assembly file (testcase.dtb.S).
|
||||
|
||||
$(obj)/%.dtb.S: $(obj)/%.dtb
|
||||
$(call cmd, dt_S_dtb)
|
||||
|
||||
The assembly file is compiled into an object file (testcase.dtb.o), and is
|
||||
linked into the kernel image.
|
||||
|
||||
|
||||
2.1. Adding the test data
|
||||
|
||||
Un-flattened device tree structure:
|
||||
|
||||
Un-flattened device tree consists of connected device_node(s) in form of a tree
|
||||
structure described below.
|
||||
|
||||
// following struct members are used to construct the tree
|
||||
struct device_node {
|
||||
...
|
||||
struct device_node *parent;
|
||||
struct device_node *child;
|
||||
struct device_node *sibling;
|
||||
struct device_node *allnext; /* next in list of all nodes */
|
||||
...
|
||||
};
|
||||
|
||||
Figure 1, describes a generic structure of machine’s un-flattened device tree
|
||||
considering only child and sibling pointers. There exists another pointer,
|
||||
*parent, that is used to traverse the tree in the reverse direction. So, at
|
||||
a particular level the child node and all the sibling nodes will have a parent
|
||||
pointer pointing to a common node (e.g. child1, sibling2, sibling3, sibling4’s
|
||||
parent points to root node)
|
||||
|
||||
root (‘/’)
|
||||
|
|
||||
child1 -> sibling2 -> sibling3 -> sibling4 -> null
|
||||
| | | |
|
||||
| | | null
|
||||
| | |
|
||||
| | child31 -> sibling32 -> null
|
||||
| | | |
|
||||
| | null null
|
||||
| |
|
||||
| child21 -> sibling22 -> sibling23 -> null
|
||||
| | | |
|
||||
| null null null
|
||||
|
|
||||
child11 -> sibling12 -> sibling13 -> sibling14 -> null
|
||||
| | | |
|
||||
| | | null
|
||||
| | |
|
||||
null null child131 -> null
|
||||
|
|
||||
null
|
||||
|
||||
Figure 1: Generic structure of un-flattened device tree
|
||||
|
||||
|
||||
*allnext: it is used to link all the nodes of DT into a list. So, for the
|
||||
above tree the list would be as follows:
|
||||
|
||||
root->child1->child11->sibling12->sibling13->child131->sibling14->sibling2->
|
||||
child21->sibling22->sibling23->sibling3->child31->sibling32->sibling4->null
|
||||
|
||||
Before executing OF selftest, it is required to attach the test data to
|
||||
machine's device tree (if present). So, when selftest_data_add() is called,
|
||||
at first it reads the flattened device tree data linked into the kernel image
|
||||
via the following kernel symbols:
|
||||
|
||||
__dtb_testcases_begin - address marking the start of test data blob
|
||||
__dtb_testcases_end - address marking the end of test data blob
|
||||
|
||||
Secondly, it calls of_fdt_unflatten_device_tree() to unflatten the flattened
|
||||
blob. And finally, if the machine’s device tree (i.e live tree) is present,
|
||||
then it attaches the unflattened test data tree to the live tree, else it
|
||||
attaches itself as a live device tree.
|
||||
|
||||
attach_node_and_children() uses of_attach_node() to attach the nodes into the
|
||||
live tree as explained below. To explain the same, the test data tree described
|
||||
in Figure 2 is attached to the live tree described in Figure 1.
|
||||
|
||||
root (‘/’)
|
||||
|
|
||||
testcase-data
|
||||
|
|
||||
test-child0 -> test-sibling1 -> test-sibling2 -> test-sibling3 -> null
|
||||
| | | |
|
||||
test-child01 null null null
|
||||
|
||||
|
||||
allnext list:
|
||||
|
||||
root->testcase-data->test-child0->test-child01->test-sibling1->test-sibling2
|
||||
->test-sibling3->null
|
||||
|
||||
Figure 2: Example test data tree to be attached to live tree.
|
||||
|
||||
According to the scenario above, the live tree is already present so it isn’t
|
||||
required to attach the root(‘/’) node. All other nodes are attached by calling
|
||||
of_attach_node() on each node.
|
||||
|
||||
In the function of_attach_node(), the new node is attached as the child of the
|
||||
given parent in live tree. But, if parent already has a child then the new node
|
||||
replaces the current child and turns it into its sibling. So, when the testcase
|
||||
data node is attached to the live tree above (Figure 1), the final structure is
|
||||
as shown in Figure 3.
|
||||
|
||||
root (‘/’)
|
||||
|
|
||||
testcase-data -> child1 -> sibling2 -> sibling3 -> sibling4 -> null
|
||||
| | | | |
|
||||
(...) | | | null
|
||||
| | child31 -> sibling32 -> null
|
||||
| | | |
|
||||
| | null null
|
||||
| |
|
||||
| child21 -> sibling22 -> sibling23 -> null
|
||||
| | | |
|
||||
| null null null
|
||||
|
|
||||
child11 -> sibling12 -> sibling13 -> sibling14 -> null
|
||||
| | | |
|
||||
null null | null
|
||||
|
|
||||
child131 -> null
|
||||
|
|
||||
null
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
root (‘/’)
|
||||
|
|
||||
testcase-data -> child1 -> sibling2 -> sibling3 -> sibling4 -> null
|
||||
| | | | |
|
||||
| (...) (...) (...) null
|
||||
|
|
||||
test-sibling3 -> test-sibling2 -> test-sibling1 -> test-child0 -> null
|
||||
| | | |
|
||||
null null null test-child01
|
||||
|
||||
|
||||
Figure 3: Live device tree structure after attaching the testcase-data.
|
||||
|
||||
|
||||
Astute readers would have noticed that test-child0 node becomes the last
|
||||
sibling compared to the earlier structure (Figure 2). After attaching first
|
||||
test-child0 the test-sibling1 is attached that pushes the child node
|
||||
(i.e. test-child0) to become a sibling and makes itself a child node,
|
||||
as mentioned above.
|
||||
|
||||
If a duplicate node is found (i.e. if a node with same full_name property is
|
||||
already present in the live tree), then the node isn’t attached rather its
|
||||
properties are updated to the live tree’s node by calling the function
|
||||
update_node_properties().
|
||||
|
||||
|
||||
2.2. Removing the test data
|
||||
|
||||
Once the test case execution is complete, selftest_data_remove is called in
|
||||
order to remove the device nodes attached initially (first the leaf nodes are
|
||||
detached and then moving up the parent nodes are removed, and eventually the
|
||||
whole tree). selftest_data_remove() calls detach_node_and_children() that uses
|
||||
of_detach_node() to detach the nodes from the live device tree.
|
||||
|
||||
To detach a node, of_detach_node() first updates all_next linked list, by
|
||||
attaching the previous node’s allnext to current node’s allnext pointer. And
|
||||
then, it either updates the child pointer of given node’s parent to its
|
||||
sibling or attaches the previous sibling to the given node’s sibling, as
|
||||
appropriate. That is it :)
|
|
@ -138,6 +138,9 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp)
|
|||
/* Important: Don't leak passwords */
|
||||
bool secure = strncmp(pp->name, "security-", 9) == 0;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_SYSFS))
|
||||
return 0;
|
||||
|
||||
if (!of_kset || !of_node_is_attached(np))
|
||||
return 0;
|
||||
|
||||
|
@ -158,6 +161,9 @@ int __of_attach_node_sysfs(struct device_node *np)
|
|||
struct property *pp;
|
||||
int rc;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_SYSFS))
|
||||
return 0;
|
||||
|
||||
if (!of_kset)
|
||||
return 0;
|
||||
|
||||
|
@ -1713,6 +1719,9 @@ int __of_remove_property(struct device_node *np, struct property *prop)
|
|||
|
||||
void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_SYSFS))
|
||||
return;
|
||||
|
||||
/* at early boot, bail here and defer setup to of_init() */
|
||||
if (of_kset && of_node_is_attached(np))
|
||||
sysfs_remove_bin_file(&np->kobj, &prop->attr);
|
||||
|
@ -1777,6 +1786,9 @@ int __of_update_property(struct device_node *np, struct property *newprop,
|
|||
void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
|
||||
struct property *oldprop)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_SYSFS))
|
||||
return;
|
||||
|
||||
/* At early boot, bail out and defer setup to of_init() */
|
||||
if (!of_kset)
|
||||
return;
|
||||
|
@ -1847,6 +1859,7 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
|
|||
{
|
||||
struct property *pp;
|
||||
|
||||
of_aliases = of_find_node_by_path("/aliases");
|
||||
of_chosen = of_find_node_by_path("/chosen");
|
||||
if (of_chosen == NULL)
|
||||
of_chosen = of_find_node_by_path("/chosen@0");
|
||||
|
@ -1862,7 +1875,6 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
|
|||
of_stdout = of_find_node_by_path(name);
|
||||
}
|
||||
|
||||
of_aliases = of_find_node_by_path("/aliases");
|
||||
if (!of_aliases)
|
||||
return;
|
||||
|
||||
|
@ -1986,7 +1998,7 @@ bool of_console_check(struct device_node *dn, char *name, int index)
|
|||
{
|
||||
if (!dn || dn != of_stdout || console_set_on_cmdline)
|
||||
return false;
|
||||
return add_preferred_console(name, index, NULL);
|
||||
return !add_preferred_console(name, index, NULL);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_console_check);
|
||||
|
||||
|
|
|
@ -45,6 +45,9 @@ void __of_detach_node_sysfs(struct device_node *np)
|
|||
{
|
||||
struct property *pp;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_SYSFS))
|
||||
return;
|
||||
|
||||
BUG_ON(!of_node_is_initialized(np));
|
||||
if (!of_kset)
|
||||
return;
|
||||
|
|
|
@ -928,7 +928,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
|
|||
void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
|
||||
{
|
||||
const u64 phys_offset = __pa(PAGE_OFFSET);
|
||||
base &= PAGE_MASK;
|
||||
|
||||
if (!PAGE_ALIGNED(base)) {
|
||||
size -= PAGE_SIZE - (base & ~PAGE_MASK);
|
||||
base = PAGE_ALIGN(base);
|
||||
}
|
||||
size &= PAGE_MASK;
|
||||
|
||||
if (base > MAX_PHYS_ADDR) {
|
||||
|
@ -937,10 +941,10 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
|
|||
return;
|
||||
}
|
||||
|
||||
if (base + size > MAX_PHYS_ADDR) {
|
||||
pr_warning("Ignoring memory range 0x%lx - 0x%llx\n",
|
||||
ULONG_MAX, base + size);
|
||||
size = MAX_PHYS_ADDR - base;
|
||||
if (base + size - 1 > MAX_PHYS_ADDR) {
|
||||
pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
|
||||
((u64)MAX_PHYS_ADDR) + 1, base + size);
|
||||
size = MAX_PHYS_ADDR - base + 1;
|
||||
}
|
||||
|
||||
if (base + size < phys_offset) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче