@ -40,37 +40,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
return fdt32_to_cpu(*val);
return fdt32_to_cpu(*val);
}
}
/**
int fdt_overlay_target_offset(const void *fdt, const void *fdto,
* overlay_get_target - retrieves the offset of a fragment's target
int fragment_offset, char const **pathp)
* @fdt: Base device tree blob
* @fdto: Device tree overlay blob
* @fragment: node offset of the fragment in the overlay
* @pathp: pointer which receives the path of the target (or NULL)
*
* overlay_get_target() retrieves the target offset in the base
* device tree of a fragment, no matter how the actual targeting is
* done (through a phandle or a path)
*
* returns:
* the targeted node offset in the base device tree
* Negative error code on error
*/
static int overlay_get_target(const void *fdt, const void *fdto,
int fragment, char const **pathp)
{
{
uint32_t phandle;
uint32_t phandle;
const char *path = NULL;
const char *path = NULL;
int path_len = 0, ret;
int path_len = 0, ret;
/* Try first to do a phandle based lookup */
/* Try first to do a phandle based lookup */
phandle = overlay_get_target_phandle(fdto, fragment);
phandle = overlay_get_target_phandle(fdto, fragment_offset);
if (phandle == (uint32_t)-1)
if (phandle == (uint32_t)-1)
return -FDT_ERR_BADPHANDLE;
return -FDT_ERR_BADPHANDLE;
/* no phandle, try path */
/* no phandle, try path */
if (!phandle) {
if (!phandle) {
/* And then a path based lookup */
/* And then a path based lookup */
path = fdt_getprop(fdto, fragment, "target-path", &path_len);
path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len);
if (path)
if (path)
ret = fdt_path_offset(fdt, path);
ret = fdt_path_offset(fdt, path);
else
else
@ -636,7 +621,7 @@ static int overlay_merge(void *fdt, void *fdto)
if (overlay < 0)
if (overlay < 0)
return overlay;
return overlay;
target = overlay_get_target(fdt, fdto, fragment, NULL);
target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL);
if (target < 0)
if (target < 0)
return target;
return target;
@ -779,7 +764,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)
return -FDT_ERR_BADOVERLAY;
return -FDT_ERR_BADOVERLAY;
/* get the target of the fragment */
/* get the target of the fragment */
ret = overlay_get_target(fdt, fdto, fragment, &target_path);
ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
if (ret < 0)
if (ret < 0)
return ret;
return ret;
target = ret;
target = ret;
@ -801,7 +786,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)
if (!target_path) {
if (!target_path) {
/* again in case setprop_placeholder changed it */
/* again in case setprop_placeholder changed it */
ret = overlay_get_target(fdt, fdto, fragment, &target_path);
ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path);
if (ret < 0)
if (ret < 0)
return ret;
return ret;
target = ret;
target = ret;