QUESTION
Device Tree population과 deep probe 단계에서 실제로 바뀌는 상태는 무엇인가?
DT node의 존재, device 등록, driver probe 확인을 구분한다. of_platform_populate의 child walk와 of_device_ensure_probed의 요청 node 처리는 서로 다른 진입 경로다.
일반 population의 0 반환을 모든 child의 등록·probe 완료로 해석하지 않는다. on-demand 경로도 deep probe가 지원되지 않으면 작업 없이 0을 반환한다.
STRUCTURE
객체와 주소가 놓이는 구조
입력 node, 생성 가능한 device, 선택적 resource, probe 확인 상태를 역할별로 놓았다. 이 그림은 네 블록을 모두 지나는 직렬 실행 순서가 아니다.
CALL PATH
서로 다른 두 진입 경로
일반: of_platform_populate
- root가 없으면
/를 찾고, 없으면-EINVAL. - 직계 child마다
of_platform_bus_create호출. - compatible·available·AMBA·bus match 조건에 따라 생성·재귀 또는 건너뜀.
결과는 walk의 rc. 모든 node의 device 또는 driver probe 완료를 보장하지 않는다.
요청 시: of_device_ensure_probed(np)
- node가 없거나 deep probe 미지원이면 작업 없이 0.
- 필요 시 parent rescan·재귀 생성 후 요청 node 재확인.
- device와
dev->driver확인: 없으면-EPROBE_DEFER.
요청 node의 성공 여부를 확인하는 별도 호출이다. 일반 walk 뒤에 항상 자동 실행되지 않는다.
platform.c 380–515행: AMBA 장치는 별도 생성 분기이며, 일반 child 재귀는 생성된 device와 bus match가 모두 있을 때만 진행한다.
STATE LEDGER
경로별 조건과 반환 상태
두 함수의 행은 한 번에 모두 통과하는 직렬 목록이 아니다. 일반 walk의 반환값과 요청 node의 probe 확인 결과를 따로 읽는다.
| # | 경로·조건 | 실제 단계 | 남는 상태 / 반환 | 다음 확인 |
|---|---|---|---|---|
| A1 | 일반 · root NULL | of_find_node_by_path("/") | root도 없으면 -EINVAL | root node 존재 |
| A2 | 일반 · 각 직계 child | of_platform_bus_create | compatible 없으면 해당 subtree를 건너뜀 | node compatible |
| A3 | 일반 · 생성 가능 | AMBA 분기 또는 of_platform_device_create | available·기존 np->dev·resource·등록 조건 반영 | device / resource |
| A4 | 일반 · device와 bus match | child 재귀; 아니면 종료 | walk rc 반환; probe 보장 아님 | 실제 방문 범위 |
| B1 | 요청 · NULL 또는 deep 미지원 | of_device_ensure_probed guard | 작업 없이 0; probe 완료 증거 아님 | deep_probe_is_supported |
| B2 | 요청 · 지원됨 | parent rescan / 필요한 parent 재귀 생성 | 기존 np->dev 재사용 또는 device 생성 시도 | parent와 compatible |
| B3 | 요청 · device 확인 | dev->driver 검사 | device·driver가 있으면 0, 아니면 -EPROBE_DEFER | driver bind·probe 결과 |
고정 v2026.06.1 구현에서 일반 population은 선택적 subtree walk이고 deep probe는 요청 시 검증이다.
VISUAL WALKTHROUGH
일반 walk와 on-demand 생성의 경계
각 카드의 번호는 해당 함수 안의 순서다. 그림 3의 끝이 그림 4의 시작을 뜻하지 않는다.
of_platform_populate의 선택적 child walk직계 child에서 시작하고, descendant 재귀는 bus match와 생성 결과에 따라 달라진다.
/ 조회root가 없으면 -EINVAL.
compatible이 없으면 그 subtree를 건너뛴다.
available, 기존 np->dev, resource와 등록 결과를 반영한다.
그 외에는 해당 node에서 멈춘다. driver probe를 일괄 강제하지 않는다.
of_device_ensure_probed의 요청 node 경로요청이 있고 deep probe가 지원될 때 parent를 필요에 따라 준비한 뒤 해당 device의 driver를 확인한다.
이 반환은 device가 probe되었다는 뜻이 아니다.
parent 준비 뒤 요청 node가 이미 생겼으면 재사용한다.
필요하면 AMBA 또는 platform device를 만든다. 실패는 defer.
dev->driver 검사있으면 0, device·driver가 없으면 -EPROBE_DEFER.
UPSTREAM SOURCE
원본 코드
아래 코드는 Barebox v2026.06.1의 drivers/of/platform.c에서 397-485줄을 그대로 가져온 것이다.
397 return 0;
398
399 for_each_child_of_node(node, child) {
400 pr_debug(" create child: %pOF\n", child);
401 rc = of_platform_bus_create(child, matches, dev);
402 if (rc)
403 break;
404 }
405 return rc;
406}
407
408/**
409 * of_platform_populate() - Populate platform_devices from device tree data
410 * @root: parent of the first level to probe or NULL for the root of the tree
411 * @matches: match table, NULL to use the default
412 * @parent: parent to hook devices from, NULL for toplevel
413 *
414 * This function walks the device tree given by @root node and creates devices
415 * from nodes. It requires all device nodes to have a 'compatible' property,
416 * and it is suitable for creating devices which are children of the root
417 * node.
418 *
419 * Returns 0 on success, < 0 on failure.
420 */
421int of_platform_populate(struct device_node *root,
422 const struct of_device_id *matches,
423 struct device *parent)
424{
425 struct device_node *child;
426 int rc = 0;
427
428 if (!root)
429 root = of_find_node_by_path("/");
430 if (!root)
431 return -EINVAL;
432
433 for_each_child_of_node(root, child) {
434 rc = of_platform_bus_create(child, matches, parent);
435 if (rc)
436 break;
437 }
438
439 return rc;
440}
441EXPORT_SYMBOL_GPL(of_platform_populate);
442
443static struct device *of_device_create_on_demand(struct device_node *np)
444{
445 struct device_node *parent;
446 struct device *parent_dev, *dev;
447
448 parent = of_get_parent(np);
449 if (!parent)
450 return NULL;
451
452 if (!np->dev && parent->dev)
453 device_rescan(parent->dev);
454
455 /* Create all parent devices needed for the requested device */
456 parent_dev = parent->dev ? : of_device_create_on_demand(parent);
457 if (IS_ERR(parent_dev))
458 return parent_dev;
459
460 /*
461 * Parent devices like i2c/spi controllers are populating their own
462 * devices. So it can be that the requested device already exists after
463 * the parent device creation.
464 */
465 if (np->dev)
466 return np->dev;
467
468 if (!of_property_present(np, "compatible"))
469 return NULL;
470
471 pr_debug("Creating device for %pOF\n", np);
472
473 if (of_device_is_compatible(np, "arm,primecell"))
474 dev = of_amba_device_create(np);
475 else
476 dev = of_platform_device_create(np, parent_dev);
477
478 return dev ? : ERR_PTR(-EPROBE_DEFER);
479}
480
481/**
482 * of_device_ensure_probed() - ensures that a device is probed
483 *
484 * @np: the device_node handle which should be probed
485 *
READING CONTRACT
발췌 범위와 읽기 기준
원문 397-485줄에는 앞뒤 문맥이 포함됩니다. 기준 구문 int of_platform_populate은 L421에 있습니다. 발췌 첫 줄을 함수 정의의 시작으로 해석하지 않습니다.
원문 발췌는 485행까지다. 요청 node의 최종 dev->driver 검사와 반환 조건은 같은 버전의 487–515행에서 이어진다.
RELATED SOURCE
함께 읽어야 하는 원본 코드
첫 코드 조각만으로 동작이 완성되지 않는 경우 호출 매크로, 객체 정의와 실제 실행 목록을 같은 페이지에 묶었다. 각 조각은 같은 기준 commit에서 가져왔다.
01. DT node에서 resource를 읽어 device를 만드는 함수
drivers/of/platform.c 114-214줄이다.
114}
115
116/**
117 * of_platform_device_create - Alloc, initialize and register an of_device
118 * @np: pointer to node to create device for
119 * @parent: device model parent device.
120 *
121 * Returns pointer to created platform device, or NULL if a device was not
122 * registered. Unavailable devices will not get registered.
123 */
124struct device *of_platform_device_create(struct device_node *np,
125 struct device *parent)
126{
127 struct device *dev;
128 struct resource *res = NULL, temp_res;
129 resource_size_t resinval;
130 int i, ret, num_reg = 0;
131 u32 virt;
132
133 if (!of_device_is_available(np))
134 return NULL;
135
136 /*
137 * Linux uses the OF_POPULATED flag to skip already populated/created
138 * devices.
139 */
140 if (np->dev) {
141 device_rescan(np->dev);
142 return np->dev;
143 }
144
145 /* count the io resources */
146 if (of_can_translate_address(np))
147 while (of_address_to_resource(np, num_reg, &temp_res) == 0)
148 num_reg++;
149
150 /* Populate the resource table */
151 if (num_reg) {
152 res = xzalloc(sizeof(*res) * num_reg);
153 for (i = 0; i < num_reg; i++) {
154 ret = of_address_to_resource(np, i, &res[i]);
155 if (ret) {
156 free(res);
157 return NULL;
158 }
159 }
160 }
161
162 /* setup generic device info */
163 dev = xzalloc(sizeof(*dev));
164 dev->id = DEVICE_ID_SINGLE;
165 dev->of_node = np;
166 dev->parent = parent;
167 dev->resource = res;
168 dev->num_resources = num_reg;
169 of_device_make_bus_id(dev);
170
171 of_dma_configure(dev, np);
172
173 if (num_reg && !of_property_read_u32(np, "virtual-reg", &virt)) {
174 resource_size_t remap_offset = virt - res[0].start;
175
176 for (i = 0; i < num_reg; i++) {
177 void *new_virt = (void *)res[i].start + remap_offset;
178 resource_size_t size = resource_size(&res[i]);
179
180 ret = arch_remap_range(new_virt, res[i].start, size, MAP_UNCACHED);
181 if (!ret) {
182 debug("%s: remap device %s resource %d: %pa -> 0x%p\n",
183 __func__, dev_name(dev), i, &res[i].start, new_virt);
184
185 res[i].start = (resource_size_t)new_virt;
186 res[i].end = res[i].start + size - 1;
187 }
188 }
189 }
190
191 resinval = (-1);
192
193 debug("%s: register device %s, io=%pa\n",
194 __func__, dev_name(dev),
195 (num_reg) ? &dev->resource[0].start : &resinval);
196
197 BUG_ON(np->dev);
198 np->dev = dev;
199
200 ret = platform_device_register(dev);
201 if (ret) {
202 np->dev = NULL;
203 free_device(dev);
204 if (num_reg)
205 free(res);
206 return NULL;
207 }
208
209
210 return dev;
211}
212
213struct driver dummy_driver = {
214 .name = "dummy-driver",
DETAILS
조건별 상태를 소스에서 읽기
두 API의 진입 조건을 분리한다
of_platform_populate는 root가 NULL이면 /를 찾아 child walk를 시작한다. of_device_ensure_probed는 요청 node가 없거나 deep probe가 지원되지 않으면 즉시 0을 반환한다.
후자의 0 반환만으로 driver probe 완료를 판정하지 않는다.
node와 device의 생성 시점을 구분한다
일반 walk는 compatible이 없는 node를 건너뛰고, of_platform_device_create는 unavailable node를 등록하지 않는다. 기존 np->dev가 있으면 rescan 뒤 재사용한다.
on-demand 경로는 필요 시 parent rescan·재귀 생성 뒤 요청 node의 device가 이미 생겼는지 다시 확인한다.
resource는 생성 가능한 node에서만 채운다
of_can_translate_address인 node에서 of_address_to_resource로 I/O resource 개수를 세고 배열을 채운다. virtual-reg가 있으면 remap을 시도한다.
주소 translation 또는 등록 실패 시 해당 함수의 cleanup 경로를 확인한다.
등록과 probe 확인은 다른 결과다
일반 population은 device 생성 뒤 bus match가 있을 때만 child를 재귀 방문하고 walk의 rc를 반환한다. 이 반환값은 모든 descendant의 등록이나 driver probe 완료 증거가 아니다.
요청 node 경로는 device 생성·재사용 뒤 dev->driver가 없으면 -EPROBE_DEFER를 반환한다.
실패와 건너뜀을 구별한다
일반 경로에서 root가 없으면 -EINVAL이지만 compatible이 없거나 device 생성 결과가 NULL인 node는 그 subtree에서 멈추고 다른 child walk를 계속할 수 있다.
on-demand 경로에서 요청 device 생성 실패 또는 driver 부재는 -EPROBE_DEFER다. 설정상 deep probe 미지원은 오류가 아니라 조기 0 반환이다.
IMPLEMENTATION NOTES
조건 분기에서 놓치기 쉬운 부분
compatible과 bus match는 서로 다른 관문이다
compatible이 없는 node는 of_platform_bus_create가 건너뛴다. device가 만들어져도 of_match_node(matches, node)가 맞지 않으면 child 재귀는 없다.
AMBA 장치 생성 성공도 별도 조기 반환 경로다. 소스 365–406행.
resource는 선택적으로 생성되고 정리된다
주소 translation 가능 여부와 reg 항목 수가 resource 배열을 결정한다. 등록 전 np->dev를 지정하지만 등록 실패 시 NULL로 되돌리고 device와 resource를 정리한다.
실제 node의 resource와 devinfo·iomem을 대조한다. 소스 129–209행.
deep probe는 필요한 parent와 요청 device를 확인한다
np->dev가 없고 parent device가 있을 때 device_rescan(parent->dev)을 호출한다. parent device가 없으면 재귀 생성한다. parent controller가 요청 child를 이미 만들 수 있으므로 np->dev를 다시 검사한다.
최종 dev->driver 검사에 실패하면 defer한다. 첫 접근 시간과 probe 수는 이 조건의 선택 결과로 측정한다. 소스 443–515행.
OBJECT LIFETIME
node·device·driver의 상태
| 대상 | 처리 시점 | 코드가 확인하는 상태 | 근거 |
|---|---|---|---|
device_node *np | 두 API 진입 전 DT에 존재 | compatible·available·parent 참조 | bus create |
np->dev | device 생성·등록 또는 기존 device rescan | 등록 실패 시 NULL로 복구; on-demand에서 재사용 검사 | device create |
| resource 배열 | 주소 translation 가능하고 resource가 있으면 생성 | num_reg와 resource; 등록 실패 시 해제 | resource path |
parent_dev | on-demand에서 필요 시 parent rescan·재귀 생성 | 요청 child가 이미 생성됐는지 확인 | parent path |
dev->driver | 요청 device 생성·재사용 뒤 | 있으면 성공 0; 없으면 -EPROBE_DEFER | ensure probed |
FAILURE PATH
건너뜀·오류·조기 반환
| # | 조건 | 소스의 결과 | 먼저 확인할 곳 |
|---|---|---|---|
| 01 | 일반 경로에서 root도 /도 없음 | -EINVAL | of_platform_populate |
| 02 | compatible 없음 / unavailable | 일반 walk에서 해당 node·subtree를 건너뜀 | of_platform_bus_create·device create |
| 03 | device는 있지만 bus match 없음 | 해당 child 재귀 없음; 다른 root child는 계속 처리 가능 | of_match_node |
| 04 | 요청 device 생성 실패 또는 driver 없음 | -EPROBE_DEFER | of_device_ensure_probed |
| 05 | deep probe 미지원 / 요청 node NULL | 작업 없이 0; probe 완료 증거 아님 | deep_probe_is_supported |
일반 population의 0은 순회된 범위의 오류 여부를 말하고, deep probe 경로의 0도 guard에 의해 작업 없이 반환될 수 있다. 호출 조건과 np->dev·dev->driver를 함께 기록한다.
EVIDENCE
소스 밖에서 확인할 증거
소스에서 파악한 동작을 실제 빌드 결과와 대상 보드의 로그로 확인한다. 아래 명령의 보드 이름과 툴체인 접두사는 사용 중인 빌드 환경에 맞게 바꾼다.
| # | 목적 | 명령 또는 계측 | 판정 기준 |
|---|---|---|---|
| 01 | 빌드 구성 | make <board>_defconfig && make V=1 | Kconfig, linker section과 최종 barebox image 생성 명령을 보관한다. |
| 02 | symbol과 section | ${CROSS_COMPILE}nm -n barebox | grep -E 'of_platform_populate|of_device_ensure_probed' | 두 API의 symbol이 대상 빌드에 포함됐는지 확인한다. |
| 03 | 주소와 resource | iomem | 생성된 device의 translated resource와 실제 MMIO 범위를 확인한다. |
| 04 | device 상태 | devinfo; drvinfo; of_dump | DT node 생성, device 등록, driver probe를 서로 구분한다. |
| 05 | 요청 경로 반환값 | GDB/JTAG: of_device_ensure_probed(np) | deep probe 지원 여부, parent·요청 device 상태와 반환값을 기록한다. |
LAB
직접 확인할 실험
- 01같은 node의 DT·device 상태 비교
of_platform_populate전후 같은 child path의np->dev와 compatible·bus match를 비교한다. - 02요청 node의 deep probe 반환값 비교
of_device_ensure_probed호출 전후 요청 node와 parent의 device·driver 상태 및 반환값을 기록한다. - 03ranges가 있는 bus의 translated resource 확인
대표 bus child의
of_address_to_resource결과와 등록된 device resource를 비교한다.
PRIMARY REFERENCES