Is there a way to modify the device tree on a live system?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Is there a way to modify the device tree on a live system?

跳至解决方案
1,408 次查看
chillinwithscb
Contributor III

i.MX8M nano

yocto Linux

I'd like to test device tree changes without going through a build process. Is there a way to modify device-tree settings on a live system?

This https://developer.ridgerun.com/wiki/index.php/Edit_device_tree_at_run_time mentions tools for doing what I want, but they are not installed on the nano and I doubt they could be without rebuilding the kernel.

标记 (2)
0 项奖励
回复
1 解答
1,381 次查看
gidame
Contributor III

If the "live" you mean is runtime , then the following documents give a good demonstration of how to modify dtb at runtime under u-boot. The document also includes using dtc to modify dtb files. I have tested all of these according to the document, and they are all feasible.

https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/u-boot-runtime-modify-Linux-device-tree-...


https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Device-Tree-Standalone-Compile-under-Win...

Moreover, the code of nxp's u-boot itself uses this technology. For example, the following code reads the fuse to know the number of cores of the chip and modifies the dtb file at runtime. There are a lot of such codes in this file.

https://github.com/nxp-imx/uboot-imx/blob/lf-6.6.52-2.2.0/arch/arm/mach-imx/imx8m/soc.c

 

	if (is_imx8md())
		disable_cpu_nodes(blob, 2);

#elif defined(CONFIG_IMX8MM)
	if (is_imx8mml() || is_imx8mmdl() ||  is_imx8mmsl())
		disable_vpu_nodes(blob);

	if (is_imx8mmd() || is_imx8mmdl())
		disable_cpu_nodes(blob, 2);
	else if (is_imx8mms() || is_imx8mmsl())
		disable_cpu_nodes(blob, 3);
		
		
static int disable_cpu_nodes(void *blob, u32 disabled_cores)
{
	static const char * const nodes_path[] = {
		"/cpus/cpu@1",
		"/cpus/cpu@2",
		"/cpus/cpu@3",
	};
	u32 i = 0;
	int rc;
	int nodeoff;

	if (disabled_cores > 3)
		return -EINVAL;

	i = 3 - disabled_cores;

	for (; i < 3; i++) {
		nodeoff = fdt_path_offset(blob, nodes_path[i]);
		if (nodeoff < 0)
			continue; /* Not found, skip it */

		debug("Found %s node\n", nodes_path[i]);

		rc = fdt_del_node(blob, nodeoff);
		if (rc < 0) {
			printf("Unable to delete node %s, err=%s\n",
			       nodes_path[i], fdt_strerror(rc));
		} else {
			printf("Delete node %s\n", nodes_path[i]);
		}
	}

	disable_thermal_cpu_nodes(blob, disabled_cores);
	disable_pmu_cpu_nodes(blob, disabled_cores);

	return 0;
}

 

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,382 次查看
gidame
Contributor III

If the "live" you mean is runtime , then the following documents give a good demonstration of how to modify dtb at runtime under u-boot. The document also includes using dtc to modify dtb files. I have tested all of these according to the document, and they are all feasible.

https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/u-boot-runtime-modify-Linux-device-tree-...


https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Device-Tree-Standalone-Compile-under-Win...

Moreover, the code of nxp's u-boot itself uses this technology. For example, the following code reads the fuse to know the number of cores of the chip and modifies the dtb file at runtime. There are a lot of such codes in this file.

https://github.com/nxp-imx/uboot-imx/blob/lf-6.6.52-2.2.0/arch/arm/mach-imx/imx8m/soc.c

 

	if (is_imx8md())
		disable_cpu_nodes(blob, 2);

#elif defined(CONFIG_IMX8MM)
	if (is_imx8mml() || is_imx8mmdl() ||  is_imx8mmsl())
		disable_vpu_nodes(blob);

	if (is_imx8mmd() || is_imx8mmdl())
		disable_cpu_nodes(blob, 2);
	else if (is_imx8mms() || is_imx8mmsl())
		disable_cpu_nodes(blob, 3);
		
		
static int disable_cpu_nodes(void *blob, u32 disabled_cores)
{
	static const char * const nodes_path[] = {
		"/cpus/cpu@1",
		"/cpus/cpu@2",
		"/cpus/cpu@3",
	};
	u32 i = 0;
	int rc;
	int nodeoff;

	if (disabled_cores > 3)
		return -EINVAL;

	i = 3 - disabled_cores;

	for (; i < 3; i++) {
		nodeoff = fdt_path_offset(blob, nodes_path[i]);
		if (nodeoff < 0)
			continue; /* Not found, skip it */

		debug("Found %s node\n", nodes_path[i]);

		rc = fdt_del_node(blob, nodeoff);
		if (rc < 0) {
			printf("Unable to delete node %s, err=%s\n",
			       nodes_path[i], fdt_strerror(rc));
		} else {
			printf("Delete node %s\n", nodes_path[i]);
		}
	}

	disable_thermal_cpu_nodes(blob, disabled_cores);
	disable_pmu_cpu_nodes(blob, disabled_cores);

	return 0;
}

 

 

0 项奖励
回复
1,367 次查看
chillinwithscb
Contributor III

Yes, live system, at runtime. I didn't want to build since that has been problematic for me. Actually, I did build as standalone, but I don't know how to get the DT onto the device without reinstalling the kernel image which has also been problematic for me.

The uboot tool is the sort of thing I was hoping for. I can modify just the DT without touching anything else.

Thanks.

 

0 项奖励
回复
1,393 次查看
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @chillinwithscb 

 

For the i.MX processors,  the Device tree is loaded from the bootloader "U-boot", when Linux kernel boots, the device tree was loaded.

You can install the device-tree-compiler tool for yocto adding the below line in /conf/local.conf:

CORE_IMAGE_EXTRA_INSTALL += "dtc"

 

Then, recompile it. 

But this just will allow to you to compile device trees in the platform.

 

The only way at moment is to rebuild device tree, this is quick in an Standalone environment, you can see this post in step 7.

 

I hpe this information can helps to you.

 

Best regards,

Salas.

0 项奖励
回复
1,366 次查看
chillinwithscb
Contributor III

Interesting, but it involves building Linux which I'm trying to avoid (for the time being).

0 项奖励
回复