Commit 5513023cb74e56b3d6205f3ccc2d6a9ec8866369
Committed by
Lokesh Vutla
1 parent
af27d08464
Exists in
v2017.01-smarct4x
and in
2 other branches
dm: allow limiting pre-reloc markings to spl or tpl
Right now the u-boot,dm-pre-reloc flag will make each marked node always appear in both spl and tpl. But systems needing an additional tpl might have special constraints for each, like the spl needing to be very tiny. So introduce two additional flags to mark nodes for only spl or tpl environments and introduce a function dm_fdt_pre_reloc to automate the necessary checks in code instances checking for pre-relocation flags. The behaviour of the original flag stays untouched and still marks a node for both spl and tpl. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
Showing 8 changed files with 68 additions and 4 deletions Inline Diff
doc/driver-model/README.txt
1 | Driver Model | 1 | Driver Model |
2 | ============ | 2 | ============ |
3 | 3 | ||
4 | This README contains high-level information about driver model, a unified | 4 | This README contains high-level information about driver model, a unified |
5 | way of declaring and accessing drivers in U-Boot. The original work was done | 5 | way of declaring and accessing drivers in U-Boot. The original work was done |
6 | by: | 6 | by: |
7 | 7 | ||
8 | Marek Vasut <marex@denx.de> | 8 | Marek Vasut <marex@denx.de> |
9 | Pavel Herrmann <morpheus.ibis@gmail.com> | 9 | Pavel Herrmann <morpheus.ibis@gmail.com> |
10 | Viktor Křivák <viktor.krivak@gmail.com> | 10 | Viktor Křivák <viktor.krivak@gmail.com> |
11 | Tomas Hlavacek <tmshlvck@gmail.com> | 11 | Tomas Hlavacek <tmshlvck@gmail.com> |
12 | 12 | ||
13 | This has been both simplified and extended into the current implementation | 13 | This has been both simplified and extended into the current implementation |
14 | by: | 14 | by: |
15 | 15 | ||
16 | Simon Glass <sjg@chromium.org> | 16 | Simon Glass <sjg@chromium.org> |
17 | 17 | ||
18 | 18 | ||
19 | Terminology | 19 | Terminology |
20 | ----------- | 20 | ----------- |
21 | 21 | ||
22 | Uclass - a group of devices which operate in the same way. A uclass provides | 22 | Uclass - a group of devices which operate in the same way. A uclass provides |
23 | a way of accessing individual devices within the group, but always | 23 | a way of accessing individual devices within the group, but always |
24 | using the same interface. For example a GPIO uclass provides | 24 | using the same interface. For example a GPIO uclass provides |
25 | operations for get/set value. An I2C uclass may have 10 I2C ports, | 25 | operations for get/set value. An I2C uclass may have 10 I2C ports, |
26 | 4 with one driver, and 6 with another. | 26 | 4 with one driver, and 6 with another. |
27 | 27 | ||
28 | Driver - some code which talks to a peripheral and presents a higher-level | 28 | Driver - some code which talks to a peripheral and presents a higher-level |
29 | interface to it. | 29 | interface to it. |
30 | 30 | ||
31 | Device - an instance of a driver, tied to a particular port or peripheral. | 31 | Device - an instance of a driver, tied to a particular port or peripheral. |
32 | 32 | ||
33 | 33 | ||
34 | How to try it | 34 | How to try it |
35 | ------------- | 35 | ------------- |
36 | 36 | ||
37 | Build U-Boot sandbox and run it: | 37 | Build U-Boot sandbox and run it: |
38 | 38 | ||
39 | make sandbox_defconfig | 39 | make sandbox_defconfig |
40 | make | 40 | make |
41 | ./u-boot -d u-boot.dtb | 41 | ./u-boot -d u-boot.dtb |
42 | 42 | ||
43 | (type 'reset' to exit U-Boot) | 43 | (type 'reset' to exit U-Boot) |
44 | 44 | ||
45 | 45 | ||
46 | There is a uclass called 'demo'. This uclass handles | 46 | There is a uclass called 'demo'. This uclass handles |
47 | saying hello, and reporting its status. There are two drivers in this | 47 | saying hello, and reporting its status. There are two drivers in this |
48 | uclass: | 48 | uclass: |
49 | 49 | ||
50 | - simple: Just prints a message for hello, doesn't implement status | 50 | - simple: Just prints a message for hello, doesn't implement status |
51 | - shape: Prints shapes and reports number of characters printed as status | 51 | - shape: Prints shapes and reports number of characters printed as status |
52 | 52 | ||
53 | The demo class is pretty simple, but not trivial. The intention is that it | 53 | The demo class is pretty simple, but not trivial. The intention is that it |
54 | can be used for testing, so it will implement all driver model features and | 54 | can be used for testing, so it will implement all driver model features and |
55 | provide good code coverage of them. It does have multiple drivers, it | 55 | provide good code coverage of them. It does have multiple drivers, it |
56 | handles parameter data and platdata (data which tells the driver how | 56 | handles parameter data and platdata (data which tells the driver how |
57 | to operate on a particular platform) and it uses private driver data. | 57 | to operate on a particular platform) and it uses private driver data. |
58 | 58 | ||
59 | To try it, see the example session below: | 59 | To try it, see the example session below: |
60 | 60 | ||
61 | =>demo hello 1 | 61 | =>demo hello 1 |
62 | Hello '@' from 07981110: red 4 | 62 | Hello '@' from 07981110: red 4 |
63 | =>demo status 2 | 63 | =>demo status 2 |
64 | Status: 0 | 64 | Status: 0 |
65 | =>demo hello 2 | 65 | =>demo hello 2 |
66 | g | 66 | g |
67 | r@ | 67 | r@ |
68 | e@@ | 68 | e@@ |
69 | e@@@ | 69 | e@@@ |
70 | n@@@@ | 70 | n@@@@ |
71 | g@@@@@ | 71 | g@@@@@ |
72 | =>demo status 2 | 72 | =>demo status 2 |
73 | Status: 21 | 73 | Status: 21 |
74 | =>demo hello 4 ^ | 74 | =>demo hello 4 ^ |
75 | y^^^ | 75 | y^^^ |
76 | e^^^^^ | 76 | e^^^^^ |
77 | l^^^^^^^ | 77 | l^^^^^^^ |
78 | l^^^^^^^ | 78 | l^^^^^^^ |
79 | o^^^^^ | 79 | o^^^^^ |
80 | w^^^ | 80 | w^^^ |
81 | =>demo status 4 | 81 | =>demo status 4 |
82 | Status: 36 | 82 | Status: 36 |
83 | => | 83 | => |
84 | 84 | ||
85 | 85 | ||
86 | Running the tests | 86 | Running the tests |
87 | ----------------- | 87 | ----------------- |
88 | 88 | ||
89 | The intent with driver model is that the core portion has 100% test coverage | 89 | The intent with driver model is that the core portion has 100% test coverage |
90 | in sandbox, and every uclass has its own test. As a move towards this, tests | 90 | in sandbox, and every uclass has its own test. As a move towards this, tests |
91 | are provided in test/dm. To run them, try: | 91 | are provided in test/dm. To run them, try: |
92 | 92 | ||
93 | ./test/py/test.py --bd sandbox --build -k ut_dm -v | 93 | ./test/py/test.py --bd sandbox --build -k ut_dm -v |
94 | 94 | ||
95 | You should see something like this: | 95 | You should see something like this: |
96 | 96 | ||
97 | (venv)$ ./test/py/test.py --bd sandbox --build -k ut_dm -v | 97 | (venv)$ ./test/py/test.py --bd sandbox --build -k ut_dm -v |
98 | +make O=/root/u-boot/build-sandbox -s sandbox_defconfig | 98 | +make O=/root/u-boot/build-sandbox -s sandbox_defconfig |
99 | +make O=/root/u-boot/build-sandbox -s -j8 | 99 | +make O=/root/u-boot/build-sandbox -s -j8 |
100 | ============================= test session starts ============================== | 100 | ============================= test session starts ============================== |
101 | platform linux2 -- Python 2.7.5, pytest-2.9.0, py-1.4.31, pluggy-0.3.1 -- /root/u-boot/venv/bin/python | 101 | platform linux2 -- Python 2.7.5, pytest-2.9.0, py-1.4.31, pluggy-0.3.1 -- /root/u-boot/venv/bin/python |
102 | cachedir: .cache | 102 | cachedir: .cache |
103 | rootdir: /root/u-boot, inifile: | 103 | rootdir: /root/u-boot, inifile: |
104 | collected 199 items | 104 | collected 199 items |
105 | 105 | ||
106 | test/py/tests/test_ut.py::test_ut_dm_init PASSED | 106 | test/py/tests/test_ut.py::test_ut_dm_init PASSED |
107 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_bind] PASSED | 107 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_bind] PASSED |
108 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_multi_channel_conversion] PASSED | 108 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_multi_channel_conversion] PASSED |
109 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_multi_channel_shot] PASSED | 109 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_multi_channel_shot] PASSED |
110 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_single_channel_conversion] PASSED | 110 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_single_channel_conversion] PASSED |
111 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_single_channel_shot] PASSED | 111 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_single_channel_shot] PASSED |
112 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_supply] PASSED | 112 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_supply] PASSED |
113 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_wrong_channel_selection] PASSED | 113 | test/py/tests/test_ut.py::test_ut[ut_dm_adc_wrong_channel_selection] PASSED |
114 | test/py/tests/test_ut.py::test_ut[ut_dm_autobind] PASSED | 114 | test/py/tests/test_ut.py::test_ut[ut_dm_autobind] PASSED |
115 | test/py/tests/test_ut.py::test_ut[ut_dm_autobind_uclass_pdata_alloc] PASSED | 115 | test/py/tests/test_ut.py::test_ut[ut_dm_autobind_uclass_pdata_alloc] PASSED |
116 | test/py/tests/test_ut.py::test_ut[ut_dm_autobind_uclass_pdata_valid] PASSED | 116 | test/py/tests/test_ut.py::test_ut[ut_dm_autobind_uclass_pdata_valid] PASSED |
117 | test/py/tests/test_ut.py::test_ut[ut_dm_autoprobe] PASSED | 117 | test/py/tests/test_ut.py::test_ut[ut_dm_autoprobe] PASSED |
118 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_child_post_bind] PASSED | 118 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_child_post_bind] PASSED |
119 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_child_post_bind_uclass] PASSED | 119 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_child_post_bind_uclass] PASSED |
120 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_child_pre_probe_uclass] PASSED | 120 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_child_pre_probe_uclass] PASSED |
121 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_children] PASSED | 121 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_children] PASSED |
122 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_children_funcs] PASSED | 122 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_children_funcs] PASSED |
123 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_children_iterators] PASSED | 123 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_children_iterators] PASSED |
124 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_data] PASSED | 124 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_data] PASSED |
125 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_data_uclass] PASSED | 125 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_data_uclass] PASSED |
126 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_ops] PASSED | 126 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_ops] PASSED |
127 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_platdata] PASSED | 127 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_platdata] PASSED |
128 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_platdata_uclass] PASSED | 128 | test/py/tests/test_ut.py::test_ut[ut_dm_bus_parent_platdata_uclass] PASSED |
129 | test/py/tests/test_ut.py::test_ut[ut_dm_children] PASSED | 129 | test/py/tests/test_ut.py::test_ut[ut_dm_children] PASSED |
130 | test/py/tests/test_ut.py::test_ut[ut_dm_clk_base] PASSED | 130 | test/py/tests/test_ut.py::test_ut[ut_dm_clk_base] PASSED |
131 | test/py/tests/test_ut.py::test_ut[ut_dm_clk_periph] PASSED | 131 | test/py/tests/test_ut.py::test_ut[ut_dm_clk_periph] PASSED |
132 | test/py/tests/test_ut.py::test_ut[ut_dm_device_get_uclass_id] PASSED | 132 | test/py/tests/test_ut.py::test_ut[ut_dm_device_get_uclass_id] PASSED |
133 | test/py/tests/test_ut.py::test_ut[ut_dm_eth] PASSED | 133 | test/py/tests/test_ut.py::test_ut[ut_dm_eth] PASSED |
134 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_act] PASSED | 134 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_act] PASSED |
135 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_alias] PASSED | 135 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_alias] PASSED |
136 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_prime] PASSED | 136 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_prime] PASSED |
137 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_rotate] PASSED | 137 | test/py/tests/test_ut.py::test_ut[ut_dm_eth_rotate] PASSED |
138 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt] PASSED | 138 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt] PASSED |
139 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt_offset] PASSED | 139 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt_offset] PASSED |
140 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt_pre_reloc] PASSED | 140 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt_pre_reloc] PASSED |
141 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt_uclass_seq] PASSED | 141 | test/py/tests/test_ut.py::test_ut[ut_dm_fdt_uclass_seq] PASSED |
142 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio] PASSED | 142 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio] PASSED |
143 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_anon] PASSED | 143 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_anon] PASSED |
144 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_copy] PASSED | 144 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_copy] PASSED |
145 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_leak] PASSED | 145 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_leak] PASSED |
146 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_phandles] PASSED | 146 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_phandles] PASSED |
147 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_requestf] PASSED | 147 | test/py/tests/test_ut.py::test_ut[ut_dm_gpio_requestf] PASSED |
148 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_bytewise] PASSED | 148 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_bytewise] PASSED |
149 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_find] PASSED | 149 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_find] PASSED |
150 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_offset] PASSED | 150 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_offset] PASSED |
151 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_offset_len] PASSED | 151 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_offset_len] PASSED |
152 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_probe_empty] PASSED | 152 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_probe_empty] PASSED |
153 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_read_write] PASSED | 153 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_read_write] PASSED |
154 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_speed] PASSED | 154 | test/py/tests/test_ut.py::test_ut[ut_dm_i2c_speed] PASSED |
155 | test/py/tests/test_ut.py::test_ut[ut_dm_leak] PASSED | 155 | test/py/tests/test_ut.py::test_ut[ut_dm_leak] PASSED |
156 | test/py/tests/test_ut.py::test_ut[ut_dm_led_base] PASSED | 156 | test/py/tests/test_ut.py::test_ut[ut_dm_led_base] PASSED |
157 | test/py/tests/test_ut.py::test_ut[ut_dm_led_gpio] PASSED | 157 | test/py/tests/test_ut.py::test_ut[ut_dm_led_gpio] PASSED |
158 | test/py/tests/test_ut.py::test_ut[ut_dm_led_label] PASSED | 158 | test/py/tests/test_ut.py::test_ut[ut_dm_led_label] PASSED |
159 | test/py/tests/test_ut.py::test_ut[ut_dm_lifecycle] PASSED | 159 | test/py/tests/test_ut.py::test_ut[ut_dm_lifecycle] PASSED |
160 | test/py/tests/test_ut.py::test_ut[ut_dm_mmc_base] PASSED | 160 | test/py/tests/test_ut.py::test_ut[ut_dm_mmc_base] PASSED |
161 | test/py/tests/test_ut.py::test_ut[ut_dm_net_retry] PASSED | 161 | test/py/tests/test_ut.py::test_ut[ut_dm_net_retry] PASSED |
162 | test/py/tests/test_ut.py::test_ut[ut_dm_operations] PASSED | 162 | test/py/tests/test_ut.py::test_ut[ut_dm_operations] PASSED |
163 | test/py/tests/test_ut.py::test_ut[ut_dm_ordering] PASSED | 163 | test/py/tests/test_ut.py::test_ut[ut_dm_ordering] PASSED |
164 | test/py/tests/test_ut.py::test_ut[ut_dm_pci_base] PASSED | 164 | test/py/tests/test_ut.py::test_ut[ut_dm_pci_base] PASSED |
165 | test/py/tests/test_ut.py::test_ut[ut_dm_pci_busnum] PASSED | 165 | test/py/tests/test_ut.py::test_ut[ut_dm_pci_busnum] PASSED |
166 | test/py/tests/test_ut.py::test_ut[ut_dm_pci_swapcase] PASSED | 166 | test/py/tests/test_ut.py::test_ut[ut_dm_pci_swapcase] PASSED |
167 | test/py/tests/test_ut.py::test_ut[ut_dm_platdata] PASSED | 167 | test/py/tests/test_ut.py::test_ut[ut_dm_platdata] PASSED |
168 | test/py/tests/test_ut.py::test_ut[ut_dm_power_pmic_get] PASSED | 168 | test/py/tests/test_ut.py::test_ut[ut_dm_power_pmic_get] PASSED |
169 | test/py/tests/test_ut.py::test_ut[ut_dm_power_pmic_io] PASSED | 169 | test/py/tests/test_ut.py::test_ut[ut_dm_power_pmic_io] PASSED |
170 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_autoset] PASSED | 170 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_autoset] PASSED |
171 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_autoset_list] PASSED | 171 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_autoset_list] PASSED |
172 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_get] PASSED | 172 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_get] PASSED |
173 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_current] PASSED | 173 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_current] PASSED |
174 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_enable] PASSED | 174 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_enable] PASSED |
175 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_mode] PASSED | 175 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_mode] PASSED |
176 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_voltage] PASSED | 176 | test/py/tests/test_ut.py::test_ut[ut_dm_power_regulator_set_get_voltage] PASSED |
177 | test/py/tests/test_ut.py::test_ut[ut_dm_pre_reloc] PASSED | 177 | test/py/tests/test_ut.py::test_ut[ut_dm_pre_reloc] PASSED |
178 | test/py/tests/test_ut.py::test_ut[ut_dm_ram_base] PASSED | 178 | test/py/tests/test_ut.py::test_ut[ut_dm_ram_base] PASSED |
179 | test/py/tests/test_ut.py::test_ut[ut_dm_regmap_base] PASSED | 179 | test/py/tests/test_ut.py::test_ut[ut_dm_regmap_base] PASSED |
180 | test/py/tests/test_ut.py::test_ut[ut_dm_regmap_syscon] PASSED | 180 | test/py/tests/test_ut.py::test_ut[ut_dm_regmap_syscon] PASSED |
181 | test/py/tests/test_ut.py::test_ut[ut_dm_remoteproc_base] PASSED | 181 | test/py/tests/test_ut.py::test_ut[ut_dm_remoteproc_base] PASSED |
182 | test/py/tests/test_ut.py::test_ut[ut_dm_remove] PASSED | 182 | test/py/tests/test_ut.py::test_ut[ut_dm_remove] PASSED |
183 | test/py/tests/test_ut.py::test_ut[ut_dm_reset_base] PASSED | 183 | test/py/tests/test_ut.py::test_ut[ut_dm_reset_base] PASSED |
184 | test/py/tests/test_ut.py::test_ut[ut_dm_reset_walk] PASSED | 184 | test/py/tests/test_ut.py::test_ut[ut_dm_reset_walk] PASSED |
185 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_base] PASSED | 185 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_base] PASSED |
186 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_dual] PASSED | 186 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_dual] PASSED |
187 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_reset] PASSED | 187 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_reset] PASSED |
188 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_set_get] PASSED | 188 | test/py/tests/test_ut.py::test_ut[ut_dm_rtc_set_get] PASSED |
189 | test/py/tests/test_ut.py::test_ut[ut_dm_spi_find] PASSED | 189 | test/py/tests/test_ut.py::test_ut[ut_dm_spi_find] PASSED |
190 | test/py/tests/test_ut.py::test_ut[ut_dm_spi_flash] PASSED | 190 | test/py/tests/test_ut.py::test_ut[ut_dm_spi_flash] PASSED |
191 | test/py/tests/test_ut.py::test_ut[ut_dm_spi_xfer] PASSED | 191 | test/py/tests/test_ut.py::test_ut[ut_dm_spi_xfer] PASSED |
192 | test/py/tests/test_ut.py::test_ut[ut_dm_syscon_base] PASSED | 192 | test/py/tests/test_ut.py::test_ut[ut_dm_syscon_base] PASSED |
193 | test/py/tests/test_ut.py::test_ut[ut_dm_syscon_by_driver_data] PASSED | 193 | test/py/tests/test_ut.py::test_ut[ut_dm_syscon_by_driver_data] PASSED |
194 | test/py/tests/test_ut.py::test_ut[ut_dm_timer_base] PASSED | 194 | test/py/tests/test_ut.py::test_ut[ut_dm_timer_base] PASSED |
195 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass] PASSED | 195 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass] PASSED |
196 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_before_ready] PASSED | 196 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_before_ready] PASSED |
197 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_find] PASSED | 197 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_find] PASSED |
198 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_find_by_name] PASSED | 198 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_find_by_name] PASSED |
199 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_get] PASSED | 199 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_get] PASSED |
200 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_get_by_name] PASSED | 200 | test/py/tests/test_ut.py::test_ut[ut_dm_uclass_devices_get_by_name] PASSED |
201 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_base] PASSED | 201 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_base] PASSED |
202 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] PASSED | 202 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] PASSED |
203 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_keyb] PASSED | 203 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_keyb] PASSED |
204 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] PASSED | 204 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] PASSED |
205 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_remove] PASSED | 205 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_remove] PASSED |
206 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_tree] PASSED | 206 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_tree] PASSED |
207 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_tree_remove] PASSED | 207 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_tree_remove] PASSED |
208 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_tree_reorder] PASSED | 208 | test/py/tests/test_ut.py::test_ut[ut_dm_usb_tree_reorder] PASSED |
209 | test/py/tests/test_ut.py::test_ut[ut_dm_video_base] PASSED | 209 | test/py/tests/test_ut.py::test_ut[ut_dm_video_base] PASSED |
210 | test/py/tests/test_ut.py::test_ut[ut_dm_video_bmp] PASSED | 210 | test/py/tests/test_ut.py::test_ut[ut_dm_video_bmp] PASSED |
211 | test/py/tests/test_ut.py::test_ut[ut_dm_video_bmp_comp] PASSED | 211 | test/py/tests/test_ut.py::test_ut[ut_dm_video_bmp_comp] PASSED |
212 | test/py/tests/test_ut.py::test_ut[ut_dm_video_chars] PASSED | 212 | test/py/tests/test_ut.py::test_ut[ut_dm_video_chars] PASSED |
213 | test/py/tests/test_ut.py::test_ut[ut_dm_video_context] PASSED | 213 | test/py/tests/test_ut.py::test_ut[ut_dm_video_context] PASSED |
214 | test/py/tests/test_ut.py::test_ut[ut_dm_video_rotation1] PASSED | 214 | test/py/tests/test_ut.py::test_ut[ut_dm_video_rotation1] PASSED |
215 | test/py/tests/test_ut.py::test_ut[ut_dm_video_rotation2] PASSED | 215 | test/py/tests/test_ut.py::test_ut[ut_dm_video_rotation2] PASSED |
216 | test/py/tests/test_ut.py::test_ut[ut_dm_video_rotation3] PASSED | 216 | test/py/tests/test_ut.py::test_ut[ut_dm_video_rotation3] PASSED |
217 | test/py/tests/test_ut.py::test_ut[ut_dm_video_text] PASSED | 217 | test/py/tests/test_ut.py::test_ut[ut_dm_video_text] PASSED |
218 | test/py/tests/test_ut.py::test_ut[ut_dm_video_truetype] PASSED | 218 | test/py/tests/test_ut.py::test_ut[ut_dm_video_truetype] PASSED |
219 | test/py/tests/test_ut.py::test_ut[ut_dm_video_truetype_bs] PASSED | 219 | test/py/tests/test_ut.py::test_ut[ut_dm_video_truetype_bs] PASSED |
220 | test/py/tests/test_ut.py::test_ut[ut_dm_video_truetype_scroll] PASSED | 220 | test/py/tests/test_ut.py::test_ut[ut_dm_video_truetype_scroll] PASSED |
221 | 221 | ||
222 | ======================= 84 tests deselected by '-kut_dm' ======================= | 222 | ======================= 84 tests deselected by '-kut_dm' ======================= |
223 | ================== 115 passed, 84 deselected in 3.77 seconds =================== | 223 | ================== 115 passed, 84 deselected in 3.77 seconds =================== |
224 | 224 | ||
225 | What is going on? | 225 | What is going on? |
226 | ----------------- | 226 | ----------------- |
227 | 227 | ||
228 | Let's start at the top. The demo command is in common/cmd_demo.c. It does | 228 | Let's start at the top. The demo command is in common/cmd_demo.c. It does |
229 | the usual command processing and then: | 229 | the usual command processing and then: |
230 | 230 | ||
231 | struct udevice *demo_dev; | 231 | struct udevice *demo_dev; |
232 | 232 | ||
233 | ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev); | 233 | ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev); |
234 | 234 | ||
235 | UCLASS_DEMO means the class of devices which implement 'demo'. Other | 235 | UCLASS_DEMO means the class of devices which implement 'demo'. Other |
236 | classes might be MMC, or GPIO, hashing or serial. The idea is that the | 236 | classes might be MMC, or GPIO, hashing or serial. The idea is that the |
237 | devices in the class all share a particular way of working. The class | 237 | devices in the class all share a particular way of working. The class |
238 | presents a unified view of all these devices to U-Boot. | 238 | presents a unified view of all these devices to U-Boot. |
239 | 239 | ||
240 | This function looks up a device for the demo uclass. Given a device | 240 | This function looks up a device for the demo uclass. Given a device |
241 | number we can find the device because all devices have registered with | 241 | number we can find the device because all devices have registered with |
242 | the UCLASS_DEMO uclass. | 242 | the UCLASS_DEMO uclass. |
243 | 243 | ||
244 | The device is automatically activated ready for use by uclass_get_device(). | 244 | The device is automatically activated ready for use by uclass_get_device(). |
245 | 245 | ||
246 | Now that we have the device we can do things like: | 246 | Now that we have the device we can do things like: |
247 | 247 | ||
248 | return demo_hello(demo_dev, ch); | 248 | return demo_hello(demo_dev, ch); |
249 | 249 | ||
250 | This function is in the demo uclass. It takes care of calling the 'hello' | 250 | This function is in the demo uclass. It takes care of calling the 'hello' |
251 | method of the relevant driver. Bearing in mind that there are two drivers, | 251 | method of the relevant driver. Bearing in mind that there are two drivers, |
252 | this particular device may use one or other of them. | 252 | this particular device may use one or other of them. |
253 | 253 | ||
254 | The code for demo_hello() is in drivers/demo/demo-uclass.c: | 254 | The code for demo_hello() is in drivers/demo/demo-uclass.c: |
255 | 255 | ||
256 | int demo_hello(struct udevice *dev, int ch) | 256 | int demo_hello(struct udevice *dev, int ch) |
257 | { | 257 | { |
258 | const struct demo_ops *ops = device_get_ops(dev); | 258 | const struct demo_ops *ops = device_get_ops(dev); |
259 | 259 | ||
260 | if (!ops->hello) | 260 | if (!ops->hello) |
261 | return -ENOSYS; | 261 | return -ENOSYS; |
262 | 262 | ||
263 | return ops->hello(dev, ch); | 263 | return ops->hello(dev, ch); |
264 | } | 264 | } |
265 | 265 | ||
266 | As you can see it just calls the relevant driver method. One of these is | 266 | As you can see it just calls the relevant driver method. One of these is |
267 | in drivers/demo/demo-simple.c: | 267 | in drivers/demo/demo-simple.c: |
268 | 268 | ||
269 | static int simple_hello(struct udevice *dev, int ch) | 269 | static int simple_hello(struct udevice *dev, int ch) |
270 | { | 270 | { |
271 | const struct dm_demo_pdata *pdata = dev_get_platdata(dev); | 271 | const struct dm_demo_pdata *pdata = dev_get_platdata(dev); |
272 | 272 | ||
273 | printf("Hello from %08x: %s %d\n", map_to_sysmem(dev), | 273 | printf("Hello from %08x: %s %d\n", map_to_sysmem(dev), |
274 | pdata->colour, pdata->sides); | 274 | pdata->colour, pdata->sides); |
275 | 275 | ||
276 | return 0; | 276 | return 0; |
277 | } | 277 | } |
278 | 278 | ||
279 | 279 | ||
280 | So that is a trip from top (command execution) to bottom (driver action) | 280 | So that is a trip from top (command execution) to bottom (driver action) |
281 | but it leaves a lot of topics to address. | 281 | but it leaves a lot of topics to address. |
282 | 282 | ||
283 | 283 | ||
284 | Declaring Drivers | 284 | Declaring Drivers |
285 | ----------------- | 285 | ----------------- |
286 | 286 | ||
287 | A driver declaration looks something like this (see | 287 | A driver declaration looks something like this (see |
288 | drivers/demo/demo-shape.c): | 288 | drivers/demo/demo-shape.c): |
289 | 289 | ||
290 | static const struct demo_ops shape_ops = { | 290 | static const struct demo_ops shape_ops = { |
291 | .hello = shape_hello, | 291 | .hello = shape_hello, |
292 | .status = shape_status, | 292 | .status = shape_status, |
293 | }; | 293 | }; |
294 | 294 | ||
295 | U_BOOT_DRIVER(demo_shape_drv) = { | 295 | U_BOOT_DRIVER(demo_shape_drv) = { |
296 | .name = "demo_shape_drv", | 296 | .name = "demo_shape_drv", |
297 | .id = UCLASS_DEMO, | 297 | .id = UCLASS_DEMO, |
298 | .ops = &shape_ops, | 298 | .ops = &shape_ops, |
299 | .priv_data_size = sizeof(struct shape_data), | 299 | .priv_data_size = sizeof(struct shape_data), |
300 | }; | 300 | }; |
301 | 301 | ||
302 | 302 | ||
303 | This driver has two methods (hello and status) and requires a bit of | 303 | This driver has two methods (hello and status) and requires a bit of |
304 | private data (accessible through dev_get_priv(dev) once the driver has | 304 | private data (accessible through dev_get_priv(dev) once the driver has |
305 | been probed). It is a member of UCLASS_DEMO so will register itself | 305 | been probed). It is a member of UCLASS_DEMO so will register itself |
306 | there. | 306 | there. |
307 | 307 | ||
308 | In U_BOOT_DRIVER it is also possible to specify special methods for bind | 308 | In U_BOOT_DRIVER it is also possible to specify special methods for bind |
309 | and unbind, and these are called at appropriate times. For many drivers | 309 | and unbind, and these are called at appropriate times. For many drivers |
310 | it is hoped that only 'probe' and 'remove' will be needed. | 310 | it is hoped that only 'probe' and 'remove' will be needed. |
311 | 311 | ||
312 | The U_BOOT_DRIVER macro creates a data structure accessible from C, | 312 | The U_BOOT_DRIVER macro creates a data structure accessible from C, |
313 | so driver model can find the drivers that are available. | 313 | so driver model can find the drivers that are available. |
314 | 314 | ||
315 | The methods a device can provide are documented in the device.h header. | 315 | The methods a device can provide are documented in the device.h header. |
316 | Briefly, they are: | 316 | Briefly, they are: |
317 | 317 | ||
318 | bind - make the driver model aware of a device (bind it to its driver) | 318 | bind - make the driver model aware of a device (bind it to its driver) |
319 | unbind - make the driver model forget the device | 319 | unbind - make the driver model forget the device |
320 | ofdata_to_platdata - convert device tree data to platdata - see later | 320 | ofdata_to_platdata - convert device tree data to platdata - see later |
321 | probe - make a device ready for use | 321 | probe - make a device ready for use |
322 | remove - remove a device so it cannot be used until probed again | 322 | remove - remove a device so it cannot be used until probed again |
323 | 323 | ||
324 | The sequence to get a device to work is bind, ofdata_to_platdata (if using | 324 | The sequence to get a device to work is bind, ofdata_to_platdata (if using |
325 | device tree) and probe. | 325 | device tree) and probe. |
326 | 326 | ||
327 | 327 | ||
328 | Platform Data | 328 | Platform Data |
329 | ------------- | 329 | ------------- |
330 | 330 | ||
331 | *** Note: platform data is the old way of doing things. It is | 331 | *** Note: platform data is the old way of doing things. It is |
332 | *** basically a C structure which is passed to drivers to tell them about | 332 | *** basically a C structure which is passed to drivers to tell them about |
333 | *** platform-specific settings like the address of its registers, bus | 333 | *** platform-specific settings like the address of its registers, bus |
334 | *** speed, etc. Device tree is now the preferred way of handling this. | 334 | *** speed, etc. Device tree is now the preferred way of handling this. |
335 | *** Unless you have a good reason not to use device tree (the main one | 335 | *** Unless you have a good reason not to use device tree (the main one |
336 | *** being you need serial support in SPL and don't have enough SRAM for | 336 | *** being you need serial support in SPL and don't have enough SRAM for |
337 | *** the cut-down device tree and libfdt libraries) you should stay away | 337 | *** the cut-down device tree and libfdt libraries) you should stay away |
338 | *** from platform data. | 338 | *** from platform data. |
339 | 339 | ||
340 | Platform data is like Linux platform data, if you are familiar with that. | 340 | Platform data is like Linux platform data, if you are familiar with that. |
341 | It provides the board-specific information to start up a device. | 341 | It provides the board-specific information to start up a device. |
342 | 342 | ||
343 | Why is this information not just stored in the device driver itself? The | 343 | Why is this information not just stored in the device driver itself? The |
344 | idea is that the device driver is generic, and can in principle operate on | 344 | idea is that the device driver is generic, and can in principle operate on |
345 | any board that has that type of device. For example, with modern | 345 | any board that has that type of device. For example, with modern |
346 | highly-complex SoCs it is common for the IP to come from an IP vendor, and | 346 | highly-complex SoCs it is common for the IP to come from an IP vendor, and |
347 | therefore (for example) the MMC controller may be the same on chips from | 347 | therefore (for example) the MMC controller may be the same on chips from |
348 | different vendors. It makes no sense to write independent drivers for the | 348 | different vendors. It makes no sense to write independent drivers for the |
349 | MMC controller on each vendor's SoC, when they are all almost the same. | 349 | MMC controller on each vendor's SoC, when they are all almost the same. |
350 | Similarly, we may have 6 UARTs in an SoC, all of which are mostly the same, | 350 | Similarly, we may have 6 UARTs in an SoC, all of which are mostly the same, |
351 | but lie at different addresses in the address space. | 351 | but lie at different addresses in the address space. |
352 | 352 | ||
353 | Using the UART example, we have a single driver and it is instantiated 6 | 353 | Using the UART example, we have a single driver and it is instantiated 6 |
354 | times by supplying 6 lots of platform data. Each lot of platform data | 354 | times by supplying 6 lots of platform data. Each lot of platform data |
355 | gives the driver name and a pointer to a structure containing information | 355 | gives the driver name and a pointer to a structure containing information |
356 | about this instance - e.g. the address of the register space. It may be that | 356 | about this instance - e.g. the address of the register space. It may be that |
357 | one of the UARTS supports RS-485 operation - this can be added as a flag in | 357 | one of the UARTS supports RS-485 operation - this can be added as a flag in |
358 | the platform data, which is set for this one port and clear for the rest. | 358 | the platform data, which is set for this one port and clear for the rest. |
359 | 359 | ||
360 | Think of your driver as a generic piece of code which knows how to talk to | 360 | Think of your driver as a generic piece of code which knows how to talk to |
361 | a device, but needs to know where it is, any variant/option information and | 361 | a device, but needs to know where it is, any variant/option information and |
362 | so on. Platform data provides this link between the generic piece of code | 362 | so on. Platform data provides this link between the generic piece of code |
363 | and the specific way it is bound on a particular board. | 363 | and the specific way it is bound on a particular board. |
364 | 364 | ||
365 | Examples of platform data include: | 365 | Examples of platform data include: |
366 | 366 | ||
367 | - The base address of the IP block's register space | 367 | - The base address of the IP block's register space |
368 | - Configuration options, like: | 368 | - Configuration options, like: |
369 | - the SPI polarity and maximum speed for a SPI controller | 369 | - the SPI polarity and maximum speed for a SPI controller |
370 | - the I2C speed to use for an I2C device | 370 | - the I2C speed to use for an I2C device |
371 | - the number of GPIOs available in a GPIO device | 371 | - the number of GPIOs available in a GPIO device |
372 | 372 | ||
373 | Where does the platform data come from? It is either held in a structure | 373 | Where does the platform data come from? It is either held in a structure |
374 | which is compiled into U-Boot, or it can be parsed from the Device Tree | 374 | which is compiled into U-Boot, or it can be parsed from the Device Tree |
375 | (see 'Device Tree' below). | 375 | (see 'Device Tree' below). |
376 | 376 | ||
377 | For an example of how it can be compiled in, see demo-pdata.c which | 377 | For an example of how it can be compiled in, see demo-pdata.c which |
378 | sets up a table of driver names and their associated platform data. | 378 | sets up a table of driver names and their associated platform data. |
379 | The data can be interpreted by the drivers however they like - it is | 379 | The data can be interpreted by the drivers however they like - it is |
380 | basically a communication scheme between the board-specific code and | 380 | basically a communication scheme between the board-specific code and |
381 | the generic drivers, which are intended to work on any board. | 381 | the generic drivers, which are intended to work on any board. |
382 | 382 | ||
383 | Drivers can access their data via dev->info->platdata. Here is | 383 | Drivers can access their data via dev->info->platdata. Here is |
384 | the declaration for the platform data, which would normally appear | 384 | the declaration for the platform data, which would normally appear |
385 | in the board file. | 385 | in the board file. |
386 | 386 | ||
387 | static const struct dm_demo_cdata red_square = { | 387 | static const struct dm_demo_cdata red_square = { |
388 | .colour = "red", | 388 | .colour = "red", |
389 | .sides = 4. | 389 | .sides = 4. |
390 | }; | 390 | }; |
391 | static const struct driver_info info[] = { | 391 | static const struct driver_info info[] = { |
392 | { | 392 | { |
393 | .name = "demo_shape_drv", | 393 | .name = "demo_shape_drv", |
394 | .platdata = &red_square, | 394 | .platdata = &red_square, |
395 | }, | 395 | }, |
396 | }; | 396 | }; |
397 | 397 | ||
398 | demo1 = driver_bind(root, &info[0]); | 398 | demo1 = driver_bind(root, &info[0]); |
399 | 399 | ||
400 | 400 | ||
401 | Device Tree | 401 | Device Tree |
402 | ----------- | 402 | ----------- |
403 | 403 | ||
404 | While platdata is useful, a more flexible way of providing device data is | 404 | While platdata is useful, a more flexible way of providing device data is |
405 | by using device tree. In U-Boot you should use this where possible. Avoid | 405 | by using device tree. In U-Boot you should use this where possible. Avoid |
406 | sending patches which make use of the U_BOOT_DEVICE() macro unless strictly | 406 | sending patches which make use of the U_BOOT_DEVICE() macro unless strictly |
407 | necessary. | 407 | necessary. |
408 | 408 | ||
409 | With device tree we replace the above code with the following device tree | 409 | With device tree we replace the above code with the following device tree |
410 | fragment: | 410 | fragment: |
411 | 411 | ||
412 | red-square { | 412 | red-square { |
413 | compatible = "demo-shape"; | 413 | compatible = "demo-shape"; |
414 | colour = "red"; | 414 | colour = "red"; |
415 | sides = <4>; | 415 | sides = <4>; |
416 | }; | 416 | }; |
417 | 417 | ||
418 | This means that instead of having lots of U_BOOT_DEVICE() declarations in | 418 | This means that instead of having lots of U_BOOT_DEVICE() declarations in |
419 | the board file, we put these in the device tree. This approach allows a lot | 419 | the board file, we put these in the device tree. This approach allows a lot |
420 | more generality, since the same board file can support many types of boards | 420 | more generality, since the same board file can support many types of boards |
421 | (e,g. with the same SoC) just by using different device trees. An added | 421 | (e,g. with the same SoC) just by using different device trees. An added |
422 | benefit is that the Linux device tree can be used, thus further simplifying | 422 | benefit is that the Linux device tree can be used, thus further simplifying |
423 | the task of board-bring up either for U-Boot or Linux devs (whoever gets to | 423 | the task of board-bring up either for U-Boot or Linux devs (whoever gets to |
424 | the board first!). | 424 | the board first!). |
425 | 425 | ||
426 | The easiest way to make this work it to add a few members to the driver: | 426 | The easiest way to make this work it to add a few members to the driver: |
427 | 427 | ||
428 | .platdata_auto_alloc_size = sizeof(struct dm_test_pdata), | 428 | .platdata_auto_alloc_size = sizeof(struct dm_test_pdata), |
429 | .ofdata_to_platdata = testfdt_ofdata_to_platdata, | 429 | .ofdata_to_platdata = testfdt_ofdata_to_platdata, |
430 | 430 | ||
431 | The 'auto_alloc' feature allowed space for the platdata to be allocated | 431 | The 'auto_alloc' feature allowed space for the platdata to be allocated |
432 | and zeroed before the driver's ofdata_to_platdata() method is called. The | 432 | and zeroed before the driver's ofdata_to_platdata() method is called. The |
433 | ofdata_to_platdata() method, which the driver write supplies, should parse | 433 | ofdata_to_platdata() method, which the driver write supplies, should parse |
434 | the device tree node for this device and place it in dev->platdata. Thus | 434 | the device tree node for this device and place it in dev->platdata. Thus |
435 | when the probe method is called later (to set up the device ready for use) | 435 | when the probe method is called later (to set up the device ready for use) |
436 | the platform data will be present. | 436 | the platform data will be present. |
437 | 437 | ||
438 | Note that both methods are optional. If you provide an ofdata_to_platdata | 438 | Note that both methods are optional. If you provide an ofdata_to_platdata |
439 | method then it will be called first (during activation). If you provide a | 439 | method then it will be called first (during activation). If you provide a |
440 | probe method it will be called next. See Driver Lifecycle below for more | 440 | probe method it will be called next. See Driver Lifecycle below for more |
441 | details. | 441 | details. |
442 | 442 | ||
443 | If you don't want to have the platdata automatically allocated then you | 443 | If you don't want to have the platdata automatically allocated then you |
444 | can leave out platdata_auto_alloc_size. In this case you can use malloc | 444 | can leave out platdata_auto_alloc_size. In this case you can use malloc |
445 | in your ofdata_to_platdata (or probe) method to allocate the required memory, | 445 | in your ofdata_to_platdata (or probe) method to allocate the required memory, |
446 | and you should free it in the remove method. | 446 | and you should free it in the remove method. |
447 | 447 | ||
448 | The driver model tree is intended to mirror that of the device tree. The | 448 | The driver model tree is intended to mirror that of the device tree. The |
449 | root driver is at device tree offset 0 (the root node, '/'), and its | 449 | root driver is at device tree offset 0 (the root node, '/'), and its |
450 | children are the children of the root node. | 450 | children are the children of the root node. |
451 | 451 | ||
452 | 452 | ||
453 | Declaring Uclasses | 453 | Declaring Uclasses |
454 | ------------------ | 454 | ------------------ |
455 | 455 | ||
456 | The demo uclass is declared like this: | 456 | The demo uclass is declared like this: |
457 | 457 | ||
458 | U_BOOT_CLASS(demo) = { | 458 | U_BOOT_CLASS(demo) = { |
459 | .id = UCLASS_DEMO, | 459 | .id = UCLASS_DEMO, |
460 | }; | 460 | }; |
461 | 461 | ||
462 | It is also possible to specify special methods for probe, etc. The uclass | 462 | It is also possible to specify special methods for probe, etc. The uclass |
463 | numbering comes from include/dm/uclass.h. To add a new uclass, add to the | 463 | numbering comes from include/dm/uclass.h. To add a new uclass, add to the |
464 | end of the enum there, then declare your uclass as above. | 464 | end of the enum there, then declare your uclass as above. |
465 | 465 | ||
466 | 466 | ||
467 | Device Sequence Numbers | 467 | Device Sequence Numbers |
468 | ----------------------- | 468 | ----------------------- |
469 | 469 | ||
470 | U-Boot numbers devices from 0 in many situations, such as in the command | 470 | U-Boot numbers devices from 0 in many situations, such as in the command |
471 | line for I2C and SPI buses, and the device names for serial ports (serial0, | 471 | line for I2C and SPI buses, and the device names for serial ports (serial0, |
472 | serial1, ...). Driver model supports this numbering and permits devices | 472 | serial1, ...). Driver model supports this numbering and permits devices |
473 | to be locating by their 'sequence'. This numbering uniquely identifies a | 473 | to be locating by their 'sequence'. This numbering uniquely identifies a |
474 | device in its uclass, so no two devices within a particular uclass can have | 474 | device in its uclass, so no two devices within a particular uclass can have |
475 | the same sequence number. | 475 | the same sequence number. |
476 | 476 | ||
477 | Sequence numbers start from 0 but gaps are permitted. For example, a board | 477 | Sequence numbers start from 0 but gaps are permitted. For example, a board |
478 | may have I2C buses 1, 4, 5 but no 0, 2 or 3. The choice of how devices are | 478 | may have I2C buses 1, 4, 5 but no 0, 2 or 3. The choice of how devices are |
479 | numbered is up to a particular board, and may be set by the SoC in some | 479 | numbered is up to a particular board, and may be set by the SoC in some |
480 | cases. While it might be tempting to automatically renumber the devices | 480 | cases. While it might be tempting to automatically renumber the devices |
481 | where there are gaps in the sequence, this can lead to confusion and is | 481 | where there are gaps in the sequence, this can lead to confusion and is |
482 | not the way that U-Boot works. | 482 | not the way that U-Boot works. |
483 | 483 | ||
484 | Each device can request a sequence number. If none is required then the | 484 | Each device can request a sequence number. If none is required then the |
485 | device will be automatically allocated the next available sequence number. | 485 | device will be automatically allocated the next available sequence number. |
486 | 486 | ||
487 | To specify the sequence number in the device tree an alias is typically | 487 | To specify the sequence number in the device tree an alias is typically |
488 | used. Make sure that the uclass has the DM_UC_FLAG_SEQ_ALIAS flag set. | 488 | used. Make sure that the uclass has the DM_UC_FLAG_SEQ_ALIAS flag set. |
489 | 489 | ||
490 | aliases { | 490 | aliases { |
491 | serial2 = "/serial@22230000"; | 491 | serial2 = "/serial@22230000"; |
492 | }; | 492 | }; |
493 | 493 | ||
494 | This indicates that in the uclass called "serial", the named node | 494 | This indicates that in the uclass called "serial", the named node |
495 | ("/serial@22230000") will be given sequence number 2. Any command or driver | 495 | ("/serial@22230000") will be given sequence number 2. Any command or driver |
496 | which requests serial device 2 will obtain this device. | 496 | which requests serial device 2 will obtain this device. |
497 | 497 | ||
498 | More commonly you can use node references, which expand to the full path: | 498 | More commonly you can use node references, which expand to the full path: |
499 | 499 | ||
500 | aliases { | 500 | aliases { |
501 | serial2 = &serial_2; | 501 | serial2 = &serial_2; |
502 | }; | 502 | }; |
503 | ... | 503 | ... |
504 | serial_2: serial@22230000 { | 504 | serial_2: serial@22230000 { |
505 | ... | 505 | ... |
506 | }; | 506 | }; |
507 | 507 | ||
508 | The alias resolves to the same string in this case, but this version is | 508 | The alias resolves to the same string in this case, but this version is |
509 | easier to read. | 509 | easier to read. |
510 | 510 | ||
511 | Device sequence numbers are resolved when a device is probed. Before then | 511 | Device sequence numbers are resolved when a device is probed. Before then |
512 | the sequence number is only a request which may or may not be honoured, | 512 | the sequence number is only a request which may or may not be honoured, |
513 | depending on what other devices have been probed. However the numbering is | 513 | depending on what other devices have been probed. However the numbering is |
514 | entirely under the control of the board author so a conflict is generally | 514 | entirely under the control of the board author so a conflict is generally |
515 | an error. | 515 | an error. |
516 | 516 | ||
517 | 517 | ||
518 | Bus Drivers | 518 | Bus Drivers |
519 | ----------- | 519 | ----------- |
520 | 520 | ||
521 | A common use of driver model is to implement a bus, a device which provides | 521 | A common use of driver model is to implement a bus, a device which provides |
522 | access to other devices. Example of buses include SPI and I2C. Typically | 522 | access to other devices. Example of buses include SPI and I2C. Typically |
523 | the bus provides some sort of transport or translation that makes it | 523 | the bus provides some sort of transport or translation that makes it |
524 | possible to talk to the devices on the bus. | 524 | possible to talk to the devices on the bus. |
525 | 525 | ||
526 | Driver model provides some useful features to help with implementing buses. | 526 | Driver model provides some useful features to help with implementing buses. |
527 | Firstly, a bus can request that its children store some 'parent data' which | 527 | Firstly, a bus can request that its children store some 'parent data' which |
528 | can be used to keep track of child state. Secondly, the bus can define | 528 | can be used to keep track of child state. Secondly, the bus can define |
529 | methods which are called when a child is probed or removed. This is similar | 529 | methods which are called when a child is probed or removed. This is similar |
530 | to the methods the uclass driver provides. Thirdly, per-child platform data | 530 | to the methods the uclass driver provides. Thirdly, per-child platform data |
531 | can be provided to specify things like the child's address on the bus. This | 531 | can be provided to specify things like the child's address on the bus. This |
532 | persists across child probe()/remove() cycles. | 532 | persists across child probe()/remove() cycles. |
533 | 533 | ||
534 | For consistency and ease of implementation, the bus uclass can specify the | 534 | For consistency and ease of implementation, the bus uclass can specify the |
535 | per-child platform data, so that it can be the same for all children of buses | 535 | per-child platform data, so that it can be the same for all children of buses |
536 | in that uclass. There are also uclass methods which can be called when | 536 | in that uclass. There are also uclass methods which can be called when |
537 | children are bound and probed. | 537 | children are bound and probed. |
538 | 538 | ||
539 | Here an explanation of how a bus fits with a uclass may be useful. Consider | 539 | Here an explanation of how a bus fits with a uclass may be useful. Consider |
540 | a USB bus with several devices attached to it, each from a different (made | 540 | a USB bus with several devices attached to it, each from a different (made |
541 | up) uclass: | 541 | up) uclass: |
542 | 542 | ||
543 | xhci_usb (UCLASS_USB) | 543 | xhci_usb (UCLASS_USB) |
544 | eth (UCLASS_ETHERNET) | 544 | eth (UCLASS_ETHERNET) |
545 | camera (UCLASS_CAMERA) | 545 | camera (UCLASS_CAMERA) |
546 | flash (UCLASS_FLASH_STORAGE) | 546 | flash (UCLASS_FLASH_STORAGE) |
547 | 547 | ||
548 | Each of the devices is connected to a different address on the USB bus. | 548 | Each of the devices is connected to a different address on the USB bus. |
549 | The bus device wants to store this address and some other information such | 549 | The bus device wants to store this address and some other information such |
550 | as the bus speed for each device. | 550 | as the bus speed for each device. |
551 | 551 | ||
552 | To achieve this, the bus device can use dev->parent_platdata in each of its | 552 | To achieve this, the bus device can use dev->parent_platdata in each of its |
553 | three children. This can be auto-allocated if the bus driver (or bus uclass) | 553 | three children. This can be auto-allocated if the bus driver (or bus uclass) |
554 | has a non-zero value for per_child_platdata_auto_alloc_size. If not, then | 554 | has a non-zero value for per_child_platdata_auto_alloc_size. If not, then |
555 | the bus device or uclass can allocate the space itself before the child | 555 | the bus device or uclass can allocate the space itself before the child |
556 | device is probed. | 556 | device is probed. |
557 | 557 | ||
558 | Also the bus driver can define the child_pre_probe() and child_post_remove() | 558 | Also the bus driver can define the child_pre_probe() and child_post_remove() |
559 | methods to allow it to do some processing before the child is activated or | 559 | methods to allow it to do some processing before the child is activated or |
560 | after it is deactivated. | 560 | after it is deactivated. |
561 | 561 | ||
562 | Similarly the bus uclass can define the child_post_bind() method to obtain | 562 | Similarly the bus uclass can define the child_post_bind() method to obtain |
563 | the per-child platform data from the device tree and set it up for the child. | 563 | the per-child platform data from the device tree and set it up for the child. |
564 | The bus uclass can also provide a child_pre_probe() method. Very often it is | 564 | The bus uclass can also provide a child_pre_probe() method. Very often it is |
565 | the bus uclass that controls these features, since it avoids each driver | 565 | the bus uclass that controls these features, since it avoids each driver |
566 | having to do the same processing. Of course the driver can still tweak and | 566 | having to do the same processing. Of course the driver can still tweak and |
567 | override these activities. | 567 | override these activities. |
568 | 568 | ||
569 | Note that the information that controls this behaviour is in the bus's | 569 | Note that the information that controls this behaviour is in the bus's |
570 | driver, not the child's. In fact it is possible that child has no knowledge | 570 | driver, not the child's. In fact it is possible that child has no knowledge |
571 | that it is connected to a bus. The same child device may even be used on two | 571 | that it is connected to a bus. The same child device may even be used on two |
572 | different bus types. As an example. the 'flash' device shown above may also | 572 | different bus types. As an example. the 'flash' device shown above may also |
573 | be connected on a SATA bus or standalone with no bus: | 573 | be connected on a SATA bus or standalone with no bus: |
574 | 574 | ||
575 | xhci_usb (UCLASS_USB) | 575 | xhci_usb (UCLASS_USB) |
576 | flash (UCLASS_FLASH_STORAGE) - parent data/methods defined by USB bus | 576 | flash (UCLASS_FLASH_STORAGE) - parent data/methods defined by USB bus |
577 | 577 | ||
578 | sata (UCLASS_SATA) | 578 | sata (UCLASS_SATA) |
579 | flash (UCLASS_FLASH_STORAGE) - parent data/methods defined by SATA bus | 579 | flash (UCLASS_FLASH_STORAGE) - parent data/methods defined by SATA bus |
580 | 580 | ||
581 | flash (UCLASS_FLASH_STORAGE) - no parent data/methods (not on a bus) | 581 | flash (UCLASS_FLASH_STORAGE) - no parent data/methods (not on a bus) |
582 | 582 | ||
583 | Above you can see that the driver for xhci_usb/sata controls the child's | 583 | Above you can see that the driver for xhci_usb/sata controls the child's |
584 | bus methods. In the third example the device is not on a bus, and therefore | 584 | bus methods. In the third example the device is not on a bus, and therefore |
585 | will not have these methods at all. Consider the case where the flash | 585 | will not have these methods at all. Consider the case where the flash |
586 | device defines child methods. These would be used for *its* children, and | 586 | device defines child methods. These would be used for *its* children, and |
587 | would be quite separate from the methods defined by the driver for the bus | 587 | would be quite separate from the methods defined by the driver for the bus |
588 | that the flash device is connetced to. The act of attaching a device to a | 588 | that the flash device is connetced to. The act of attaching a device to a |
589 | parent device which is a bus, causes the device to start behaving like a | 589 | parent device which is a bus, causes the device to start behaving like a |
590 | bus device, regardless of its own views on the matter. | 590 | bus device, regardless of its own views on the matter. |
591 | 591 | ||
592 | The uclass for the device can also contain data private to that uclass. | 592 | The uclass for the device can also contain data private to that uclass. |
593 | But note that each device on the bus may be a memeber of a different | 593 | But note that each device on the bus may be a memeber of a different |
594 | uclass, and this data has nothing to do with the child data for each child | 594 | uclass, and this data has nothing to do with the child data for each child |
595 | on the bus. It is the bus' uclass that controls the child with respect to | 595 | on the bus. It is the bus' uclass that controls the child with respect to |
596 | the bus. | 596 | the bus. |
597 | 597 | ||
598 | 598 | ||
599 | Driver Lifecycle | 599 | Driver Lifecycle |
600 | ---------------- | 600 | ---------------- |
601 | 601 | ||
602 | Here are the stages that a device goes through in driver model. Note that all | 602 | Here are the stages that a device goes through in driver model. Note that all |
603 | methods mentioned here are optional - e.g. if there is no probe() method for | 603 | methods mentioned here are optional - e.g. if there is no probe() method for |
604 | a device then it will not be called. A simple device may have very few | 604 | a device then it will not be called. A simple device may have very few |
605 | methods actually defined. | 605 | methods actually defined. |
606 | 606 | ||
607 | 1. Bind stage | 607 | 1. Bind stage |
608 | 608 | ||
609 | U-Boot discovers devices using one of these two methods: | 609 | U-Boot discovers devices using one of these two methods: |
610 | 610 | ||
611 | - Scan the U_BOOT_DEVICE() definitions. U-Boot looks up the name specified | 611 | - Scan the U_BOOT_DEVICE() definitions. U-Boot looks up the name specified |
612 | by each, to find the appropriate U_BOOT_DRIVER() definition. In this case, | 612 | by each, to find the appropriate U_BOOT_DRIVER() definition. In this case, |
613 | there is no path by which driver_data may be provided, but the U_BOOT_DEVICE() | 613 | there is no path by which driver_data may be provided, but the U_BOOT_DEVICE() |
614 | may provide platdata. | 614 | may provide platdata. |
615 | 615 | ||
616 | - Scan through the device tree definitions. U-Boot looks at top-level | 616 | - Scan through the device tree definitions. U-Boot looks at top-level |
617 | nodes in the the device tree. It looks at the compatible string in each node | 617 | nodes in the the device tree. It looks at the compatible string in each node |
618 | and uses the of_match table of the U_BOOT_DRIVER() structure to find the | 618 | and uses the of_match table of the U_BOOT_DRIVER() structure to find the |
619 | right driver for each node. In this case, the of_match table may provide a | 619 | right driver for each node. In this case, the of_match table may provide a |
620 | driver_data value, but platdata cannot be provided until later. | 620 | driver_data value, but platdata cannot be provided until later. |
621 | 621 | ||
622 | For each device that is discovered, U-Boot then calls device_bind() to create a | 622 | For each device that is discovered, U-Boot then calls device_bind() to create a |
623 | new device, initializes various core fields of the device object such as name, | 623 | new device, initializes various core fields of the device object such as name, |
624 | uclass & driver, initializes any optional fields of the device object that are | 624 | uclass & driver, initializes any optional fields of the device object that are |
625 | applicable such as of_offset, driver_data & platdata, and finally calls the | 625 | applicable such as of_offset, driver_data & platdata, and finally calls the |
626 | driver's bind() method if one is defined. | 626 | driver's bind() method if one is defined. |
627 | 627 | ||
628 | At this point all the devices are known, and bound to their drivers. There | 628 | At this point all the devices are known, and bound to their drivers. There |
629 | is a 'struct udevice' allocated for all devices. However, nothing has been | 629 | is a 'struct udevice' allocated for all devices. However, nothing has been |
630 | activated (except for the root device). Each bound device that was created | 630 | activated (except for the root device). Each bound device that was created |
631 | from a U_BOOT_DEVICE() declaration will hold the platdata pointer specified | 631 | from a U_BOOT_DEVICE() declaration will hold the platdata pointer specified |
632 | in that declaration. For a bound device created from the device tree, | 632 | in that declaration. For a bound device created from the device tree, |
633 | platdata will be NULL, but of_offset will be the offset of the device tree | 633 | platdata will be NULL, but of_offset will be the offset of the device tree |
634 | node that caused the device to be created. The uclass is set correctly for | 634 | node that caused the device to be created. The uclass is set correctly for |
635 | the device. | 635 | the device. |
636 | 636 | ||
637 | The device's bind() method is permitted to perform simple actions, but | 637 | The device's bind() method is permitted to perform simple actions, but |
638 | should not scan the device tree node, not initialise hardware, nor set up | 638 | should not scan the device tree node, not initialise hardware, nor set up |
639 | structures or allocate memory. All of these tasks should be left for | 639 | structures or allocate memory. All of these tasks should be left for |
640 | the probe() method. | 640 | the probe() method. |
641 | 641 | ||
642 | Note that compared to Linux, U-Boot's driver model has a separate step of | 642 | Note that compared to Linux, U-Boot's driver model has a separate step of |
643 | probe/remove which is independent of bind/unbind. This is partly because in | 643 | probe/remove which is independent of bind/unbind. This is partly because in |
644 | U-Boot it may be expensive to probe devices and we don't want to do it until | 644 | U-Boot it may be expensive to probe devices and we don't want to do it until |
645 | they are needed, or perhaps until after relocation. | 645 | they are needed, or perhaps until after relocation. |
646 | 646 | ||
647 | 2. Activation/probe | 647 | 2. Activation/probe |
648 | 648 | ||
649 | When a device needs to be used, U-Boot activates it, by following these | 649 | When a device needs to be used, U-Boot activates it, by following these |
650 | steps (see device_probe()): | 650 | steps (see device_probe()): |
651 | 651 | ||
652 | a. If priv_auto_alloc_size is non-zero, then the device-private space | 652 | a. If priv_auto_alloc_size is non-zero, then the device-private space |
653 | is allocated for the device and zeroed. It will be accessible as | 653 | is allocated for the device and zeroed. It will be accessible as |
654 | dev->priv. The driver can put anything it likes in there, but should use | 654 | dev->priv. The driver can put anything it likes in there, but should use |
655 | it for run-time information, not platform data (which should be static | 655 | it for run-time information, not platform data (which should be static |
656 | and known before the device is probed). | 656 | and known before the device is probed). |
657 | 657 | ||
658 | b. If platdata_auto_alloc_size is non-zero, then the platform data space | 658 | b. If platdata_auto_alloc_size is non-zero, then the platform data space |
659 | is allocated. This is only useful for device tree operation, since | 659 | is allocated. This is only useful for device tree operation, since |
660 | otherwise you would have to specific the platform data in the | 660 | otherwise you would have to specific the platform data in the |
661 | U_BOOT_DEVICE() declaration. The space is allocated for the device and | 661 | U_BOOT_DEVICE() declaration. The space is allocated for the device and |
662 | zeroed. It will be accessible as dev->platdata. | 662 | zeroed. It will be accessible as dev->platdata. |
663 | 663 | ||
664 | c. If the device's uclass specifies a non-zero per_device_auto_alloc_size, | 664 | c. If the device's uclass specifies a non-zero per_device_auto_alloc_size, |
665 | then this space is allocated and zeroed also. It is allocated for and | 665 | then this space is allocated and zeroed also. It is allocated for and |
666 | stored in the device, but it is uclass data. owned by the uclass driver. | 666 | stored in the device, but it is uclass data. owned by the uclass driver. |
667 | It is possible for the device to access it. | 667 | It is possible for the device to access it. |
668 | 668 | ||
669 | d. If the device's immediate parent specifies a per_child_auto_alloc_size | 669 | d. If the device's immediate parent specifies a per_child_auto_alloc_size |
670 | then this space is allocated. This is intended for use by the parent | 670 | then this space is allocated. This is intended for use by the parent |
671 | device to keep track of things related to the child. For example a USB | 671 | device to keep track of things related to the child. For example a USB |
672 | flash stick attached to a USB host controller would likely use this | 672 | flash stick attached to a USB host controller would likely use this |
673 | space. The controller can hold information about the USB state of each | 673 | space. The controller can hold information about the USB state of each |
674 | of its children. | 674 | of its children. |
675 | 675 | ||
676 | e. All parent devices are probed. It is not possible to activate a device | 676 | e. All parent devices are probed. It is not possible to activate a device |
677 | unless its predecessors (all the way up to the root device) are activated. | 677 | unless its predecessors (all the way up to the root device) are activated. |
678 | This means (for example) that an I2C driver will require that its bus | 678 | This means (for example) that an I2C driver will require that its bus |
679 | be activated. | 679 | be activated. |
680 | 680 | ||
681 | f. The device's sequence number is assigned, either the requested one | 681 | f. The device's sequence number is assigned, either the requested one |
682 | (assuming no conflicts) or the next available one if there is a conflict | 682 | (assuming no conflicts) or the next available one if there is a conflict |
683 | or nothing particular is requested. | 683 | or nothing particular is requested. |
684 | 684 | ||
685 | g. If the driver provides an ofdata_to_platdata() method, then this is | 685 | g. If the driver provides an ofdata_to_platdata() method, then this is |
686 | called to convert the device tree data into platform data. This should | 686 | called to convert the device tree data into platform data. This should |
687 | do various calls like fdtdec_get_int(gd->fdt_blob, dev->of_offset, ...) | 687 | do various calls like fdtdec_get_int(gd->fdt_blob, dev->of_offset, ...) |
688 | to access the node and store the resulting information into dev->platdata. | 688 | to access the node and store the resulting information into dev->platdata. |
689 | After this point, the device works the same way whether it was bound | 689 | After this point, the device works the same way whether it was bound |
690 | using a device tree node or U_BOOT_DEVICE() structure. In either case, | 690 | using a device tree node or U_BOOT_DEVICE() structure. In either case, |
691 | the platform data is now stored in the platdata structure. Typically you | 691 | the platform data is now stored in the platdata structure. Typically you |
692 | will use the platdata_auto_alloc_size feature to specify the size of the | 692 | will use the platdata_auto_alloc_size feature to specify the size of the |
693 | platform data structure, and U-Boot will automatically allocate and zero | 693 | platform data structure, and U-Boot will automatically allocate and zero |
694 | it for you before entry to ofdata_to_platdata(). But if not, you can | 694 | it for you before entry to ofdata_to_platdata(). But if not, you can |
695 | allocate it yourself in ofdata_to_platdata(). Note that it is preferable | 695 | allocate it yourself in ofdata_to_platdata(). Note that it is preferable |
696 | to do all the device tree decoding in ofdata_to_platdata() rather than | 696 | to do all the device tree decoding in ofdata_to_platdata() rather than |
697 | in probe(). (Apart from the ugliness of mixing configuration and run-time | 697 | in probe(). (Apart from the ugliness of mixing configuration and run-time |
698 | data, one day it is possible that U-Boot will cache platformat data for | 698 | data, one day it is possible that U-Boot will cache platformat data for |
699 | devices which are regularly de/activated). | 699 | devices which are regularly de/activated). |
700 | 700 | ||
701 | h. The device's probe() method is called. This should do anything that | 701 | h. The device's probe() method is called. This should do anything that |
702 | is required by the device to get it going. This could include checking | 702 | is required by the device to get it going. This could include checking |
703 | that the hardware is actually present, setting up clocks for the | 703 | that the hardware is actually present, setting up clocks for the |
704 | hardware and setting up hardware registers to initial values. The code | 704 | hardware and setting up hardware registers to initial values. The code |
705 | in probe() can access: | 705 | in probe() can access: |
706 | 706 | ||
707 | - platform data in dev->platdata (for configuration) | 707 | - platform data in dev->platdata (for configuration) |
708 | - private data in dev->priv (for run-time state) | 708 | - private data in dev->priv (for run-time state) |
709 | - uclass data in dev->uclass_priv (for things the uclass stores | 709 | - uclass data in dev->uclass_priv (for things the uclass stores |
710 | about this device) | 710 | about this device) |
711 | 711 | ||
712 | Note: If you don't use priv_auto_alloc_size then you will need to | 712 | Note: If you don't use priv_auto_alloc_size then you will need to |
713 | allocate the priv space here yourself. The same applies also to | 713 | allocate the priv space here yourself. The same applies also to |
714 | platdata_auto_alloc_size. Remember to free them in the remove() method. | 714 | platdata_auto_alloc_size. Remember to free them in the remove() method. |
715 | 715 | ||
716 | i. The device is marked 'activated' | 716 | i. The device is marked 'activated' |
717 | 717 | ||
718 | j. The uclass's post_probe() method is called, if one exists. This may | 718 | j. The uclass's post_probe() method is called, if one exists. This may |
719 | cause the uclass to do some housekeeping to record the device as | 719 | cause the uclass to do some housekeeping to record the device as |
720 | activated and 'known' by the uclass. | 720 | activated and 'known' by the uclass. |
721 | 721 | ||
722 | 3. Running stage | 722 | 3. Running stage |
723 | 723 | ||
724 | The device is now activated and can be used. From now until it is removed | 724 | The device is now activated and can be used. From now until it is removed |
725 | all of the above structures are accessible. The device appears in the | 725 | all of the above structures are accessible. The device appears in the |
726 | uclass's list of devices (so if the device is in UCLASS_GPIO it will appear | 726 | uclass's list of devices (so if the device is in UCLASS_GPIO it will appear |
727 | as a device in the GPIO uclass). This is the 'running' state of the device. | 727 | as a device in the GPIO uclass). This is the 'running' state of the device. |
728 | 728 | ||
729 | 4. Removal stage | 729 | 4. Removal stage |
730 | 730 | ||
731 | When the device is no-longer required, you can call device_remove() to | 731 | When the device is no-longer required, you can call device_remove() to |
732 | remove it. This performs the probe steps in reverse: | 732 | remove it. This performs the probe steps in reverse: |
733 | 733 | ||
734 | a. The uclass's pre_remove() method is called, if one exists. This may | 734 | a. The uclass's pre_remove() method is called, if one exists. This may |
735 | cause the uclass to do some housekeeping to record the device as | 735 | cause the uclass to do some housekeeping to record the device as |
736 | deactivated and no-longer 'known' by the uclass. | 736 | deactivated and no-longer 'known' by the uclass. |
737 | 737 | ||
738 | b. All the device's children are removed. It is not permitted to have | 738 | b. All the device's children are removed. It is not permitted to have |
739 | an active child device with a non-active parent. This means that | 739 | an active child device with a non-active parent. This means that |
740 | device_remove() is called for all the children recursively at this point. | 740 | device_remove() is called for all the children recursively at this point. |
741 | 741 | ||
742 | c. The device's remove() method is called. At this stage nothing has been | 742 | c. The device's remove() method is called. At this stage nothing has been |
743 | deallocated so platform data, private data and the uclass data will all | 743 | deallocated so platform data, private data and the uclass data will all |
744 | still be present. This is where the hardware can be shut down. It is | 744 | still be present. This is where the hardware can be shut down. It is |
745 | intended that the device be completely inactive at this point, For U-Boot | 745 | intended that the device be completely inactive at this point, For U-Boot |
746 | to be sure that no hardware is running, it should be enough to remove | 746 | to be sure that no hardware is running, it should be enough to remove |
747 | all devices. | 747 | all devices. |
748 | 748 | ||
749 | d. The device memory is freed (platform data, private data, uclass data, | 749 | d. The device memory is freed (platform data, private data, uclass data, |
750 | parent data). | 750 | parent data). |
751 | 751 | ||
752 | Note: Because the platform data for a U_BOOT_DEVICE() is defined with a | 752 | Note: Because the platform data for a U_BOOT_DEVICE() is defined with a |
753 | static pointer, it is not de-allocated during the remove() method. For | 753 | static pointer, it is not de-allocated during the remove() method. For |
754 | a device instantiated using the device tree data, the platform data will | 754 | a device instantiated using the device tree data, the platform data will |
755 | be dynamically allocated, and thus needs to be deallocated during the | 755 | be dynamically allocated, and thus needs to be deallocated during the |
756 | remove() method, either: | 756 | remove() method, either: |
757 | 757 | ||
758 | 1. if the platdata_auto_alloc_size is non-zero, the deallocation | 758 | 1. if the platdata_auto_alloc_size is non-zero, the deallocation |
759 | happens automatically within the driver model core; or | 759 | happens automatically within the driver model core; or |
760 | 760 | ||
761 | 2. when platdata_auto_alloc_size is 0, both the allocation (in probe() | 761 | 2. when platdata_auto_alloc_size is 0, both the allocation (in probe() |
762 | or preferably ofdata_to_platdata()) and the deallocation in remove() | 762 | or preferably ofdata_to_platdata()) and the deallocation in remove() |
763 | are the responsibility of the driver author. | 763 | are the responsibility of the driver author. |
764 | 764 | ||
765 | e. The device sequence number is set to -1, meaning that it no longer | 765 | e. The device sequence number is set to -1, meaning that it no longer |
766 | has an allocated sequence. If the device is later reactivated and that | 766 | has an allocated sequence. If the device is later reactivated and that |
767 | sequence number is still free, it may well receive the name sequence | 767 | sequence number is still free, it may well receive the name sequence |
768 | number again. But from this point, the sequence number previously used | 768 | number again. But from this point, the sequence number previously used |
769 | by this device will no longer exist (think of SPI bus 2 being removed | 769 | by this device will no longer exist (think of SPI bus 2 being removed |
770 | and bus 2 is no longer available for use). | 770 | and bus 2 is no longer available for use). |
771 | 771 | ||
772 | f. The device is marked inactive. Note that it is still bound, so the | 772 | f. The device is marked inactive. Note that it is still bound, so the |
773 | device structure itself is not freed at this point. Should the device be | 773 | device structure itself is not freed at this point. Should the device be |
774 | activated again, then the cycle starts again at step 2 above. | 774 | activated again, then the cycle starts again at step 2 above. |
775 | 775 | ||
776 | 5. Unbind stage | 776 | 5. Unbind stage |
777 | 777 | ||
778 | The device is unbound. This is the step that actually destroys the device. | 778 | The device is unbound. This is the step that actually destroys the device. |
779 | If a parent has children these will be destroyed first. After this point | 779 | If a parent has children these will be destroyed first. After this point |
780 | the device does not exist and its memory has be deallocated. | 780 | the device does not exist and its memory has be deallocated. |
781 | 781 | ||
782 | 782 | ||
783 | Data Structures | 783 | Data Structures |
784 | --------------- | 784 | --------------- |
785 | 785 | ||
786 | Driver model uses a doubly-linked list as the basic data structure. Some | 786 | Driver model uses a doubly-linked list as the basic data structure. Some |
787 | nodes have several lists running through them. Creating a more efficient | 787 | nodes have several lists running through them. Creating a more efficient |
788 | data structure might be worthwhile in some rare cases, once we understand | 788 | data structure might be worthwhile in some rare cases, once we understand |
789 | what the bottlenecks are. | 789 | what the bottlenecks are. |
790 | 790 | ||
791 | 791 | ||
792 | Changes since v1 | 792 | Changes since v1 |
793 | ---------------- | 793 | ---------------- |
794 | 794 | ||
795 | For the record, this implementation uses a very similar approach to the | 795 | For the record, this implementation uses a very similar approach to the |
796 | original patches, but makes at least the following changes: | 796 | original patches, but makes at least the following changes: |
797 | 797 | ||
798 | - Tried to aggressively remove boilerplate, so that for most drivers there | 798 | - Tried to aggressively remove boilerplate, so that for most drivers there |
799 | is little or no 'driver model' code to write. | 799 | is little or no 'driver model' code to write. |
800 | - Moved some data from code into data structure - e.g. store a pointer to | 800 | - Moved some data from code into data structure - e.g. store a pointer to |
801 | the driver operations structure in the driver, rather than passing it | 801 | the driver operations structure in the driver, rather than passing it |
802 | to the driver bind function. | 802 | to the driver bind function. |
803 | - Rename some structures to make them more similar to Linux (struct udevice | 803 | - Rename some structures to make them more similar to Linux (struct udevice |
804 | instead of struct instance, struct platdata, etc.) | 804 | instead of struct instance, struct platdata, etc.) |
805 | - Change the name 'core' to 'uclass', meaning U-Boot class. It seems that | 805 | - Change the name 'core' to 'uclass', meaning U-Boot class. It seems that |
806 | this concept relates to a class of drivers (or a subsystem). We shouldn't | 806 | this concept relates to a class of drivers (or a subsystem). We shouldn't |
807 | use 'class' since it is a C++ reserved word, so U-Boot class (uclass) seems | 807 | use 'class' since it is a C++ reserved word, so U-Boot class (uclass) seems |
808 | better than 'core'. | 808 | better than 'core'. |
809 | - Remove 'struct driver_instance' and just use a single 'struct udevice'. | 809 | - Remove 'struct driver_instance' and just use a single 'struct udevice'. |
810 | This removes a level of indirection that doesn't seem necessary. | 810 | This removes a level of indirection that doesn't seem necessary. |
811 | - Built in device tree support, to avoid the need for platdata | 811 | - Built in device tree support, to avoid the need for platdata |
812 | - Removed the concept of driver relocation, and just make it possible for | 812 | - Removed the concept of driver relocation, and just make it possible for |
813 | the new driver (created after relocation) to access the old driver data. | 813 | the new driver (created after relocation) to access the old driver data. |
814 | I feel that relocation is a very special case and will only apply to a few | 814 | I feel that relocation is a very special case and will only apply to a few |
815 | drivers, many of which can/will just re-init anyway. So the overhead of | 815 | drivers, many of which can/will just re-init anyway. So the overhead of |
816 | dealing with this might not be worth it. | 816 | dealing with this might not be worth it. |
817 | - Implemented a GPIO system, trying to keep it simple | 817 | - Implemented a GPIO system, trying to keep it simple |
818 | 818 | ||
819 | 819 | ||
820 | Pre-Relocation Support | 820 | Pre-Relocation Support |
821 | ---------------------- | 821 | ---------------------- |
822 | 822 | ||
823 | For pre-relocation we simply call the driver model init function. Only | 823 | For pre-relocation we simply call the driver model init function. Only |
824 | drivers marked with DM_FLAG_PRE_RELOC or the device tree | 824 | drivers marked with DM_FLAG_PRE_RELOC or the device tree |
825 | 'u-boot,dm-pre-reloc' flag are initialised prior to relocation. This helps | 825 | 'u-boot,dm-pre-reloc' flag are initialised prior to relocation. This helps |
826 | to reduce the driver model overhead. | 826 | to reduce the driver model overhead. |
827 | 827 | ||
828 | It is possible to limit this to specific relocation steps, by using | ||
829 | the more specialized 'u-boot,dm-spl' and 'u-boot,dm-tpl' flags | ||
830 | in the devicetree. | ||
831 | |||
828 | Then post relocation we throw that away and re-init driver model again. | 832 | Then post relocation we throw that away and re-init driver model again. |
829 | For drivers which require some sort of continuity between pre- and | 833 | For drivers which require some sort of continuity between pre- and |
830 | post-relocation devices, we can provide access to the pre-relocation | 834 | post-relocation devices, we can provide access to the pre-relocation |
831 | device pointers, but this is not currently implemented (the root device | 835 | device pointers, but this is not currently implemented (the root device |
832 | pointer is saved but not made available through the driver model API). | 836 | pointer is saved but not made available through the driver model API). |
833 | 837 | ||
834 | 838 | ||
835 | SPL Support | 839 | SPL Support |
836 | ----------- | 840 | ----------- |
837 | 841 | ||
838 | Driver model can operate in SPL. Its efficient implementation and small code | 842 | Driver model can operate in SPL. Its efficient implementation and small code |
839 | size provide for a small overhead which is acceptable for all but the most | 843 | size provide for a small overhead which is acceptable for all but the most |
840 | constrained systems. | 844 | constrained systems. |
841 | 845 | ||
842 | To enable driver model in SPL, define CONFIG_SPL_DM. You might want to | 846 | To enable driver model in SPL, define CONFIG_SPL_DM. You might want to |
843 | consider the following option also. See the main README for more details. | 847 | consider the following option also. See the main README for more details. |
844 | 848 | ||
845 | - CONFIG_SYS_MALLOC_SIMPLE | 849 | - CONFIG_SYS_MALLOC_SIMPLE |
846 | - CONFIG_DM_WARN | 850 | - CONFIG_DM_WARN |
847 | - CONFIG_DM_DEVICE_REMOVE | 851 | - CONFIG_DM_DEVICE_REMOVE |
848 | - CONFIG_DM_STDIO | 852 | - CONFIG_DM_STDIO |
849 | 853 | ||
850 | 854 | ||
851 | Enabling Driver Model | 855 | Enabling Driver Model |
852 | --------------------- | 856 | --------------------- |
853 | 857 | ||
854 | Driver model is being brought into U-Boot gradually. As each subsystems gets | 858 | Driver model is being brought into U-Boot gradually. As each subsystems gets |
855 | support, a uclass is created and a CONFIG to enable use of driver model for | 859 | support, a uclass is created and a CONFIG to enable use of driver model for |
856 | that subsystem. | 860 | that subsystem. |
857 | 861 | ||
858 | For example CONFIG_DM_SERIAL enables driver model for serial. With that | 862 | For example CONFIG_DM_SERIAL enables driver model for serial. With that |
859 | defined, the old serial support is not enabled, and your serial driver must | 863 | defined, the old serial support is not enabled, and your serial driver must |
860 | conform to driver model. With that undefined, the old serial support is | 864 | conform to driver model. With that undefined, the old serial support is |
861 | enabled and driver model is not available for serial. This means that when | 865 | enabled and driver model is not available for serial. This means that when |
862 | you convert a driver, you must either convert all its boards, or provide for | 866 | you convert a driver, you must either convert all its boards, or provide for |
863 | the driver to be compiled both with and without driver model (generally this | 867 | the driver to be compiled both with and without driver model (generally this |
864 | is not very hard). | 868 | is not very hard). |
865 | 869 | ||
866 | See the main README for full details of the available driver model CONFIG | 870 | See the main README for full details of the available driver model CONFIG |
867 | options. | 871 | options. |
868 | 872 | ||
869 | 873 | ||
870 | Things to punt for later | 874 | Things to punt for later |
871 | ------------------------ | 875 | ------------------------ |
872 | 876 | ||
873 | Uclasses are statically numbered at compile time. It would be possible to | 877 | Uclasses are statically numbered at compile time. It would be possible to |
874 | change this to dynamic numbering, but then we would require some sort of | 878 | change this to dynamic numbering, but then we would require some sort of |
875 | lookup service, perhaps searching by name. This is slightly less efficient | 879 | lookup service, perhaps searching by name. This is slightly less efficient |
876 | so has been left out for now. One small advantage of dynamic numbering might | 880 | so has been left out for now. One small advantage of dynamic numbering might |
877 | be fewer merge conflicts in uclass-id.h. | 881 | be fewer merge conflicts in uclass-id.h. |
878 | 882 | ||
879 | 883 | ||
880 | Simon Glass | 884 | Simon Glass |
881 | sjg@chromium.org | 885 | sjg@chromium.org |
882 | April 2013 | 886 | April 2013 |
883 | Updated 7-May-13 | 887 | Updated 7-May-13 |
884 | Updated 14-Jun-13 | 888 | Updated 14-Jun-13 |
885 | Updated 18-Oct-13 | 889 | Updated 18-Oct-13 |
886 | Updated 5-Nov-13 | 890 | Updated 5-Nov-13 |
887 | 891 |
drivers/clk/at91/pmc.c
1 | /* | 1 | /* |
2 | * Copyright (C) 2016 Atmel Corporation | 2 | * Copyright (C) 2016 Atmel Corporation |
3 | * Wenyou.Yang <wenyou.yang@atmel.com> | 3 | * Wenyou.Yang <wenyou.yang@atmel.com> |
4 | * | 4 | * |
5 | * SPDX-License-Identifier: GPL-2.0+ | 5 | * SPDX-License-Identifier: GPL-2.0+ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <common.h> | 8 | #include <common.h> |
9 | #include <clk-uclass.h> | 9 | #include <clk-uclass.h> |
10 | #include <dm/device.h> | 10 | #include <dm/device.h> |
11 | #include <dm/lists.h> | 11 | #include <dm/lists.h> |
12 | #include <dm/root.h> | 12 | #include <dm/root.h> |
13 | #include <dm/util.h> | ||
13 | #include "pmc.h" | 14 | #include "pmc.h" |
14 | 15 | ||
15 | DECLARE_GLOBAL_DATA_PTR; | 16 | DECLARE_GLOBAL_DATA_PTR; |
16 | 17 | ||
17 | static const struct udevice_id at91_pmc_match[] = { | 18 | static const struct udevice_id at91_pmc_match[] = { |
18 | { .compatible = "atmel,sama5d2-pmc" }, | 19 | { .compatible = "atmel,sama5d2-pmc" }, |
19 | {} | 20 | {} |
20 | }; | 21 | }; |
21 | 22 | ||
22 | U_BOOT_DRIVER(at91_pmc) = { | 23 | U_BOOT_DRIVER(at91_pmc) = { |
23 | .name = "at91-pmc", | 24 | .name = "at91-pmc", |
24 | .id = UCLASS_SIMPLE_BUS, | 25 | .id = UCLASS_SIMPLE_BUS, |
25 | .of_match = at91_pmc_match, | 26 | .of_match = at91_pmc_match, |
26 | }; | 27 | }; |
27 | 28 | ||
28 | /*---------------------------------------------------------*/ | 29 | /*---------------------------------------------------------*/ |
29 | 30 | ||
30 | int at91_pmc_core_probe(struct udevice *dev) | 31 | int at91_pmc_core_probe(struct udevice *dev) |
31 | { | 32 | { |
32 | struct pmc_platdata *plat = dev_get_platdata(dev); | 33 | struct pmc_platdata *plat = dev_get_platdata(dev); |
33 | 34 | ||
34 | dev = dev_get_parent(dev); | 35 | dev = dev_get_parent(dev); |
35 | 36 | ||
36 | plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev); | 37 | plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev); |
37 | 38 | ||
38 | return 0; | 39 | return 0; |
39 | } | 40 | } |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * at91_clk_sub_device_bind() - for the at91 clock driver | 43 | * at91_clk_sub_device_bind() - for the at91 clock driver |
43 | * Recursively bind its children as clk devices. | 44 | * Recursively bind its children as clk devices. |
44 | * | 45 | * |
45 | * @return: 0 on success, or negative error code on failure | 46 | * @return: 0 on success, or negative error code on failure |
46 | */ | 47 | */ |
47 | int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name) | 48 | int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name) |
48 | { | 49 | { |
49 | const void *fdt = gd->fdt_blob; | 50 | const void *fdt = gd->fdt_blob; |
50 | int offset = dev->of_offset; | 51 | int offset = dev->of_offset; |
51 | bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); | 52 | bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); |
52 | const char *name; | 53 | const char *name; |
53 | int ret; | 54 | int ret; |
54 | 55 | ||
55 | for (offset = fdt_first_subnode(fdt, offset); | 56 | for (offset = fdt_first_subnode(fdt, offset); |
56 | offset > 0; | 57 | offset > 0; |
57 | offset = fdt_next_subnode(fdt, offset)) { | 58 | offset = fdt_next_subnode(fdt, offset)) { |
58 | if (pre_reloc_only && | 59 | if (pre_reloc_only && |
59 | !fdt_getprop(fdt, offset, "u-boot,dm-pre-reloc", NULL)) | 60 | !dm_fdt_pre_reloc(fdt, offset)) |
60 | continue; | 61 | continue; |
61 | /* | 62 | /* |
62 | * If this node has "compatible" property, this is not | 63 | * If this node has "compatible" property, this is not |
63 | * a clock sub-node, but a normal device. skip. | 64 | * a clock sub-node, but a normal device. skip. |
64 | */ | 65 | */ |
65 | fdt_get_property(fdt, offset, "compatible", &ret); | 66 | fdt_get_property(fdt, offset, "compatible", &ret); |
66 | if (ret >= 0) | 67 | if (ret >= 0) |
67 | continue; | 68 | continue; |
68 | 69 | ||
69 | if (ret != -FDT_ERR_NOTFOUND) | 70 | if (ret != -FDT_ERR_NOTFOUND) |
70 | return ret; | 71 | return ret; |
71 | 72 | ||
72 | name = fdt_get_name(fdt, offset, NULL); | 73 | name = fdt_get_name(fdt, offset, NULL); |
73 | if (!name) | 74 | if (!name) |
74 | return -EINVAL; | 75 | return -EINVAL; |
75 | ret = device_bind_driver_to_node(dev, drv_name, name, | 76 | ret = device_bind_driver_to_node(dev, drv_name, name, |
76 | offset, NULL); | 77 | offset, NULL); |
77 | if (ret) | 78 | if (ret) |
78 | return ret; | 79 | return ret; |
79 | } | 80 | } |
80 | 81 | ||
81 | return 0; | 82 | return 0; |
82 | } | 83 | } |
83 | 84 | ||
84 | int at91_clk_of_xlate(struct clk *clk, struct fdtdec_phandle_args *args) | 85 | int at91_clk_of_xlate(struct clk *clk, struct fdtdec_phandle_args *args) |
85 | { | 86 | { |
86 | int periph; | 87 | int periph; |
87 | 88 | ||
88 | if (args->args_count) { | 89 | if (args->args_count) { |
89 | debug("Invalid args_count: %d\n", args->args_count); | 90 | debug("Invalid args_count: %d\n", args->args_count); |
90 | return -EINVAL; | 91 | return -EINVAL; |
91 | } | 92 | } |
92 | 93 | ||
93 | periph = fdtdec_get_uint(gd->fdt_blob, clk->dev->of_offset, "reg", -1); | 94 | periph = fdtdec_get_uint(gd->fdt_blob, clk->dev->of_offset, "reg", -1); |
94 | if (periph < 0) | 95 | if (periph < 0) |
95 | return -EINVAL; | 96 | return -EINVAL; |
96 | 97 | ||
97 | clk->id = periph; | 98 | clk->id = periph; |
98 | 99 | ||
99 | return 0; | 100 | return 0; |
100 | } | 101 | } |
101 | 102 | ||
102 | int at91_clk_probe(struct udevice *dev) | 103 | int at91_clk_probe(struct udevice *dev) |
103 | { | 104 | { |
104 | struct udevice *dev_periph_container, *dev_pmc; | 105 | struct udevice *dev_periph_container, *dev_pmc; |
105 | struct pmc_platdata *plat = dev_get_platdata(dev); | 106 | struct pmc_platdata *plat = dev_get_platdata(dev); |
106 | 107 | ||
107 | dev_periph_container = dev_get_parent(dev); | 108 | dev_periph_container = dev_get_parent(dev); |
108 | dev_pmc = dev_get_parent(dev_periph_container); | 109 | dev_pmc = dev_get_parent(dev_periph_container); |
109 | 110 | ||
110 | plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev_pmc); | 111 | plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev_pmc); |
111 | 112 | ||
112 | return 0; | 113 | return 0; |
113 | } | 114 | } |
114 | 115 |
drivers/core/root.c
1 | /* | 1 | /* |
2 | * Copyright (c) 2013 Google, Inc | 2 | * Copyright (c) 2013 Google, Inc |
3 | * | 3 | * |
4 | * (C) Copyright 2012 | 4 | * (C) Copyright 2012 |
5 | * Pavel Herrmann <morpheus.ibis@gmail.com> | 5 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: GPL-2.0+ | 7 | * SPDX-License-Identifier: GPL-2.0+ |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <common.h> | 10 | #include <common.h> |
11 | #include <errno.h> | 11 | #include <errno.h> |
12 | #include <fdtdec.h> | 12 | #include <fdtdec.h> |
13 | #include <malloc.h> | 13 | #include <malloc.h> |
14 | #include <libfdt.h> | 14 | #include <libfdt.h> |
15 | #include <dm/device.h> | 15 | #include <dm/device.h> |
16 | #include <dm/device-internal.h> | 16 | #include <dm/device-internal.h> |
17 | #include <dm/lists.h> | 17 | #include <dm/lists.h> |
18 | #include <dm/platdata.h> | 18 | #include <dm/platdata.h> |
19 | #include <dm/root.h> | 19 | #include <dm/root.h> |
20 | #include <dm/uclass.h> | 20 | #include <dm/uclass.h> |
21 | #include <dm/util.h> | 21 | #include <dm/util.h> |
22 | #include <linux/list.h> | 22 | #include <linux/list.h> |
23 | 23 | ||
24 | DECLARE_GLOBAL_DATA_PTR; | 24 | DECLARE_GLOBAL_DATA_PTR; |
25 | 25 | ||
26 | struct root_priv { | 26 | struct root_priv { |
27 | fdt_addr_t translation_offset; /* optional translation offset */ | 27 | fdt_addr_t translation_offset; /* optional translation offset */ |
28 | }; | 28 | }; |
29 | 29 | ||
30 | static const struct driver_info root_info = { | 30 | static const struct driver_info root_info = { |
31 | .name = "root_driver", | 31 | .name = "root_driver", |
32 | }; | 32 | }; |
33 | 33 | ||
34 | struct udevice *dm_root(void) | 34 | struct udevice *dm_root(void) |
35 | { | 35 | { |
36 | if (!gd->dm_root) { | 36 | if (!gd->dm_root) { |
37 | dm_warn("Virtual root driver does not exist!\n"); | 37 | dm_warn("Virtual root driver does not exist!\n"); |
38 | return NULL; | 38 | return NULL; |
39 | } | 39 | } |
40 | 40 | ||
41 | return gd->dm_root; | 41 | return gd->dm_root; |
42 | } | 42 | } |
43 | 43 | ||
44 | void dm_fixup_for_gd_move(struct global_data *new_gd) | 44 | void dm_fixup_for_gd_move(struct global_data *new_gd) |
45 | { | 45 | { |
46 | /* The sentinel node has moved, so update things that point to it */ | 46 | /* The sentinel node has moved, so update things that point to it */ |
47 | if (gd->dm_root) { | 47 | if (gd->dm_root) { |
48 | new_gd->uclass_root.next->prev = &new_gd->uclass_root; | 48 | new_gd->uclass_root.next->prev = &new_gd->uclass_root; |
49 | new_gd->uclass_root.prev->next = &new_gd->uclass_root; | 49 | new_gd->uclass_root.prev->next = &new_gd->uclass_root; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | fdt_addr_t dm_get_translation_offset(void) | 53 | fdt_addr_t dm_get_translation_offset(void) |
54 | { | 54 | { |
55 | struct udevice *root = dm_root(); | 55 | struct udevice *root = dm_root(); |
56 | struct root_priv *priv = dev_get_priv(root); | 56 | struct root_priv *priv = dev_get_priv(root); |
57 | 57 | ||
58 | return priv->translation_offset; | 58 | return priv->translation_offset; |
59 | } | 59 | } |
60 | 60 | ||
61 | void dm_set_translation_offset(fdt_addr_t offs) | 61 | void dm_set_translation_offset(fdt_addr_t offs) |
62 | { | 62 | { |
63 | struct udevice *root = dm_root(); | 63 | struct udevice *root = dm_root(); |
64 | struct root_priv *priv = dev_get_priv(root); | 64 | struct root_priv *priv = dev_get_priv(root); |
65 | 65 | ||
66 | priv->translation_offset = offs; | 66 | priv->translation_offset = offs; |
67 | } | 67 | } |
68 | 68 | ||
69 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) | 69 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
70 | void fix_drivers(void) | 70 | void fix_drivers(void) |
71 | { | 71 | { |
72 | struct driver *drv = | 72 | struct driver *drv = |
73 | ll_entry_start(struct driver, driver); | 73 | ll_entry_start(struct driver, driver); |
74 | const int n_ents = ll_entry_count(struct driver, driver); | 74 | const int n_ents = ll_entry_count(struct driver, driver); |
75 | struct driver *entry; | 75 | struct driver *entry; |
76 | 76 | ||
77 | for (entry = drv; entry != drv + n_ents; entry++) { | 77 | for (entry = drv; entry != drv + n_ents; entry++) { |
78 | if (entry->of_match) | 78 | if (entry->of_match) |
79 | entry->of_match = (const struct udevice_id *) | 79 | entry->of_match = (const struct udevice_id *) |
80 | ((u32)entry->of_match + gd->reloc_off); | 80 | ((u32)entry->of_match + gd->reloc_off); |
81 | if (entry->bind) | 81 | if (entry->bind) |
82 | entry->bind += gd->reloc_off; | 82 | entry->bind += gd->reloc_off; |
83 | if (entry->probe) | 83 | if (entry->probe) |
84 | entry->probe += gd->reloc_off; | 84 | entry->probe += gd->reloc_off; |
85 | if (entry->remove) | 85 | if (entry->remove) |
86 | entry->remove += gd->reloc_off; | 86 | entry->remove += gd->reloc_off; |
87 | if (entry->unbind) | 87 | if (entry->unbind) |
88 | entry->unbind += gd->reloc_off; | 88 | entry->unbind += gd->reloc_off; |
89 | if (entry->ofdata_to_platdata) | 89 | if (entry->ofdata_to_platdata) |
90 | entry->ofdata_to_platdata += gd->reloc_off; | 90 | entry->ofdata_to_platdata += gd->reloc_off; |
91 | if (entry->child_post_bind) | 91 | if (entry->child_post_bind) |
92 | entry->child_post_bind += gd->reloc_off; | 92 | entry->child_post_bind += gd->reloc_off; |
93 | if (entry->child_pre_probe) | 93 | if (entry->child_pre_probe) |
94 | entry->child_pre_probe += gd->reloc_off; | 94 | entry->child_pre_probe += gd->reloc_off; |
95 | if (entry->child_post_remove) | 95 | if (entry->child_post_remove) |
96 | entry->child_post_remove += gd->reloc_off; | 96 | entry->child_post_remove += gd->reloc_off; |
97 | /* OPS are fixed in every uclass post_probe function */ | 97 | /* OPS are fixed in every uclass post_probe function */ |
98 | if (entry->ops) | 98 | if (entry->ops) |
99 | entry->ops += gd->reloc_off; | 99 | entry->ops += gd->reloc_off; |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | void fix_uclass(void) | 103 | void fix_uclass(void) |
104 | { | 104 | { |
105 | struct uclass_driver *uclass = | 105 | struct uclass_driver *uclass = |
106 | ll_entry_start(struct uclass_driver, uclass); | 106 | ll_entry_start(struct uclass_driver, uclass); |
107 | const int n_ents = ll_entry_count(struct uclass_driver, uclass); | 107 | const int n_ents = ll_entry_count(struct uclass_driver, uclass); |
108 | struct uclass_driver *entry; | 108 | struct uclass_driver *entry; |
109 | 109 | ||
110 | for (entry = uclass; entry != uclass + n_ents; entry++) { | 110 | for (entry = uclass; entry != uclass + n_ents; entry++) { |
111 | if (entry->post_bind) | 111 | if (entry->post_bind) |
112 | entry->post_bind += gd->reloc_off; | 112 | entry->post_bind += gd->reloc_off; |
113 | if (entry->pre_unbind) | 113 | if (entry->pre_unbind) |
114 | entry->pre_unbind += gd->reloc_off; | 114 | entry->pre_unbind += gd->reloc_off; |
115 | if (entry->pre_probe) | 115 | if (entry->pre_probe) |
116 | entry->pre_probe += gd->reloc_off; | 116 | entry->pre_probe += gd->reloc_off; |
117 | if (entry->post_probe) | 117 | if (entry->post_probe) |
118 | entry->post_probe += gd->reloc_off; | 118 | entry->post_probe += gd->reloc_off; |
119 | if (entry->pre_remove) | 119 | if (entry->pre_remove) |
120 | entry->pre_remove += gd->reloc_off; | 120 | entry->pre_remove += gd->reloc_off; |
121 | if (entry->child_post_bind) | 121 | if (entry->child_post_bind) |
122 | entry->child_post_bind += gd->reloc_off; | 122 | entry->child_post_bind += gd->reloc_off; |
123 | if (entry->child_pre_probe) | 123 | if (entry->child_pre_probe) |
124 | entry->child_pre_probe += gd->reloc_off; | 124 | entry->child_pre_probe += gd->reloc_off; |
125 | if (entry->init) | 125 | if (entry->init) |
126 | entry->init += gd->reloc_off; | 126 | entry->init += gd->reloc_off; |
127 | if (entry->destroy) | 127 | if (entry->destroy) |
128 | entry->destroy += gd->reloc_off; | 128 | entry->destroy += gd->reloc_off; |
129 | /* FIXME maybe also need to fix these ops */ | 129 | /* FIXME maybe also need to fix these ops */ |
130 | if (entry->ops) | 130 | if (entry->ops) |
131 | entry->ops += gd->reloc_off; | 131 | entry->ops += gd->reloc_off; |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | void fix_devices(void) | 135 | void fix_devices(void) |
136 | { | 136 | { |
137 | struct driver_info *dev = | 137 | struct driver_info *dev = |
138 | ll_entry_start(struct driver_info, driver_info); | 138 | ll_entry_start(struct driver_info, driver_info); |
139 | const int n_ents = ll_entry_count(struct driver_info, driver_info); | 139 | const int n_ents = ll_entry_count(struct driver_info, driver_info); |
140 | struct driver_info *entry; | 140 | struct driver_info *entry; |
141 | 141 | ||
142 | for (entry = dev; entry != dev + n_ents; entry++) { | 142 | for (entry = dev; entry != dev + n_ents; entry++) { |
143 | if (entry->platdata) | 143 | if (entry->platdata) |
144 | entry->platdata += gd->reloc_off; | 144 | entry->platdata += gd->reloc_off; |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | #endif | 148 | #endif |
149 | 149 | ||
150 | int dm_init(void) | 150 | int dm_init(void) |
151 | { | 151 | { |
152 | int ret; | 152 | int ret; |
153 | 153 | ||
154 | if (gd->dm_root) { | 154 | if (gd->dm_root) { |
155 | dm_warn("Virtual root driver already exists!\n"); | 155 | dm_warn("Virtual root driver already exists!\n"); |
156 | return -EINVAL; | 156 | return -EINVAL; |
157 | } | 157 | } |
158 | INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST); | 158 | INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST); |
159 | 159 | ||
160 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) | 160 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
161 | fix_drivers(); | 161 | fix_drivers(); |
162 | fix_uclass(); | 162 | fix_uclass(); |
163 | fix_devices(); | 163 | fix_devices(); |
164 | #endif | 164 | #endif |
165 | 165 | ||
166 | ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST); | 166 | ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST); |
167 | if (ret) | 167 | if (ret) |
168 | return ret; | 168 | return ret; |
169 | #if CONFIG_IS_ENABLED(OF_CONTROL) | 169 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
170 | DM_ROOT_NON_CONST->of_offset = 0; | 170 | DM_ROOT_NON_CONST->of_offset = 0; |
171 | #endif | 171 | #endif |
172 | ret = device_probe(DM_ROOT_NON_CONST); | 172 | ret = device_probe(DM_ROOT_NON_CONST); |
173 | if (ret) | 173 | if (ret) |
174 | return ret; | 174 | return ret; |
175 | 175 | ||
176 | return 0; | 176 | return 0; |
177 | } | 177 | } |
178 | 178 | ||
179 | int dm_uninit(void) | 179 | int dm_uninit(void) |
180 | { | 180 | { |
181 | device_remove(dm_root()); | 181 | device_remove(dm_root()); |
182 | device_unbind(dm_root()); | 182 | device_unbind(dm_root()); |
183 | 183 | ||
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | 186 | ||
187 | int dm_scan_platdata(bool pre_reloc_only) | 187 | int dm_scan_platdata(bool pre_reloc_only) |
188 | { | 188 | { |
189 | int ret; | 189 | int ret; |
190 | 190 | ||
191 | ret = lists_bind_drivers(DM_ROOT_NON_CONST, pre_reloc_only); | 191 | ret = lists_bind_drivers(DM_ROOT_NON_CONST, pre_reloc_only); |
192 | if (ret == -ENOENT) { | 192 | if (ret == -ENOENT) { |
193 | dm_warn("Some drivers were not found\n"); | 193 | dm_warn("Some drivers were not found\n"); |
194 | ret = 0; | 194 | ret = 0; |
195 | } | 195 | } |
196 | 196 | ||
197 | return ret; | 197 | return ret; |
198 | } | 198 | } |
199 | 199 | ||
200 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) | 200 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
201 | int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset, | 201 | int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset, |
202 | bool pre_reloc_only) | 202 | bool pre_reloc_only) |
203 | { | 203 | { |
204 | int ret = 0, err; | 204 | int ret = 0, err; |
205 | 205 | ||
206 | for (offset = fdt_first_subnode(blob, offset); | 206 | for (offset = fdt_first_subnode(blob, offset); |
207 | offset > 0; | 207 | offset > 0; |
208 | offset = fdt_next_subnode(blob, offset)) { | 208 | offset = fdt_next_subnode(blob, offset)) { |
209 | if (pre_reloc_only && | 209 | if (pre_reloc_only && |
210 | !fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL)) | 210 | !dm_fdt_pre_reloc(blob, offset)) |
211 | continue; | 211 | continue; |
212 | if (!fdtdec_get_is_enabled(blob, offset)) { | 212 | if (!fdtdec_get_is_enabled(blob, offset)) { |
213 | dm_dbg(" - ignoring disabled device\n"); | 213 | dm_dbg(" - ignoring disabled device\n"); |
214 | continue; | 214 | continue; |
215 | } | 215 | } |
216 | err = lists_bind_fdt(parent, blob, offset, NULL); | 216 | err = lists_bind_fdt(parent, blob, offset, NULL); |
217 | if (err && !ret) { | 217 | if (err && !ret) { |
218 | ret = err; | 218 | ret = err; |
219 | debug("%s: ret=%d\n", fdt_get_name(blob, offset, NULL), | 219 | debug("%s: ret=%d\n", fdt_get_name(blob, offset, NULL), |
220 | ret); | 220 | ret); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | 223 | ||
224 | if (ret) | 224 | if (ret) |
225 | dm_warn("Some drivers failed to bind\n"); | 225 | dm_warn("Some drivers failed to bind\n"); |
226 | 226 | ||
227 | return ret; | 227 | return ret; |
228 | } | 228 | } |
229 | 229 | ||
230 | int dm_scan_fdt_dev(struct udevice *dev) | 230 | int dm_scan_fdt_dev(struct udevice *dev) |
231 | { | 231 | { |
232 | if (dev->of_offset == -1) | 232 | if (dev->of_offset == -1) |
233 | return 0; | 233 | return 0; |
234 | 234 | ||
235 | return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, | 235 | return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, |
236 | gd->flags & GD_FLG_RELOC ? false : true); | 236 | gd->flags & GD_FLG_RELOC ? false : true); |
237 | } | 237 | } |
238 | 238 | ||
239 | int dm_scan_fdt(const void *blob, bool pre_reloc_only) | 239 | int dm_scan_fdt(const void *blob, bool pre_reloc_only) |
240 | { | 240 | { |
241 | return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only); | 241 | return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only); |
242 | } | 242 | } |
243 | #endif | 243 | #endif |
244 | 244 | ||
245 | __weak int dm_scan_other(bool pre_reloc_only) | 245 | __weak int dm_scan_other(bool pre_reloc_only) |
246 | { | 246 | { |
247 | return 0; | 247 | return 0; |
248 | } | 248 | } |
249 | 249 | ||
250 | int dm_init_and_scan(bool pre_reloc_only) | 250 | int dm_init_and_scan(bool pre_reloc_only) |
251 | { | 251 | { |
252 | int ret; | 252 | int ret; |
253 | 253 | ||
254 | ret = dm_init(); | 254 | ret = dm_init(); |
255 | if (ret) { | 255 | if (ret) { |
256 | debug("dm_init() failed: %d\n", ret); | 256 | debug("dm_init() failed: %d\n", ret); |
257 | return ret; | 257 | return ret; |
258 | } | 258 | } |
259 | ret = dm_scan_platdata(pre_reloc_only); | 259 | ret = dm_scan_platdata(pre_reloc_only); |
260 | if (ret) { | 260 | if (ret) { |
261 | debug("dm_scan_platdata() failed: %d\n", ret); | 261 | debug("dm_scan_platdata() failed: %d\n", ret); |
262 | return ret; | 262 | return ret; |
263 | } | 263 | } |
264 | 264 | ||
265 | if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { | 265 | if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { |
266 | ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only); | 266 | ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only); |
267 | if (ret) { | 267 | if (ret) { |
268 | debug("dm_scan_fdt() failed: %d\n", ret); | 268 | debug("dm_scan_fdt() failed: %d\n", ret); |
269 | return ret; | 269 | return ret; |
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ||
273 | ret = dm_scan_other(pre_reloc_only); | 273 | ret = dm_scan_other(pre_reloc_only); |
274 | if (ret) | 274 | if (ret) |
275 | return ret; | 275 | return ret; |
276 | 276 | ||
277 | return 0; | 277 | return 0; |
278 | } | 278 | } |
279 | 279 | ||
280 | /* This is the root driver - all drivers are children of this */ | 280 | /* This is the root driver - all drivers are children of this */ |
281 | U_BOOT_DRIVER(root_driver) = { | 281 | U_BOOT_DRIVER(root_driver) = { |
282 | .name = "root_driver", | 282 | .name = "root_driver", |
283 | .id = UCLASS_ROOT, | 283 | .id = UCLASS_ROOT, |
284 | .priv_auto_alloc_size = sizeof(struct root_priv), | 284 | .priv_auto_alloc_size = sizeof(struct root_priv), |
285 | }; | 285 | }; |
286 | 286 | ||
287 | /* This is the root uclass */ | 287 | /* This is the root uclass */ |
288 | UCLASS_DRIVER(root) = { | 288 | UCLASS_DRIVER(root) = { |
289 | .name = "root", | 289 | .name = "root", |
290 | .id = UCLASS_ROOT, | 290 | .id = UCLASS_ROOT, |
291 | }; | 291 | }; |
292 | 292 |
drivers/core/util.c
1 | /* | 1 | /* |
2 | * Copyright (c) 2013 Google, Inc | 2 | * Copyright (c) 2013 Google, Inc |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <common.h> | 7 | #include <common.h> |
8 | #include <libfdt.h> | ||
8 | #include <vsprintf.h> | 9 | #include <vsprintf.h> |
9 | 10 | ||
10 | void dm_warn(const char *fmt, ...) | 11 | void dm_warn(const char *fmt, ...) |
11 | { | 12 | { |
12 | va_list args; | 13 | va_list args; |
13 | 14 | ||
14 | va_start(args, fmt); | 15 | va_start(args, fmt); |
15 | vprintf(fmt, args); | 16 | vprintf(fmt, args); |
16 | va_end(args); | 17 | va_end(args); |
17 | } | 18 | } |
18 | 19 | ||
19 | void dm_dbg(const char *fmt, ...) | 20 | void dm_dbg(const char *fmt, ...) |
20 | { | 21 | { |
21 | va_list args; | 22 | va_list args; |
22 | 23 | ||
23 | va_start(args, fmt); | 24 | va_start(args, fmt); |
24 | vprintf(fmt, args); | 25 | vprintf(fmt, args); |
25 | va_end(args); | 26 | va_end(args); |
26 | } | 27 | } |
27 | 28 | ||
28 | int list_count_items(struct list_head *head) | 29 | int list_count_items(struct list_head *head) |
29 | { | 30 | { |
30 | struct list_head *node; | 31 | struct list_head *node; |
31 | int count = 0; | 32 | int count = 0; |
32 | 33 | ||
33 | list_for_each(node, head) | 34 | list_for_each(node, head) |
34 | count++; | 35 | count++; |
35 | 36 | ||
36 | return count; | 37 | return count; |
38 | } | ||
39 | |||
40 | int dm_fdt_pre_reloc(const void *blob, int offset) | ||
41 | { | ||
42 | if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL)) | ||
43 | return 1; | ||
44 | |||
45 | #ifdef CONFIG_TPL_BUILD | ||
46 | if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL)) | ||
47 | return 1; | ||
48 | #elif defined(CONFIG_SPL_BUILD) | ||
49 | if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL)) | ||
50 | return 1; | ||
51 | #else | ||
52 | /* | ||
53 | * In regular builds individual spl and tpl handling both | ||
54 | * count as handled pre-relocation for later second init. | ||
55 | */ | ||
56 | if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL) || | ||
57 | fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL)) | ||
58 | return 1; | ||
59 | #endif | ||
60 | |||
61 | return 0; | ||
37 | } | 62 | } |
38 | 63 |
drivers/pinctrl/pinctrl-uclass.c
1 | /* | 1 | /* |
2 | * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> | 2 | * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <common.h> | 7 | #include <common.h> |
8 | #include <libfdt.h> | 8 | #include <libfdt.h> |
9 | #include <linux/err.h> | 9 | #include <linux/err.h> |
10 | #include <linux/list.h> | 10 | #include <linux/list.h> |
11 | #include <dm/device.h> | 11 | #include <dm/device.h> |
12 | #include <dm/lists.h> | 12 | #include <dm/lists.h> |
13 | #include <dm/pinctrl.h> | 13 | #include <dm/pinctrl.h> |
14 | #include <dm/uclass.h> | 14 | #include <dm/uclass.h> |
15 | #include <dm/util.h> | ||
15 | 16 | ||
16 | DECLARE_GLOBAL_DATA_PTR; | 17 | DECLARE_GLOBAL_DATA_PTR; |
17 | 18 | ||
18 | int pinctrl_decode_pin_config(const void *blob, int node) | 19 | int pinctrl_decode_pin_config(const void *blob, int node) |
19 | { | 20 | { |
20 | int flags = 0; | 21 | int flags = 0; |
21 | 22 | ||
22 | if (fdtdec_get_bool(blob, node, "bias-pull-up")) | 23 | if (fdtdec_get_bool(blob, node, "bias-pull-up")) |
23 | flags |= 1 << PIN_CONFIG_BIAS_PULL_UP; | 24 | flags |= 1 << PIN_CONFIG_BIAS_PULL_UP; |
24 | else if (fdtdec_get_bool(blob, node, "bias-pull-down")) | 25 | else if (fdtdec_get_bool(blob, node, "bias-pull-down")) |
25 | flags |= 1 << PIN_CONFIG_BIAS_PULL_DOWN; | 26 | flags |= 1 << PIN_CONFIG_BIAS_PULL_DOWN; |
26 | 27 | ||
27 | return flags; | 28 | return flags; |
28 | } | 29 | } |
29 | 30 | ||
30 | #if CONFIG_IS_ENABLED(PINCTRL_FULL) | 31 | #if CONFIG_IS_ENABLED(PINCTRL_FULL) |
31 | /** | 32 | /** |
32 | * pinctrl_config_one() - apply pinctrl settings for a single node | 33 | * pinctrl_config_one() - apply pinctrl settings for a single node |
33 | * | 34 | * |
34 | * @config: pin configuration node | 35 | * @config: pin configuration node |
35 | * @return: 0 on success, or negative error code on failure | 36 | * @return: 0 on success, or negative error code on failure |
36 | */ | 37 | */ |
37 | static int pinctrl_config_one(struct udevice *config) | 38 | static int pinctrl_config_one(struct udevice *config) |
38 | { | 39 | { |
39 | struct udevice *pctldev; | 40 | struct udevice *pctldev; |
40 | const struct pinctrl_ops *ops; | 41 | const struct pinctrl_ops *ops; |
41 | 42 | ||
42 | pctldev = config; | 43 | pctldev = config; |
43 | for (;;) { | 44 | for (;;) { |
44 | pctldev = dev_get_parent(pctldev); | 45 | pctldev = dev_get_parent(pctldev); |
45 | if (!pctldev) { | 46 | if (!pctldev) { |
46 | dev_err(config, "could not find pctldev\n"); | 47 | dev_err(config, "could not find pctldev\n"); |
47 | return -EINVAL; | 48 | return -EINVAL; |
48 | } | 49 | } |
49 | if (pctldev->uclass->uc_drv->id == UCLASS_PINCTRL) | 50 | if (pctldev->uclass->uc_drv->id == UCLASS_PINCTRL) |
50 | break; | 51 | break; |
51 | } | 52 | } |
52 | 53 | ||
53 | ops = pinctrl_get_ops(pctldev); | 54 | ops = pinctrl_get_ops(pctldev); |
54 | return ops->set_state(pctldev, config); | 55 | return ops->set_state(pctldev, config); |
55 | } | 56 | } |
56 | 57 | ||
57 | /** | 58 | /** |
58 | * pinctrl_select_state_full() - full implementation of pinctrl_select_state | 59 | * pinctrl_select_state_full() - full implementation of pinctrl_select_state |
59 | * | 60 | * |
60 | * @dev: peripheral device | 61 | * @dev: peripheral device |
61 | * @statename: state name, like "default" | 62 | * @statename: state name, like "default" |
62 | * @return: 0 on success, or negative error code on failure | 63 | * @return: 0 on success, or negative error code on failure |
63 | */ | 64 | */ |
64 | static int pinctrl_select_state_full(struct udevice *dev, const char *statename) | 65 | static int pinctrl_select_state_full(struct udevice *dev, const char *statename) |
65 | { | 66 | { |
66 | const void *fdt = gd->fdt_blob; | 67 | const void *fdt = gd->fdt_blob; |
67 | int node = dev->of_offset; | 68 | int node = dev->of_offset; |
68 | char propname[32]; /* long enough */ | 69 | char propname[32]; /* long enough */ |
69 | const fdt32_t *list; | 70 | const fdt32_t *list; |
70 | uint32_t phandle; | 71 | uint32_t phandle; |
71 | int config_node; | 72 | int config_node; |
72 | struct udevice *config; | 73 | struct udevice *config; |
73 | int state, size, i, ret; | 74 | int state, size, i, ret; |
74 | 75 | ||
75 | state = fdt_stringlist_search(fdt, node, "pinctrl-names", statename); | 76 | state = fdt_stringlist_search(fdt, node, "pinctrl-names", statename); |
76 | if (state < 0) { | 77 | if (state < 0) { |
77 | char *end; | 78 | char *end; |
78 | /* | 79 | /* |
79 | * If statename is not found in "pinctrl-names", | 80 | * If statename is not found in "pinctrl-names", |
80 | * assume statename is just the integer state ID. | 81 | * assume statename is just the integer state ID. |
81 | */ | 82 | */ |
82 | state = simple_strtoul(statename, &end, 10); | 83 | state = simple_strtoul(statename, &end, 10); |
83 | if (*end) | 84 | if (*end) |
84 | return -EINVAL; | 85 | return -EINVAL; |
85 | } | 86 | } |
86 | 87 | ||
87 | snprintf(propname, sizeof(propname), "pinctrl-%d", state); | 88 | snprintf(propname, sizeof(propname), "pinctrl-%d", state); |
88 | list = fdt_getprop(fdt, node, propname, &size); | 89 | list = fdt_getprop(fdt, node, propname, &size); |
89 | if (!list) | 90 | if (!list) |
90 | return -EINVAL; | 91 | return -EINVAL; |
91 | 92 | ||
92 | size /= sizeof(*list); | 93 | size /= sizeof(*list); |
93 | for (i = 0; i < size; i++) { | 94 | for (i = 0; i < size; i++) { |
94 | phandle = fdt32_to_cpu(*list++); | 95 | phandle = fdt32_to_cpu(*list++); |
95 | 96 | ||
96 | config_node = fdt_node_offset_by_phandle(fdt, phandle); | 97 | config_node = fdt_node_offset_by_phandle(fdt, phandle); |
97 | if (config_node < 0) { | 98 | if (config_node < 0) { |
98 | dev_err(dev, "prop %s index %d invalid phandle\n", | 99 | dev_err(dev, "prop %s index %d invalid phandle\n", |
99 | propname, i); | 100 | propname, i); |
100 | return -EINVAL; | 101 | return -EINVAL; |
101 | } | 102 | } |
102 | ret = uclass_get_device_by_of_offset(UCLASS_PINCONFIG, | 103 | ret = uclass_get_device_by_of_offset(UCLASS_PINCONFIG, |
103 | config_node, &config); | 104 | config_node, &config); |
104 | if (ret) | 105 | if (ret) |
105 | return ret; | 106 | return ret; |
106 | 107 | ||
107 | ret = pinctrl_config_one(config); | 108 | ret = pinctrl_config_one(config); |
108 | if (ret) | 109 | if (ret) |
109 | return ret; | 110 | return ret; |
110 | } | 111 | } |
111 | 112 | ||
112 | return 0; | 113 | return 0; |
113 | } | 114 | } |
114 | 115 | ||
115 | /** | 116 | /** |
116 | * pinconfig_post_bind() - post binding for PINCONFIG uclass | 117 | * pinconfig_post_bind() - post binding for PINCONFIG uclass |
117 | * Recursively bind its children as pinconfig devices. | 118 | * Recursively bind its children as pinconfig devices. |
118 | * | 119 | * |
119 | * @dev: pinconfig device | 120 | * @dev: pinconfig device |
120 | * @return: 0 on success, or negative error code on failure | 121 | * @return: 0 on success, or negative error code on failure |
121 | */ | 122 | */ |
122 | static int pinconfig_post_bind(struct udevice *dev) | 123 | static int pinconfig_post_bind(struct udevice *dev) |
123 | { | 124 | { |
124 | const void *fdt = gd->fdt_blob; | 125 | const void *fdt = gd->fdt_blob; |
125 | int offset = dev->of_offset; | 126 | int offset = dev->of_offset; |
126 | bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); | 127 | bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); |
127 | const char *name; | 128 | const char *name; |
128 | int ret; | 129 | int ret; |
129 | 130 | ||
130 | for (offset = fdt_first_subnode(fdt, offset); | 131 | for (offset = fdt_first_subnode(fdt, offset); |
131 | offset > 0; | 132 | offset > 0; |
132 | offset = fdt_next_subnode(fdt, offset)) { | 133 | offset = fdt_next_subnode(fdt, offset)) { |
133 | if (pre_reloc_only && | 134 | if (pre_reloc_only && |
134 | !fdt_getprop(fdt, offset, "u-boot,dm-pre-reloc", NULL)) | 135 | !dm_fdt_pre_reloc(fdt, offset)) |
135 | continue; | 136 | continue; |
136 | /* | 137 | /* |
137 | * If this node has "compatible" property, this is not | 138 | * If this node has "compatible" property, this is not |
138 | * a pin configuration node, but a normal device. skip. | 139 | * a pin configuration node, but a normal device. skip. |
139 | */ | 140 | */ |
140 | fdt_get_property(fdt, offset, "compatible", &ret); | 141 | fdt_get_property(fdt, offset, "compatible", &ret); |
141 | if (ret >= 0) | 142 | if (ret >= 0) |
142 | continue; | 143 | continue; |
143 | 144 | ||
144 | if (ret != -FDT_ERR_NOTFOUND) | 145 | if (ret != -FDT_ERR_NOTFOUND) |
145 | return ret; | 146 | return ret; |
146 | 147 | ||
147 | name = fdt_get_name(fdt, offset, NULL); | 148 | name = fdt_get_name(fdt, offset, NULL); |
148 | if (!name) | 149 | if (!name) |
149 | return -EINVAL; | 150 | return -EINVAL; |
150 | ret = device_bind_driver_to_node(dev, "pinconfig", name, | 151 | ret = device_bind_driver_to_node(dev, "pinconfig", name, |
151 | offset, NULL); | 152 | offset, NULL); |
152 | if (ret) | 153 | if (ret) |
153 | return ret; | 154 | return ret; |
154 | } | 155 | } |
155 | 156 | ||
156 | return 0; | 157 | return 0; |
157 | } | 158 | } |
158 | 159 | ||
159 | UCLASS_DRIVER(pinconfig) = { | 160 | UCLASS_DRIVER(pinconfig) = { |
160 | .id = UCLASS_PINCONFIG, | 161 | .id = UCLASS_PINCONFIG, |
161 | .post_bind = pinconfig_post_bind, | 162 | .post_bind = pinconfig_post_bind, |
162 | .name = "pinconfig", | 163 | .name = "pinconfig", |
163 | }; | 164 | }; |
164 | 165 | ||
165 | U_BOOT_DRIVER(pinconfig_generic) = { | 166 | U_BOOT_DRIVER(pinconfig_generic) = { |
166 | .name = "pinconfig", | 167 | .name = "pinconfig", |
167 | .id = UCLASS_PINCONFIG, | 168 | .id = UCLASS_PINCONFIG, |
168 | }; | 169 | }; |
169 | 170 | ||
170 | #else | 171 | #else |
171 | static int pinctrl_select_state_full(struct udevice *dev, const char *statename) | 172 | static int pinctrl_select_state_full(struct udevice *dev, const char *statename) |
172 | { | 173 | { |
173 | return -ENODEV; | 174 | return -ENODEV; |
174 | } | 175 | } |
175 | 176 | ||
176 | static int pinconfig_post_bind(struct udevice *dev) | 177 | static int pinconfig_post_bind(struct udevice *dev) |
177 | { | 178 | { |
178 | return 0; | 179 | return 0; |
179 | } | 180 | } |
180 | #endif | 181 | #endif |
181 | 182 | ||
182 | /** | 183 | /** |
183 | * pinctrl_select_state_simple() - simple implementation of pinctrl_select_state | 184 | * pinctrl_select_state_simple() - simple implementation of pinctrl_select_state |
184 | * | 185 | * |
185 | * @dev: peripheral device | 186 | * @dev: peripheral device |
186 | * @return: 0 on success, or negative error code on failure | 187 | * @return: 0 on success, or negative error code on failure |
187 | */ | 188 | */ |
188 | static int pinctrl_select_state_simple(struct udevice *dev) | 189 | static int pinctrl_select_state_simple(struct udevice *dev) |
189 | { | 190 | { |
190 | struct udevice *pctldev; | 191 | struct udevice *pctldev; |
191 | struct pinctrl_ops *ops; | 192 | struct pinctrl_ops *ops; |
192 | int ret; | 193 | int ret; |
193 | 194 | ||
194 | /* | 195 | /* |
195 | * For simplicity, assume the first device of PINCTRL uclass | 196 | * For simplicity, assume the first device of PINCTRL uclass |
196 | * is the correct one. This is most likely OK as there is | 197 | * is the correct one. This is most likely OK as there is |
197 | * usually only one pinctrl device on the system. | 198 | * usually only one pinctrl device on the system. |
198 | */ | 199 | */ |
199 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev); | 200 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev); |
200 | if (ret) | 201 | if (ret) |
201 | return ret; | 202 | return ret; |
202 | 203 | ||
203 | ops = pinctrl_get_ops(pctldev); | 204 | ops = pinctrl_get_ops(pctldev); |
204 | if (!ops->set_state_simple) { | 205 | if (!ops->set_state_simple) { |
205 | dev_dbg(dev, "set_state_simple op missing\n"); | 206 | dev_dbg(dev, "set_state_simple op missing\n"); |
206 | return -ENOSYS; | 207 | return -ENOSYS; |
207 | } | 208 | } |
208 | 209 | ||
209 | return ops->set_state_simple(pctldev, dev); | 210 | return ops->set_state_simple(pctldev, dev); |
210 | } | 211 | } |
211 | 212 | ||
212 | int pinctrl_select_state(struct udevice *dev, const char *statename) | 213 | int pinctrl_select_state(struct udevice *dev, const char *statename) |
213 | { | 214 | { |
214 | /* | 215 | /* |
215 | * Try full-implemented pinctrl first. | 216 | * Try full-implemented pinctrl first. |
216 | * If it fails or is not implemented, try simple one. | 217 | * If it fails or is not implemented, try simple one. |
217 | */ | 218 | */ |
218 | if (pinctrl_select_state_full(dev, statename)) | 219 | if (pinctrl_select_state_full(dev, statename)) |
219 | return pinctrl_select_state_simple(dev); | 220 | return pinctrl_select_state_simple(dev); |
220 | 221 | ||
221 | return 0; | 222 | return 0; |
222 | } | 223 | } |
223 | 224 | ||
224 | int pinctrl_request(struct udevice *dev, int func, int flags) | 225 | int pinctrl_request(struct udevice *dev, int func, int flags) |
225 | { | 226 | { |
226 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); | 227 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
227 | 228 | ||
228 | if (!ops->request) | 229 | if (!ops->request) |
229 | return -ENOSYS; | 230 | return -ENOSYS; |
230 | 231 | ||
231 | return ops->request(dev, func, flags); | 232 | return ops->request(dev, func, flags); |
232 | } | 233 | } |
233 | 234 | ||
234 | int pinctrl_request_noflags(struct udevice *dev, int func) | 235 | int pinctrl_request_noflags(struct udevice *dev, int func) |
235 | { | 236 | { |
236 | return pinctrl_request(dev, func, 0); | 237 | return pinctrl_request(dev, func, 0); |
237 | } | 238 | } |
238 | 239 | ||
239 | int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph) | 240 | int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph) |
240 | { | 241 | { |
241 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); | 242 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
242 | 243 | ||
243 | if (!ops->get_periph_id) | 244 | if (!ops->get_periph_id) |
244 | return -ENOSYS; | 245 | return -ENOSYS; |
245 | 246 | ||
246 | return ops->get_periph_id(dev, periph); | 247 | return ops->get_periph_id(dev, periph); |
247 | } | 248 | } |
248 | 249 | ||
249 | int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index) | 250 | int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index) |
250 | { | 251 | { |
251 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); | 252 | struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
252 | 253 | ||
253 | if (!ops->get_gpio_mux) | 254 | if (!ops->get_gpio_mux) |
254 | return -ENOSYS; | 255 | return -ENOSYS; |
255 | 256 | ||
256 | return ops->get_gpio_mux(dev, banknum, index); | 257 | return ops->get_gpio_mux(dev, banknum, index); |
257 | } | 258 | } |
258 | 259 | ||
259 | /** | 260 | /** |
260 | * pinconfig_post_bind() - post binding for PINCTRL uclass | 261 | * pinconfig_post_bind() - post binding for PINCTRL uclass |
261 | * Recursively bind child nodes as pinconfig devices in case of full pinctrl. | 262 | * Recursively bind child nodes as pinconfig devices in case of full pinctrl. |
262 | * | 263 | * |
263 | * @dev: pinctrl device | 264 | * @dev: pinctrl device |
264 | * @return: 0 on success, or negative error code on failure | 265 | * @return: 0 on success, or negative error code on failure |
265 | */ | 266 | */ |
266 | static int pinctrl_post_bind(struct udevice *dev) | 267 | static int pinctrl_post_bind(struct udevice *dev) |
267 | { | 268 | { |
268 | const struct pinctrl_ops *ops = pinctrl_get_ops(dev); | 269 | const struct pinctrl_ops *ops = pinctrl_get_ops(dev); |
269 | 270 | ||
270 | if (!ops) { | 271 | if (!ops) { |
271 | dev_dbg(dev, "ops is not set. Do not bind.\n"); | 272 | dev_dbg(dev, "ops is not set. Do not bind.\n"); |
272 | return -EINVAL; | 273 | return -EINVAL; |
273 | } | 274 | } |
274 | 275 | ||
275 | /* | 276 | /* |
276 | * If set_state callback is set, we assume this pinctrl driver is the | 277 | * If set_state callback is set, we assume this pinctrl driver is the |
277 | * full implementation. In this case, its child nodes should be bound | 278 | * full implementation. In this case, its child nodes should be bound |
278 | * so that peripheral devices can easily search in parent devices | 279 | * so that peripheral devices can easily search in parent devices |
279 | * during later DT-parsing. | 280 | * during later DT-parsing. |
280 | */ | 281 | */ |
281 | if (ops->set_state) | 282 | if (ops->set_state) |
282 | return pinconfig_post_bind(dev); | 283 | return pinconfig_post_bind(dev); |
283 | 284 | ||
284 | return 0; | 285 | return 0; |
285 | } | 286 | } |
286 | 287 | ||
287 | UCLASS_DRIVER(pinctrl) = { | 288 | UCLASS_DRIVER(pinctrl) = { |
288 | .id = UCLASS_PINCTRL, | 289 | .id = UCLASS_PINCTRL, |
289 | .post_bind = pinctrl_post_bind, | 290 | .post_bind = pinctrl_post_bind, |
290 | .flags = DM_UC_FLAG_SEQ_ALIAS, | 291 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
291 | .name = "pinctrl", | 292 | .name = "pinctrl", |
292 | }; | 293 | }; |
293 | 294 |
include/dm/util.h
1 | /* | 1 | /* |
2 | * Copyright (c) 2013 Google, Inc | 2 | * Copyright (c) 2013 Google, Inc |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef __DM_UTIL_H | 7 | #ifndef __DM_UTIL_H |
8 | #define __DM_UTIL_H | 8 | #define __DM_UTIL_H |
9 | 9 | ||
10 | #ifdef CONFIG_DM_WARN | 10 | #ifdef CONFIG_DM_WARN |
11 | void dm_warn(const char *fmt, ...); | 11 | void dm_warn(const char *fmt, ...); |
12 | #else | 12 | #else |
13 | static inline void dm_warn(const char *fmt, ...) | 13 | static inline void dm_warn(const char *fmt, ...) |
14 | { | 14 | { |
15 | } | 15 | } |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | #ifdef DEBUG | 18 | #ifdef DEBUG |
19 | void dm_dbg(const char *fmt, ...); | 19 | void dm_dbg(const char *fmt, ...); |
20 | #else | 20 | #else |
21 | static inline void dm_dbg(const char *fmt, ...) | 21 | static inline void dm_dbg(const char *fmt, ...) |
22 | { | 22 | { |
23 | } | 23 | } |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | struct list_head; | 26 | struct list_head; |
27 | 27 | ||
28 | /** | 28 | /** |
29 | * list_count_items() - Count number of items in a list | 29 | * list_count_items() - Count number of items in a list |
30 | * | 30 | * |
31 | * @param head: Head of list | 31 | * @param head: Head of list |
32 | * @return number of items, or 0 if empty | 32 | * @return number of items, or 0 if empty |
33 | */ | 33 | */ |
34 | int list_count_items(struct list_head *head); | 34 | int list_count_items(struct list_head *head); |
35 | 35 | ||
36 | /* Dump out a tree of all devices */ | 36 | /* Dump out a tree of all devices */ |
37 | void dm_dump_all(void); | 37 | void dm_dump_all(void); |
38 | 38 | ||
39 | /* Dump out a list of uclasses and their devices */ | 39 | /* Dump out a list of uclasses and their devices */ |
40 | void dm_dump_uclass(void); | 40 | void dm_dump_uclass(void); |
41 | 41 | ||
42 | #ifdef CONFIG_DEBUG_DEVRES | 42 | #ifdef CONFIG_DEBUG_DEVRES |
43 | /* Dump out a list of device resources */ | 43 | /* Dump out a list of device resources */ |
44 | void dm_dump_devres(void); | 44 | void dm_dump_devres(void); |
45 | #else | 45 | #else |
46 | static inline void dm_dump_devres(void) | 46 | static inline void dm_dump_devres(void) |
47 | { | 47 | { |
48 | } | 48 | } |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | /** | ||
52 | * Check if a dt node should be or was bound before relocation. | ||
53 | * | ||
54 | * Devicetree nodes can be marked as needed to be bound | ||
55 | * in the loader stages via special devicetree properties. | ||
56 | * | ||
57 | * Before relocation this function can be used to check if nodes | ||
58 | * are required in either SPL or TPL stages. | ||
59 | * | ||
60 | * After relocation and jumping into the real U-Boot binary | ||
61 | * it is possible to determine if a node was bound in one of | ||
62 | * SPL/TPL stages. | ||
63 | * | ||
64 | * There are 3 settings currently in use | ||
65 | * - | ||
66 | * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL | ||
67 | * Existing platforms only use it to indicate nodes needee in | ||
68 | * SPL. Should probably be replaced by u-boot,dm-spl for | ||
69 | * existing platforms. | ||
70 | * @blob: devicetree | ||
71 | * @offset: node offset | ||
72 | * | ||
73 | * Returns true if node is needed in SPL/TL, false otherwise. | ||
74 | */ | ||
75 | int dm_fdt_pre_reloc(const void *blob, int offset); | ||
76 | |||
51 | #endif | 77 | #endif |
52 | 78 |
scripts/Makefile.spl
1 | # | 1 | # |
2 | # (C) Copyright 2000-2011 | 2 | # (C) Copyright 2000-2011 |
3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. | 3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | # | 4 | # |
5 | # (C) Copyright 2011 | 5 | # (C) Copyright 2011 |
6 | # Daniel Schwierzeck, daniel.schwierzeck@googlemail.com. | 6 | # Daniel Schwierzeck, daniel.schwierzeck@googlemail.com. |
7 | # | 7 | # |
8 | # (C) Copyright 2011 | 8 | # (C) Copyright 2011 |
9 | # Texas Instruments Incorporated - http://www.ti.com/ | 9 | # Texas Instruments Incorporated - http://www.ti.com/ |
10 | # Aneesh V <aneesh@ti.com> | 10 | # Aneesh V <aneesh@ti.com> |
11 | # | 11 | # |
12 | # SPDX-License-Identifier: GPL-2.0+ | 12 | # SPDX-License-Identifier: GPL-2.0+ |
13 | # | 13 | # |
14 | # Based on top-level Makefile. | 14 | # Based on top-level Makefile. |
15 | # | 15 | # |
16 | 16 | ||
17 | src := $(obj) | 17 | src := $(obj) |
18 | 18 | ||
19 | # Create output directory if not already present | 19 | # Create output directory if not already present |
20 | _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) | 20 | _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) |
21 | 21 | ||
22 | include $(srctree)/scripts/Kbuild.include | 22 | include $(srctree)/scripts/Kbuild.include |
23 | 23 | ||
24 | -include include/config/auto.conf | 24 | -include include/config/auto.conf |
25 | -include $(obj)/include/autoconf.mk | 25 | -include $(obj)/include/autoconf.mk |
26 | 26 | ||
27 | KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD | 27 | KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD |
28 | ifeq ($(CONFIG_TPL_BUILD),y) | 28 | ifeq ($(CONFIG_TPL_BUILD),y) |
29 | KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD | 29 | KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD |
30 | endif | 30 | endif |
31 | 31 | ||
32 | ifeq ($(CONFIG_TPL_BUILD),y) | 32 | ifeq ($(CONFIG_TPL_BUILD),y) |
33 | SPL_BIN := u-boot-tpl | 33 | SPL_BIN := u-boot-tpl |
34 | else | 34 | else |
35 | SPL_BIN := u-boot-spl | 35 | SPL_BIN := u-boot-spl |
36 | endif | 36 | endif |
37 | 37 | ||
38 | include $(srctree)/config.mk | 38 | include $(srctree)/config.mk |
39 | include $(srctree)/arch/$(ARCH)/Makefile | 39 | include $(srctree)/arch/$(ARCH)/Makefile |
40 | 40 | ||
41 | # Enable garbage collection of un-used sections for SPL | 41 | # Enable garbage collection of un-used sections for SPL |
42 | KBUILD_CFLAGS += -ffunction-sections -fdata-sections | 42 | KBUILD_CFLAGS += -ffunction-sections -fdata-sections |
43 | LDFLAGS_FINAL += --gc-sections | 43 | LDFLAGS_FINAL += --gc-sections |
44 | 44 | ||
45 | # FIX ME | 45 | # FIX ME |
46 | cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \ | 46 | cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \ |
47 | $(NOSTDINC_FLAGS) | 47 | $(NOSTDINC_FLAGS) |
48 | c_flags := $(KBUILD_CFLAGS) $(cpp_flags) | 48 | c_flags := $(KBUILD_CFLAGS) $(cpp_flags) |
49 | 49 | ||
50 | HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n) | 50 | HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n) |
51 | 51 | ||
52 | libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/) | 52 | libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/) |
53 | libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/ | 53 | libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/ |
54 | 54 | ||
55 | libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/ | 55 | libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/ |
56 | libs-y += common/init/ | 56 | libs-y += common/init/ |
57 | 57 | ||
58 | # Special handling for a few options which support SPL/TPL | 58 | # Special handling for a few options which support SPL/TPL |
59 | ifeq ($(CONFIG_TPL_BUILD),y) | 59 | ifeq ($(CONFIG_TPL_BUILD),y) |
60 | libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += common/ cmd/ | 60 | libs-$(CONFIG_TPL_LIBCOMMON_SUPPORT) += common/ cmd/ |
61 | libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/ | 61 | libs-$(CONFIG_TPL_LIBGENERIC_SUPPORT) += lib/ |
62 | else | 62 | else |
63 | libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ | 63 | libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/ cmd/ |
64 | libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/ | 64 | libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/ |
65 | endif | 65 | endif |
66 | 66 | ||
67 | libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/ | 67 | libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/ |
68 | libs-y += drivers/ | 68 | libs-y += drivers/ |
69 | libs-$(CONFIG_SPL_USB_GADGET_SUPPORT) += drivers/usb/dwc3/ | 69 | libs-$(CONFIG_SPL_USB_GADGET_SUPPORT) += drivers/usb/dwc3/ |
70 | libs-y += dts/ | 70 | libs-y += dts/ |
71 | libs-y += fs/ | 71 | libs-y += fs/ |
72 | libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/ | 72 | libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/ |
73 | libs-$(CONFIG_SPL_NET_SUPPORT) += net/ | 73 | libs-$(CONFIG_SPL_NET_SUPPORT) += net/ |
74 | 74 | ||
75 | head-y := $(addprefix $(obj)/,$(head-y)) | 75 | head-y := $(addprefix $(obj)/,$(head-y)) |
76 | libs-y := $(addprefix $(obj)/,$(libs-y)) | 76 | libs-y := $(addprefix $(obj)/,$(libs-y)) |
77 | u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y))) | 77 | u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y))) |
78 | 78 | ||
79 | libs-y := $(patsubst %/, %/built-in.o, $(libs-y)) | 79 | libs-y := $(patsubst %/, %/built-in.o, $(libs-y)) |
80 | 80 | ||
81 | # Add GCC lib | 81 | # Add GCC lib |
82 | ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y) | 82 | ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y) |
83 | PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a | 83 | PLATFORM_LIBGCC = arch/$(ARCH)/lib/lib.a |
84 | PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC) | 84 | PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $(PLATFORM_LIBGCC) |
85 | endif | 85 | endif |
86 | 86 | ||
87 | u-boot-spl-init := $(head-y) | 87 | u-boot-spl-init := $(head-y) |
88 | u-boot-spl-main := $(libs-y) | 88 | u-boot-spl-main := $(libs-y) |
89 | ifdef CONFIG_SPL_OF_PLATDATA | 89 | ifdef CONFIG_SPL_OF_PLATDATA |
90 | u-boot-spl-platdata := $(obj)/dts/dt-platdata.o | 90 | u-boot-spl-platdata := $(obj)/dts/dt-platdata.o |
91 | endif | 91 | endif |
92 | 92 | ||
93 | # Linker Script | 93 | # Linker Script |
94 | ifdef CONFIG_SPL_LDSCRIPT | 94 | ifdef CONFIG_SPL_LDSCRIPT |
95 | # need to strip off double quotes | 95 | # need to strip off double quotes |
96 | LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_LDSCRIPT:"%"=%)) | 96 | LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_SPL_LDSCRIPT:"%"=%)) |
97 | endif | 97 | endif |
98 | 98 | ||
99 | ifeq ($(wildcard $(LDSCRIPT)),) | 99 | ifeq ($(wildcard $(LDSCRIPT)),) |
100 | LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-spl.lds | 100 | LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-spl.lds |
101 | endif | 101 | endif |
102 | ifeq ($(wildcard $(LDSCRIPT)),) | 102 | ifeq ($(wildcard $(LDSCRIPT)),) |
103 | LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-spl.lds | 103 | LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-spl.lds |
104 | endif | 104 | endif |
105 | ifeq ($(wildcard $(LDSCRIPT)),) | 105 | ifeq ($(wildcard $(LDSCRIPT)),) |
106 | LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-spl.lds | 106 | LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-spl.lds |
107 | endif | 107 | endif |
108 | ifeq ($(wildcard $(LDSCRIPT)),) | 108 | ifeq ($(wildcard $(LDSCRIPT)),) |
109 | $(error could not find linker script) | 109 | $(error could not find linker script) |
110 | endif | 110 | endif |
111 | 111 | ||
112 | # Special flags for CPP when processing the linker script. | 112 | # Special flags for CPP when processing the linker script. |
113 | # Pass the version down so we can handle backwards compatibility | 113 | # Pass the version down so we can handle backwards compatibility |
114 | # on the fly. | 114 | # on the fly. |
115 | LDPPFLAGS += \ | 115 | LDPPFLAGS += \ |
116 | -include $(srctree)/include/u-boot/u-boot.lds.h \ | 116 | -include $(srctree)/include/u-boot/u-boot.lds.h \ |
117 | -include $(objtree)/include/config.h \ | 117 | -include $(objtree)/include/config.h \ |
118 | -DCPUDIR=$(CPUDIR) \ | 118 | -DCPUDIR=$(CPUDIR) \ |
119 | $(shell $(LD) --version | \ | 119 | $(shell $(LD) --version | \ |
120 | sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p') | 120 | sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p') |
121 | 121 | ||
122 | MKIMAGEOUTPUT ?= /dev/null | 122 | MKIMAGEOUTPUT ?= /dev/null |
123 | 123 | ||
124 | quiet_cmd_mkimage = MKIMAGE $@ | 124 | quiet_cmd_mkimage = MKIMAGE $@ |
125 | cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \ | 125 | cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \ |
126 | $(if $(KBUILD_VERBOSE:1=), >$(MKIMAGEOUTPUT)) | 126 | $(if $(KBUILD_VERBOSE:1=), >$(MKIMAGEOUTPUT)) |
127 | 127 | ||
128 | MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE) | 128 | MKIMAGEFLAGS_MLO = -T omapimage -a $(CONFIG_SPL_TEXT_BASE) |
129 | 129 | ||
130 | MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE) | 130 | MKIMAGEFLAGS_MLO.byteswap = -T omapimage -n byteswap -a $(CONFIG_SPL_TEXT_BASE) |
131 | 131 | ||
132 | MLO MLO.byteswap: $(obj)/u-boot-spl.bin FORCE | 132 | MLO MLO.byteswap: $(obj)/u-boot-spl.bin FORCE |
133 | $(call if_changed,mkimage) | 133 | $(call if_changed,mkimage) |
134 | 134 | ||
135 | ifeq ($(CONFIG_SYS_SOC),"at91") | 135 | ifeq ($(CONFIG_SYS_SOC),"at91") |
136 | MKIMAGEFLAGS_boot.bin = -T atmelimage | 136 | MKIMAGEFLAGS_boot.bin = -T atmelimage |
137 | 137 | ||
138 | ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y) | 138 | ifeq ($(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER),y) |
139 | MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params) | 139 | MKIMAGEFLAGS_boot.bin += -n $(shell $(obj)/../tools/atmel_pmecc_params) |
140 | 140 | ||
141 | boot.bin: $(obj)/../tools/atmel_pmecc_params | 141 | boot.bin: $(obj)/../tools/atmel_pmecc_params |
142 | endif | 142 | endif |
143 | 143 | ||
144 | boot.bin: $(obj)/u-boot-spl.bin FORCE | 144 | boot.bin: $(obj)/u-boot-spl.bin FORCE |
145 | $(call if_changed,mkimage) | 145 | $(call if_changed,mkimage) |
146 | else | 146 | else |
147 | ifdef CONFIG_ARCH_ZYNQ | 147 | ifdef CONFIG_ARCH_ZYNQ |
148 | MKIMAGEFLAGS_boot.bin = -T zynqimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) | 148 | MKIMAGEFLAGS_boot.bin = -T zynqimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) |
149 | endif | 149 | endif |
150 | ifdef CONFIG_ARCH_ZYNQMP | 150 | ifdef CONFIG_ARCH_ZYNQMP |
151 | MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) | 151 | MKIMAGEFLAGS_boot.bin = -T zynqmpimage -R $(srctree)/$(CONFIG_BOOT_INIT_FILE) |
152 | endif | 152 | endif |
153 | 153 | ||
154 | spl/boot.bin: $(obj)/u-boot-spl.bin FORCE | 154 | spl/boot.bin: $(obj)/u-boot-spl.bin FORCE |
155 | $(call if_changed,mkimage) | 155 | $(call if_changed,mkimage) |
156 | endif | 156 | endif |
157 | 157 | ||
158 | ALL-y += $(obj)/$(SPL_BIN).bin | 158 | ALL-y += $(obj)/$(SPL_BIN).bin |
159 | 159 | ||
160 | ifdef CONFIG_SAMSUNG | 160 | ifdef CONFIG_SAMSUNG |
161 | ALL-y += $(obj)/$(BOARD)-spl.bin | 161 | ALL-y += $(obj)/$(BOARD)-spl.bin |
162 | endif | 162 | endif |
163 | 163 | ||
164 | ifdef CONFIG_ARCH_SOCFPGA | 164 | ifdef CONFIG_ARCH_SOCFPGA |
165 | ALL-y += $(obj)/$(SPL_BIN).sfp | 165 | ALL-y += $(obj)/$(SPL_BIN).sfp |
166 | endif | 166 | endif |
167 | 167 | ||
168 | ifdef CONFIG_ARCH_SUNXI | 168 | ifdef CONFIG_ARCH_SUNXI |
169 | ALL-y += $(obj)/sunxi-spl.bin | 169 | ALL-y += $(obj)/sunxi-spl.bin |
170 | endif | 170 | endif |
171 | 171 | ||
172 | ifeq ($(CONFIG_SYS_SOC),"at91") | 172 | ifeq ($(CONFIG_SYS_SOC),"at91") |
173 | ALL-y += boot.bin | 173 | ALL-y += boot.bin |
174 | endif | 174 | endif |
175 | 175 | ||
176 | ALL-$(CONFIG_ARCH_ZYNQ) += $(obj)/boot.bin | 176 | ALL-$(CONFIG_ARCH_ZYNQ) += $(obj)/boot.bin |
177 | ALL-$(CONFIG_ARCH_ZYNQMP) += $(obj)/boot.bin | 177 | ALL-$(CONFIG_ARCH_ZYNQMP) += $(obj)/boot.bin |
178 | 178 | ||
179 | all: $(ALL-y) | 179 | all: $(ALL-y) |
180 | 180 | ||
181 | quiet_cmd_cat = CAT $@ | 181 | quiet_cmd_cat = CAT $@ |
182 | cmd_cat = cat $(filter-out $(PHONY), $^) > $@ | 182 | cmd_cat = cat $(filter-out $(PHONY), $^) > $@ |
183 | 183 | ||
184 | quiet_cmd_copy = COPY $@ | 184 | quiet_cmd_copy = COPY $@ |
185 | cmd_copy = cp $< $@ | 185 | cmd_copy = cp $< $@ |
186 | 186 | ||
187 | ifeq ($(CONFIG_SPL_OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_SPL_OF_PLATDATA),yy) | 187 | ifeq ($(CONFIG_SPL_OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_SPL_OF_PLATDATA),yy) |
188 | $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin $(obj)/$(SPL_BIN)-pad.bin \ | 188 | $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin $(obj)/$(SPL_BIN)-pad.bin \ |
189 | $(obj)/$(SPL_BIN).dtb FORCE | 189 | $(obj)/$(SPL_BIN).dtb FORCE |
190 | $(call if_changed,cat) | 190 | $(call if_changed,cat) |
191 | 191 | ||
192 | $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE | 192 | $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE |
193 | $(call if_changed,copy) | 193 | $(call if_changed,copy) |
194 | else | 194 | else |
195 | $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE | 195 | $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-nodtb.bin FORCE |
196 | $(call if_changed,copy) | 196 | $(call if_changed,copy) |
197 | endif | 197 | endif |
198 | 198 | ||
199 | # Create a file that pads from the end of u-boot-spl-nodtb.bin to bss_end | 199 | # Create a file that pads from the end of u-boot-spl-nodtb.bin to bss_end |
200 | $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN) | 200 | $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN) |
201 | @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \ | 201 | @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \ |
202 | dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null; | 202 | dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null; |
203 | 203 | ||
204 | # Pass the original device tree file through fdtgrep twice. The first pass | 204 | # Pass the original device tree file through fdtgrep twice. The first pass |
205 | # removes any unwanted nodes (i.e. those which don't have the | 205 | # removes any unwanted nodes (i.e. those which don't have the |
206 | # 'u-boot,dm-pre-reloc' property and thus are not needed by SPL. The second | 206 | # 'u-boot,dm-pre-reloc' property and thus are not needed by SPL. The second |
207 | # pass removes various unused properties from the remaining nodes. | 207 | # pass removes various unused properties from the remaining nodes. |
208 | # The output is typically a much smaller device tree file. | 208 | # The output is typically a much smaller device tree file. |
209 | ifeq ($(CONFIG_TPL_BUILD),y) | ||
210 | fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-tpl | ||
211 | else | ||
212 | fdtgrep_props := -b u-boot,dm-pre-reloc -b u-boot,dm-spl | ||
213 | endif | ||
209 | quiet_cmd_fdtgrep = FDTGREP $@ | 214 | quiet_cmd_fdtgrep = FDTGREP $@ |
210 | cmd_fdtgrep = $(objtree)/tools/fdtgrep -b u-boot,dm-pre-reloc -RT $< \ | 215 | cmd_fdtgrep = $(objtree)/tools/fdtgrep $(fdtgrep_props) -RT $< \ |
211 | -n /chosen -O dtb | \ | 216 | -n /chosen -O dtb | \ |
212 | $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ | 217 | $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ |
213 | $(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS))) | 218 | $(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS))) |
214 | 219 | ||
215 | $(obj)/$(SPL_BIN).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE | 220 | $(obj)/$(SPL_BIN).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE |
216 | $(call if_changed,fdtgrep) | 221 | $(call if_changed,fdtgrep) |
217 | 222 | ||
218 | pythonpath = PYTHONPATH=tools | 223 | pythonpath = PYTHONPATH=tools |
219 | 224 | ||
220 | quiet_cmd_dtocc = DTOC C $@ | 225 | quiet_cmd_dtocc = DTOC C $@ |
221 | cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata | 226 | cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata |
222 | 227 | ||
223 | quiet_cmd_dtoch = DTOC H $@ | 228 | quiet_cmd_dtoch = DTOC H $@ |
224 | cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct | 229 | cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct |
225 | 230 | ||
226 | quiet_cmd_plat = PLAT $@ | 231 | quiet_cmd_plat = PLAT $@ |
227 | cmd_plat = $(CC) $(c_flags) -c $< -o $@ | 232 | cmd_plat = $(CC) $(c_flags) -c $< -o $@ |
228 | 233 | ||
229 | $(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c include/generated/dt-structs.h | 234 | $(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c include/generated/dt-structs.h |
230 | $(call if_changed,plat) | 235 | $(call if_changed,plat) |
231 | 236 | ||
232 | PHONY += dts_dir | 237 | PHONY += dts_dir |
233 | dts_dir: | 238 | dts_dir: |
234 | $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts) | 239 | $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts) |
235 | 240 | ||
236 | include/generated/dt-structs.h: $(obj)/$(SPL_BIN).dtb dts_dir dtoc | 241 | include/generated/dt-structs.h: $(obj)/$(SPL_BIN).dtb dts_dir dtoc |
237 | $(call if_changed,dtoch) | 242 | $(call if_changed,dtoch) |
238 | 243 | ||
239 | $(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir dtoc | 244 | $(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir dtoc |
240 | $(call if_changed,dtocc) | 245 | $(call if_changed,dtocc) |
241 | 246 | ||
242 | dtoc: #$(objtree)/tools/_libfdt.so | 247 | dtoc: #$(objtree)/tools/_libfdt.so |
243 | 248 | ||
244 | ifdef CONFIG_SAMSUNG | 249 | ifdef CONFIG_SAMSUNG |
245 | ifdef CONFIG_VAR_SIZE_SPL | 250 | ifdef CONFIG_VAR_SIZE_SPL |
246 | VAR_SIZE_PARAM = --vs | 251 | VAR_SIZE_PARAM = --vs |
247 | else | 252 | else |
248 | VAR_SIZE_PARAM = | 253 | VAR_SIZE_PARAM = |
249 | endif | 254 | endif |
250 | $(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin | 255 | $(obj)/$(BOARD)-spl.bin: $(obj)/u-boot-spl.bin |
251 | $(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\ | 256 | $(if $(wildcard $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl),\ |
252 | $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\ | 257 | $(objtree)/spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl,\ |
253 | $(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@ | 258 | $(objtree)/tools/mkexynosspl) $(VAR_SIZE_PARAM) $< $@ |
254 | endif | 259 | endif |
255 | 260 | ||
256 | quiet_cmd_objcopy = OBJCOPY $@ | 261 | quiet_cmd_objcopy = OBJCOPY $@ |
257 | cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ | 262 | cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ |
258 | 263 | ||
259 | OBJCOPYFLAGS_$(SPL_BIN)-nodtb.bin = $(SPL_OBJCFLAGS) -O binary | 264 | OBJCOPYFLAGS_$(SPL_BIN)-nodtb.bin = $(SPL_OBJCFLAGS) -O binary |
260 | 265 | ||
261 | $(obj)/$(SPL_BIN)-nodtb.bin: $(obj)/$(SPL_BIN) FORCE | 266 | $(obj)/$(SPL_BIN)-nodtb.bin: $(obj)/$(SPL_BIN) FORCE |
262 | $(call if_changed,objcopy) | 267 | $(call if_changed,objcopy) |
263 | 268 | ||
264 | LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL) | 269 | LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL) |
265 | ifneq ($(CONFIG_SPL_TEXT_BASE),) | 270 | ifneq ($(CONFIG_SPL_TEXT_BASE),) |
266 | LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE) | 271 | LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE) |
267 | endif | 272 | endif |
268 | 273 | ||
269 | MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage | 274 | MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage |
270 | $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE | 275 | $(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE |
271 | $(call if_changed,mkimage) | 276 | $(call if_changed,mkimage) |
272 | 277 | ||
273 | quiet_cmd_mksunxiboot = MKSUNXI $@ | 278 | quiet_cmd_mksunxiboot = MKSUNXI $@ |
274 | cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@ | 279 | cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@ |
275 | $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE | 280 | $(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin FORCE |
276 | $(call if_changed,mksunxiboot) | 281 | $(call if_changed,mksunxiboot) |
277 | 282 | ||
278 | # Rule to link u-boot-spl | 283 | # Rule to link u-boot-spl |
279 | # May be overridden by arch/$(ARCH)/config.mk | 284 | # May be overridden by arch/$(ARCH)/config.mk |
280 | quiet_cmd_u-boot-spl ?= LD $@ | 285 | quiet_cmd_u-boot-spl ?= LD $@ |
281 | cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \ | 286 | cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \ |
282 | $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \ | 287 | $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \ |
283 | $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \ | 288 | $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \ |
284 | $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \ | 289 | $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \ |
285 | --end-group \ | 290 | --end-group \ |
286 | $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)) | 291 | $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)) |
287 | 292 | ||
288 | $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \ | 293 | $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \ |
289 | $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE | 294 | $(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE |
290 | $(call if_changed,u-boot-spl) | 295 | $(call if_changed,u-boot-spl) |
291 | 296 | ||
292 | $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ; | 297 | $(sort $(u-boot-spl-init) $(u-boot-spl-main)): $(u-boot-spl-dirs) ; |
293 | 298 | ||
294 | PHONY += $(u-boot-spl-dirs) | 299 | PHONY += $(u-boot-spl-dirs) |
295 | $(u-boot-spl-dirs): $(u-boot-spl-platdata) | 300 | $(u-boot-spl-dirs): $(u-boot-spl-platdata) |
296 | $(Q)$(MAKE) $(build)=$@ | 301 | $(Q)$(MAKE) $(build)=$@ |
297 | 302 | ||
298 | quiet_cmd_cpp_lds = LDS $@ | 303 | quiet_cmd_cpp_lds = LDS $@ |
299 | cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \ | 304 | cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \ |
300 | -D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $< | 305 | -D__ASSEMBLY__ -x assembler-with-cpp -P -o $@ $< |
301 | 306 | ||
302 | $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE | 307 | $(obj)/u-boot-spl.lds: $(LDSCRIPT) FORCE |
303 | $(call if_changed_dep,cpp_lds) | 308 | $(call if_changed_dep,cpp_lds) |
304 | 309 | ||
305 | # read all saved command lines | 310 | # read all saved command lines |
306 | 311 | ||
307 | targets := $(wildcard $(sort $(targets))) | 312 | targets := $(wildcard $(sort $(targets))) |
308 | cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) | 313 | cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) |
309 | 314 | ||
310 | ifneq ($(cmd_files),) | 315 | ifneq ($(cmd_files),) |
311 | $(cmd_files): ; # Do not try to update included dependency files | 316 | $(cmd_files): ; # Do not try to update included dependency files |
312 | include $(cmd_files) | 317 | include $(cmd_files) |
313 | endif | 318 | endif |
314 | 319 | ||
315 | PHONY += FORCE | 320 | PHONY += FORCE |
316 | FORCE: | 321 | FORCE: |
317 | 322 | ||
318 | # Declare the contents of the .PHONY variable as phony. We keep that | 323 | # Declare the contents of the .PHONY variable as phony. We keep that |
319 | # information in a variable so we can use it in if_changed and friends. | 324 | # information in a variable so we can use it in if_changed and friends. |
320 | .PHONY: $(PHONY) | 325 | .PHONY: $(PHONY) |
321 | 326 |
tools/dtoc/dtoc.py
1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
2 | # | 2 | # |
3 | # Copyright (C) 2016 Google, Inc | 3 | # Copyright (C) 2016 Google, Inc |
4 | # Written by Simon Glass <sjg@chromium.org> | 4 | # Written by Simon Glass <sjg@chromium.org> |
5 | # | 5 | # |
6 | # SPDX-License-Identifier: GPL-2.0+ | 6 | # SPDX-License-Identifier: GPL-2.0+ |
7 | # | 7 | # |
8 | 8 | ||
9 | import copy | 9 | import copy |
10 | from optparse import OptionError, OptionParser | 10 | from optparse import OptionError, OptionParser |
11 | import os | 11 | import os |
12 | import struct | 12 | import struct |
13 | import sys | 13 | import sys |
14 | 14 | ||
15 | # Bring in the patman libraries | 15 | # Bring in the patman libraries |
16 | our_path = os.path.dirname(os.path.realpath(__file__)) | 16 | our_path = os.path.dirname(os.path.realpath(__file__)) |
17 | sys.path.append(os.path.join(our_path, '../patman')) | 17 | sys.path.append(os.path.join(our_path, '../patman')) |
18 | 18 | ||
19 | import fdt | 19 | import fdt |
20 | import fdt_select | 20 | import fdt_select |
21 | import fdt_util | 21 | import fdt_util |
22 | 22 | ||
23 | # When we see these properties we ignore them - i.e. do not create a structure member | 23 | # When we see these properties we ignore them - i.e. do not create a structure member |
24 | PROP_IGNORE_LIST = [ | 24 | PROP_IGNORE_LIST = [ |
25 | '#address-cells', | 25 | '#address-cells', |
26 | '#gpio-cells', | 26 | '#gpio-cells', |
27 | '#size-cells', | 27 | '#size-cells', |
28 | 'compatible', | 28 | 'compatible', |
29 | 'linux,phandle', | 29 | 'linux,phandle', |
30 | "status", | 30 | "status", |
31 | 'phandle', | 31 | 'phandle', |
32 | 'u-boot,dm-pre-reloc', | 32 | 'u-boot,dm-pre-reloc', |
33 | 'u-boot,dm-tpl', | ||
34 | 'u-boot,dm-spl', | ||
33 | ] | 35 | ] |
34 | 36 | ||
35 | # C type declarations for the tyues we support | 37 | # C type declarations for the tyues we support |
36 | TYPE_NAMES = { | 38 | TYPE_NAMES = { |
37 | fdt.TYPE_INT: 'fdt32_t', | 39 | fdt.TYPE_INT: 'fdt32_t', |
38 | fdt.TYPE_BYTE: 'unsigned char', | 40 | fdt.TYPE_BYTE: 'unsigned char', |
39 | fdt.TYPE_STRING: 'const char *', | 41 | fdt.TYPE_STRING: 'const char *', |
40 | fdt.TYPE_BOOL: 'bool', | 42 | fdt.TYPE_BOOL: 'bool', |
41 | }; | 43 | }; |
42 | 44 | ||
43 | STRUCT_PREFIX = 'dtd_' | 45 | STRUCT_PREFIX = 'dtd_' |
44 | VAL_PREFIX = 'dtv_' | 46 | VAL_PREFIX = 'dtv_' |
45 | 47 | ||
46 | def Conv_name_to_c(name): | 48 | def Conv_name_to_c(name): |
47 | """Convert a device-tree name to a C identifier | 49 | """Convert a device-tree name to a C identifier |
48 | 50 | ||
49 | Args: | 51 | Args: |
50 | name: Name to convert | 52 | name: Name to convert |
51 | Return: | 53 | Return: |
52 | String containing the C version of this name | 54 | String containing the C version of this name |
53 | """ | 55 | """ |
54 | str = name.replace('@', '_at_') | 56 | str = name.replace('@', '_at_') |
55 | str = str.replace('-', '_') | 57 | str = str.replace('-', '_') |
56 | str = str.replace(',', '_') | 58 | str = str.replace(',', '_') |
57 | str = str.replace('/', '__') | 59 | str = str.replace('/', '__') |
58 | return str | 60 | return str |
59 | 61 | ||
60 | def TabTo(num_tabs, str): | 62 | def TabTo(num_tabs, str): |
61 | if len(str) >= num_tabs * 8: | 63 | if len(str) >= num_tabs * 8: |
62 | return str + ' ' | 64 | return str + ' ' |
63 | return str + '\t' * (num_tabs - len(str) // 8) | 65 | return str + '\t' * (num_tabs - len(str) // 8) |
64 | 66 | ||
65 | class DtbPlatdata: | 67 | class DtbPlatdata: |
66 | """Provide a means to convert device tree binary data to platform data | 68 | """Provide a means to convert device tree binary data to platform data |
67 | 69 | ||
68 | The output of this process is C structures which can be used in space- | 70 | The output of this process is C structures which can be used in space- |
69 | constrained encvironments where the ~3KB code overhead of device tree | 71 | constrained encvironments where the ~3KB code overhead of device tree |
70 | code is not affordable. | 72 | code is not affordable. |
71 | 73 | ||
72 | Properties: | 74 | Properties: |
73 | fdt: Fdt object, referencing the device tree | 75 | fdt: Fdt object, referencing the device tree |
74 | _dtb_fname: Filename of the input device tree binary file | 76 | _dtb_fname: Filename of the input device tree binary file |
75 | _valid_nodes: A list of Node object with compatible strings | 77 | _valid_nodes: A list of Node object with compatible strings |
76 | _options: Command-line options | 78 | _options: Command-line options |
77 | _phandle_node: A dict of nodes indexed by phandle number (1, 2...) | 79 | _phandle_node: A dict of nodes indexed by phandle number (1, 2...) |
78 | _outfile: The current output file (sys.stdout or a real file) | 80 | _outfile: The current output file (sys.stdout or a real file) |
79 | _lines: Stashed list of output lines for outputting in the future | 81 | _lines: Stashed list of output lines for outputting in the future |
80 | _phandle_node: A dict of Nodes indexed by phandle (an integer) | 82 | _phandle_node: A dict of Nodes indexed by phandle (an integer) |
81 | """ | 83 | """ |
82 | def __init__(self, dtb_fname, options): | 84 | def __init__(self, dtb_fname, options): |
83 | self._dtb_fname = dtb_fname | 85 | self._dtb_fname = dtb_fname |
84 | self._valid_nodes = None | 86 | self._valid_nodes = None |
85 | self._options = options | 87 | self._options = options |
86 | self._phandle_node = {} | 88 | self._phandle_node = {} |
87 | self._outfile = None | 89 | self._outfile = None |
88 | self._lines = [] | 90 | self._lines = [] |
89 | 91 | ||
90 | def SetupOutput(self, fname): | 92 | def SetupOutput(self, fname): |
91 | """Set up the output destination | 93 | """Set up the output destination |
92 | 94 | ||
93 | Once this is done, future calls to self.Out() will output to this | 95 | Once this is done, future calls to self.Out() will output to this |
94 | file. | 96 | file. |
95 | 97 | ||
96 | Args: | 98 | Args: |
97 | fname: Filename to send output to, or '-' for stdout | 99 | fname: Filename to send output to, or '-' for stdout |
98 | """ | 100 | """ |
99 | if fname == '-': | 101 | if fname == '-': |
100 | self._outfile = sys.stdout | 102 | self._outfile = sys.stdout |
101 | else: | 103 | else: |
102 | self._outfile = open(fname, 'w') | 104 | self._outfile = open(fname, 'w') |
103 | 105 | ||
104 | def Out(self, str): | 106 | def Out(self, str): |
105 | """Output a string to the output file | 107 | """Output a string to the output file |
106 | 108 | ||
107 | Args: | 109 | Args: |
108 | str: String to output | 110 | str: String to output |
109 | """ | 111 | """ |
110 | self._outfile.write(str) | 112 | self._outfile.write(str) |
111 | 113 | ||
112 | def Buf(self, str): | 114 | def Buf(self, str): |
113 | """Buffer up a string to send later | 115 | """Buffer up a string to send later |
114 | 116 | ||
115 | Args: | 117 | Args: |
116 | str: String to add to our 'buffer' list | 118 | str: String to add to our 'buffer' list |
117 | """ | 119 | """ |
118 | self._lines.append(str) | 120 | self._lines.append(str) |
119 | 121 | ||
120 | def GetBuf(self): | 122 | def GetBuf(self): |
121 | """Get the contents of the output buffer, and clear it | 123 | """Get the contents of the output buffer, and clear it |
122 | 124 | ||
123 | Returns: | 125 | Returns: |
124 | The output buffer, which is then cleared for future use | 126 | The output buffer, which is then cleared for future use |
125 | """ | 127 | """ |
126 | lines = self._lines | 128 | lines = self._lines |
127 | self._lines = [] | 129 | self._lines = [] |
128 | return lines | 130 | return lines |
129 | 131 | ||
130 | def GetValue(self, type, value): | 132 | def GetValue(self, type, value): |
131 | """Get a value as a C expression | 133 | """Get a value as a C expression |
132 | 134 | ||
133 | For integers this returns a byte-swapped (little-endian) hex string | 135 | For integers this returns a byte-swapped (little-endian) hex string |
134 | For bytes this returns a hex string, e.g. 0x12 | 136 | For bytes this returns a hex string, e.g. 0x12 |
135 | For strings this returns a literal string enclosed in quotes | 137 | For strings this returns a literal string enclosed in quotes |
136 | For booleans this return 'true' | 138 | For booleans this return 'true' |
137 | 139 | ||
138 | Args: | 140 | Args: |
139 | type: Data type (fdt_util) | 141 | type: Data type (fdt_util) |
140 | value: Data value, as a string of bytes | 142 | value: Data value, as a string of bytes |
141 | """ | 143 | """ |
142 | if type == fdt.TYPE_INT: | 144 | if type == fdt.TYPE_INT: |
143 | return '%#x' % fdt_util.fdt32_to_cpu(value) | 145 | return '%#x' % fdt_util.fdt32_to_cpu(value) |
144 | elif type == fdt.TYPE_BYTE: | 146 | elif type == fdt.TYPE_BYTE: |
145 | return '%#x' % ord(value[0]) | 147 | return '%#x' % ord(value[0]) |
146 | elif type == fdt.TYPE_STRING: | 148 | elif type == fdt.TYPE_STRING: |
147 | return '"%s"' % value | 149 | return '"%s"' % value |
148 | elif type == fdt.TYPE_BOOL: | 150 | elif type == fdt.TYPE_BOOL: |
149 | return 'true' | 151 | return 'true' |
150 | 152 | ||
151 | def GetCompatName(self, node): | 153 | def GetCompatName(self, node): |
152 | """Get a node's first compatible string as a C identifier | 154 | """Get a node's first compatible string as a C identifier |
153 | 155 | ||
154 | Args: | 156 | Args: |
155 | node: Node object to check | 157 | node: Node object to check |
156 | Return: | 158 | Return: |
157 | C identifier for the first compatible string | 159 | C identifier for the first compatible string |
158 | """ | 160 | """ |
159 | compat = node.props['compatible'].value | 161 | compat = node.props['compatible'].value |
160 | if type(compat) == list: | 162 | if type(compat) == list: |
161 | compat = compat[0] | 163 | compat = compat[0] |
162 | return Conv_name_to_c(compat) | 164 | return Conv_name_to_c(compat) |
163 | 165 | ||
164 | def ScanDtb(self): | 166 | def ScanDtb(self): |
165 | """Scan the device tree to obtain a tree of notes and properties | 167 | """Scan the device tree to obtain a tree of notes and properties |
166 | 168 | ||
167 | Once this is done, self.fdt.GetRoot() can be called to obtain the | 169 | Once this is done, self.fdt.GetRoot() can be called to obtain the |
168 | device tree root node, and progress from there. | 170 | device tree root node, and progress from there. |
169 | """ | 171 | """ |
170 | self.fdt = fdt_select.FdtScan(self._dtb_fname) | 172 | self.fdt = fdt_select.FdtScan(self._dtb_fname) |
171 | 173 | ||
172 | def ScanTree(self): | 174 | def ScanTree(self): |
173 | """Scan the device tree for useful information | 175 | """Scan the device tree for useful information |
174 | 176 | ||
175 | This fills in the following properties: | 177 | This fills in the following properties: |
176 | _phandle_node: A dict of Nodes indexed by phandle (an integer) | 178 | _phandle_node: A dict of Nodes indexed by phandle (an integer) |
177 | _valid_nodes: A list of nodes we wish to consider include in the | 179 | _valid_nodes: A list of nodes we wish to consider include in the |
178 | platform data | 180 | platform data |
179 | """ | 181 | """ |
180 | node_list = [] | 182 | node_list = [] |
181 | self._phandle_node = {} | 183 | self._phandle_node = {} |
182 | for node in self.fdt.GetRoot().subnodes: | 184 | for node in self.fdt.GetRoot().subnodes: |
183 | if 'compatible' in node.props: | 185 | if 'compatible' in node.props: |
184 | status = node.props.get('status') | 186 | status = node.props.get('status') |
185 | if (not options.include_disabled and not status or | 187 | if (not options.include_disabled and not status or |
186 | status.value != 'disabled'): | 188 | status.value != 'disabled'): |
187 | node_list.append(node) | 189 | node_list.append(node) |
188 | phandle_prop = node.props.get('phandle') | 190 | phandle_prop = node.props.get('phandle') |
189 | if phandle_prop: | 191 | if phandle_prop: |
190 | phandle = phandle_prop.GetPhandle() | 192 | phandle = phandle_prop.GetPhandle() |
191 | self._phandle_node[phandle] = node | 193 | self._phandle_node[phandle] = node |
192 | 194 | ||
193 | self._valid_nodes = node_list | 195 | self._valid_nodes = node_list |
194 | 196 | ||
195 | def IsPhandle(self, prop): | 197 | def IsPhandle(self, prop): |
196 | """Check if a node contains phandles | 198 | """Check if a node contains phandles |
197 | 199 | ||
198 | We have no reliable way of detecting whether a node uses a phandle | 200 | We have no reliable way of detecting whether a node uses a phandle |
199 | or not. As an interim measure, use a list of known property names. | 201 | or not. As an interim measure, use a list of known property names. |
200 | 202 | ||
201 | Args: | 203 | Args: |
202 | prop: Prop object to check | 204 | prop: Prop object to check |
203 | Return: | 205 | Return: |
204 | True if the object value contains phandles, else False | 206 | True if the object value contains phandles, else False |
205 | """ | 207 | """ |
206 | if prop.name in ['clocks']: | 208 | if prop.name in ['clocks']: |
207 | return True | 209 | return True |
208 | return False | 210 | return False |
209 | 211 | ||
210 | def ScanStructs(self): | 212 | def ScanStructs(self): |
211 | """Scan the device tree building up the C structures we will use. | 213 | """Scan the device tree building up the C structures we will use. |
212 | 214 | ||
213 | Build a dict keyed by C struct name containing a dict of Prop | 215 | Build a dict keyed by C struct name containing a dict of Prop |
214 | object for each struct field (keyed by property name). Where the | 216 | object for each struct field (keyed by property name). Where the |
215 | same struct appears multiple times, try to use the 'widest' | 217 | same struct appears multiple times, try to use the 'widest' |
216 | property, i.e. the one with a type which can express all others. | 218 | property, i.e. the one with a type which can express all others. |
217 | 219 | ||
218 | Once the widest property is determined, all other properties are | 220 | Once the widest property is determined, all other properties are |
219 | updated to match that width. | 221 | updated to match that width. |
220 | """ | 222 | """ |
221 | structs = {} | 223 | structs = {} |
222 | for node in self._valid_nodes: | 224 | for node in self._valid_nodes: |
223 | node_name = self.GetCompatName(node) | 225 | node_name = self.GetCompatName(node) |
224 | fields = {} | 226 | fields = {} |
225 | 227 | ||
226 | # Get a list of all the valid properties in this node. | 228 | # Get a list of all the valid properties in this node. |
227 | for name, prop in node.props.items(): | 229 | for name, prop in node.props.items(): |
228 | if name not in PROP_IGNORE_LIST and name[0] != '#': | 230 | if name not in PROP_IGNORE_LIST and name[0] != '#': |
229 | fields[name] = copy.deepcopy(prop) | 231 | fields[name] = copy.deepcopy(prop) |
230 | 232 | ||
231 | # If we've seen this node_name before, update the existing struct. | 233 | # If we've seen this node_name before, update the existing struct. |
232 | if node_name in structs: | 234 | if node_name in structs: |
233 | struct = structs[node_name] | 235 | struct = structs[node_name] |
234 | for name, prop in fields.items(): | 236 | for name, prop in fields.items(): |
235 | oldprop = struct.get(name) | 237 | oldprop = struct.get(name) |
236 | if oldprop: | 238 | if oldprop: |
237 | oldprop.Widen(prop) | 239 | oldprop.Widen(prop) |
238 | else: | 240 | else: |
239 | struct[name] = prop | 241 | struct[name] = prop |
240 | 242 | ||
241 | # Otherwise store this as a new struct. | 243 | # Otherwise store this as a new struct. |
242 | else: | 244 | else: |
243 | structs[node_name] = fields | 245 | structs[node_name] = fields |
244 | 246 | ||
245 | upto = 0 | 247 | upto = 0 |
246 | for node in self._valid_nodes: | 248 | for node in self._valid_nodes: |
247 | node_name = self.GetCompatName(node) | 249 | node_name = self.GetCompatName(node) |
248 | struct = structs[node_name] | 250 | struct = structs[node_name] |
249 | for name, prop in node.props.items(): | 251 | for name, prop in node.props.items(): |
250 | if name not in PROP_IGNORE_LIST and name[0] != '#': | 252 | if name not in PROP_IGNORE_LIST and name[0] != '#': |
251 | prop.Widen(struct[name]) | 253 | prop.Widen(struct[name]) |
252 | upto += 1 | 254 | upto += 1 |
253 | return structs | 255 | return structs |
254 | 256 | ||
255 | def GenerateStructs(self, structs): | 257 | def GenerateStructs(self, structs): |
256 | """Generate struct defintions for the platform data | 258 | """Generate struct defintions for the platform data |
257 | 259 | ||
258 | This writes out the body of a header file consisting of structure | 260 | This writes out the body of a header file consisting of structure |
259 | definitions for node in self._valid_nodes. See the documentation in | 261 | definitions for node in self._valid_nodes. See the documentation in |
260 | README.of-plat for more information. | 262 | README.of-plat for more information. |
261 | """ | 263 | """ |
262 | self.Out('#include <stdbool.h>\n') | 264 | self.Out('#include <stdbool.h>\n') |
263 | self.Out('#include <libfdt.h>\n') | 265 | self.Out('#include <libfdt.h>\n') |
264 | 266 | ||
265 | # Output the struct definition | 267 | # Output the struct definition |
266 | for name in sorted(structs): | 268 | for name in sorted(structs): |
267 | self.Out('struct %s%s {\n' % (STRUCT_PREFIX, name)); | 269 | self.Out('struct %s%s {\n' % (STRUCT_PREFIX, name)); |
268 | for pname in sorted(structs[name]): | 270 | for pname in sorted(structs[name]): |
269 | prop = structs[name][pname] | 271 | prop = structs[name][pname] |
270 | if self.IsPhandle(prop): | 272 | if self.IsPhandle(prop): |
271 | # For phandles, include a reference to the target | 273 | # For phandles, include a reference to the target |
272 | self.Out('\t%s%s[%d]' % (TabTo(2, 'struct phandle_2_cell'), | 274 | self.Out('\t%s%s[%d]' % (TabTo(2, 'struct phandle_2_cell'), |
273 | Conv_name_to_c(prop.name), | 275 | Conv_name_to_c(prop.name), |
274 | len(prop.value) / 2)) | 276 | len(prop.value) / 2)) |
275 | else: | 277 | else: |
276 | ptype = TYPE_NAMES[prop.type] | 278 | ptype = TYPE_NAMES[prop.type] |
277 | self.Out('\t%s%s' % (TabTo(2, ptype), | 279 | self.Out('\t%s%s' % (TabTo(2, ptype), |
278 | Conv_name_to_c(prop.name))) | 280 | Conv_name_to_c(prop.name))) |
279 | if type(prop.value) == list: | 281 | if type(prop.value) == list: |
280 | self.Out('[%d]' % len(prop.value)) | 282 | self.Out('[%d]' % len(prop.value)) |
281 | self.Out(';\n') | 283 | self.Out(';\n') |
282 | self.Out('};\n') | 284 | self.Out('};\n') |
283 | 285 | ||
284 | def GenerateTables(self): | 286 | def GenerateTables(self): |
285 | """Generate device defintions for the platform data | 287 | """Generate device defintions for the platform data |
286 | 288 | ||
287 | This writes out C platform data initialisation data and | 289 | This writes out C platform data initialisation data and |
288 | U_BOOT_DEVICE() declarations for each valid node. See the | 290 | U_BOOT_DEVICE() declarations for each valid node. See the |
289 | documentation in README.of-plat for more information. | 291 | documentation in README.of-plat for more information. |
290 | """ | 292 | """ |
291 | self.Out('#include <common.h>\n') | 293 | self.Out('#include <common.h>\n') |
292 | self.Out('#include <dm.h>\n') | 294 | self.Out('#include <dm.h>\n') |
293 | self.Out('#include <dt-structs.h>\n') | 295 | self.Out('#include <dt-structs.h>\n') |
294 | self.Out('\n') | 296 | self.Out('\n') |
295 | node_txt_list = [] | 297 | node_txt_list = [] |
296 | for node in self._valid_nodes: | 298 | for node in self._valid_nodes: |
297 | struct_name = self.GetCompatName(node) | 299 | struct_name = self.GetCompatName(node) |
298 | var_name = Conv_name_to_c(node.name) | 300 | var_name = Conv_name_to_c(node.name) |
299 | self.Buf('static struct %s%s %s%s = {\n' % | 301 | self.Buf('static struct %s%s %s%s = {\n' % |
300 | (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) | 302 | (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) |
301 | for pname, prop in node.props.items(): | 303 | for pname, prop in node.props.items(): |
302 | if pname in PROP_IGNORE_LIST or pname[0] == '#': | 304 | if pname in PROP_IGNORE_LIST or pname[0] == '#': |
303 | continue | 305 | continue |
304 | ptype = TYPE_NAMES[prop.type] | 306 | ptype = TYPE_NAMES[prop.type] |
305 | member_name = Conv_name_to_c(prop.name) | 307 | member_name = Conv_name_to_c(prop.name) |
306 | self.Buf('\t%s= ' % TabTo(3, '.' + member_name)) | 308 | self.Buf('\t%s= ' % TabTo(3, '.' + member_name)) |
307 | 309 | ||
308 | # Special handling for lists | 310 | # Special handling for lists |
309 | if type(prop.value) == list: | 311 | if type(prop.value) == list: |
310 | self.Buf('{') | 312 | self.Buf('{') |
311 | vals = [] | 313 | vals = [] |
312 | # For phandles, output a reference to the platform data | 314 | # For phandles, output a reference to the platform data |
313 | # of the target node. | 315 | # of the target node. |
314 | if self.IsPhandle(prop): | 316 | if self.IsPhandle(prop): |
315 | # Process the list as pairs of (phandle, id) | 317 | # Process the list as pairs of (phandle, id) |
316 | it = iter(prop.value) | 318 | it = iter(prop.value) |
317 | for phandle_cell, id_cell in zip(it, it): | 319 | for phandle_cell, id_cell in zip(it, it): |
318 | phandle = fdt_util.fdt32_to_cpu(phandle_cell) | 320 | phandle = fdt_util.fdt32_to_cpu(phandle_cell) |
319 | id = fdt_util.fdt32_to_cpu(id_cell) | 321 | id = fdt_util.fdt32_to_cpu(id_cell) |
320 | target_node = self._phandle_node[phandle] | 322 | target_node = self._phandle_node[phandle] |
321 | name = Conv_name_to_c(target_node.name) | 323 | name = Conv_name_to_c(target_node.name) |
322 | vals.append('{&%s%s, %d}' % (VAL_PREFIX, name, id)) | 324 | vals.append('{&%s%s, %d}' % (VAL_PREFIX, name, id)) |
323 | else: | 325 | else: |
324 | for val in prop.value: | 326 | for val in prop.value: |
325 | vals.append(self.GetValue(prop.type, val)) | 327 | vals.append(self.GetValue(prop.type, val)) |
326 | self.Buf(', '.join(vals)) | 328 | self.Buf(', '.join(vals)) |
327 | self.Buf('}') | 329 | self.Buf('}') |
328 | else: | 330 | else: |
329 | self.Buf(self.GetValue(prop.type, prop.value)) | 331 | self.Buf(self.GetValue(prop.type, prop.value)) |
330 | self.Buf(',\n') | 332 | self.Buf(',\n') |
331 | self.Buf('};\n') | 333 | self.Buf('};\n') |
332 | 334 | ||
333 | # Add a device declaration | 335 | # Add a device declaration |
334 | self.Buf('U_BOOT_DEVICE(%s) = {\n' % var_name) | 336 | self.Buf('U_BOOT_DEVICE(%s) = {\n' % var_name) |
335 | self.Buf('\t.name\t\t= "%s",\n' % struct_name) | 337 | self.Buf('\t.name\t\t= "%s",\n' % struct_name) |
336 | self.Buf('\t.platdata\t= &%s%s,\n' % (VAL_PREFIX, var_name)) | 338 | self.Buf('\t.platdata\t= &%s%s,\n' % (VAL_PREFIX, var_name)) |
337 | self.Buf('\t.platdata_size\t= sizeof(%s%s),\n' % | 339 | self.Buf('\t.platdata_size\t= sizeof(%s%s),\n' % |
338 | (VAL_PREFIX, var_name)) | 340 | (VAL_PREFIX, var_name)) |
339 | self.Buf('};\n') | 341 | self.Buf('};\n') |
340 | self.Buf('\n') | 342 | self.Buf('\n') |
341 | 343 | ||
342 | # Output phandle target nodes first, since they may be referenced | 344 | # Output phandle target nodes first, since they may be referenced |
343 | # by others | 345 | # by others |
344 | if 'phandle' in node.props: | 346 | if 'phandle' in node.props: |
345 | self.Out(''.join(self.GetBuf())) | 347 | self.Out(''.join(self.GetBuf())) |
346 | else: | 348 | else: |
347 | node_txt_list.append(self.GetBuf()) | 349 | node_txt_list.append(self.GetBuf()) |
348 | 350 | ||
349 | # Output all the nodes which are not phandle targets themselves, but | 351 | # Output all the nodes which are not phandle targets themselves, but |
350 | # may reference them. This avoids the need for forward declarations. | 352 | # may reference them. This avoids the need for forward declarations. |
351 | for node_txt in node_txt_list: | 353 | for node_txt in node_txt_list: |
352 | self.Out(''.join(node_txt)) | 354 | self.Out(''.join(node_txt)) |
353 | 355 | ||
354 | 356 | ||
355 | if __name__ != "__main__": | 357 | if __name__ != "__main__": |
356 | pass | 358 | pass |
357 | 359 | ||
358 | parser = OptionParser() | 360 | parser = OptionParser() |
359 | parser.add_option('-d', '--dtb-file', action='store', | 361 | parser.add_option('-d', '--dtb-file', action='store', |
360 | help='Specify the .dtb input file') | 362 | help='Specify the .dtb input file') |
361 | parser.add_option('--include-disabled', action='store_true', | 363 | parser.add_option('--include-disabled', action='store_true', |
362 | help='Include disabled nodes') | 364 | help='Include disabled nodes') |
363 | parser.add_option('-o', '--output', action='store', default='-', | 365 | parser.add_option('-o', '--output', action='store', default='-', |
364 | help='Select output filename') | 366 | help='Select output filename') |
365 | (options, args) = parser.parse_args() | 367 | (options, args) = parser.parse_args() |
366 | 368 | ||
367 | if not args: | 369 | if not args: |
368 | raise ValueError('Please specify a command: struct, platdata') | 370 | raise ValueError('Please specify a command: struct, platdata') |
369 | 371 | ||
370 | plat = DtbPlatdata(options.dtb_file, options) | 372 | plat = DtbPlatdata(options.dtb_file, options) |
371 | plat.ScanDtb() | 373 | plat.ScanDtb() |
372 | plat.ScanTree() | 374 | plat.ScanTree() |
373 | plat.SetupOutput(options.output) | 375 | plat.SetupOutput(options.output) |
374 | structs = plat.ScanStructs() | 376 | structs = plat.ScanStructs() |
375 | 377 | ||
376 | for cmd in args[0].split(','): | 378 | for cmd in args[0].split(','): |
377 | if cmd == 'struct': | 379 | if cmd == 'struct': |
378 | plat.GenerateStructs(structs) | 380 | plat.GenerateStructs(structs) |
379 | elif cmd == 'platdata': | 381 | elif cmd == 'platdata': |
380 | plat.GenerateTables() | 382 | plat.GenerateTables() |
381 | else: | 383 | else: |
382 | raise ValueError("Unknown command '%s': (use: struct, platdata)" % cmd) | 384 | raise ValueError("Unknown command '%s': (use: struct, platdata)" % cmd) |
383 | 385 |