DTS是Linux下對於設備資源的一種描述方式,相對於之前platform的描述方式,可以大大節省Linux內核代碼,主要是驅動描述方面。
DTS文件將被編譯成DTB文件,與編譯生成的kernel文件打包在一起,一般放在頭部。
kernel在加載時,會將dtb文件導入到內存,驅動代碼使用標準的API訪問dtb資源並加載驅動。
以下是openwrt中對於dtb的分析:
1. dtb相關patch : 0103-OWRTDTB.patch
head.s 加入16KB的dtb空間
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -86,6 +86,9 @@ EXPORT(__image_cmdline)
.fill 0x400
#endif /* CONFIG_IMAGE_CMDLINE_HACK */
+ .ascii "OWRTDTB:"
+ EXPORT(__image_dtb)
+ .fill 0x4000
__REF
2. 打包
3. 啓動加載
--- a/arch/mips/ralink/of.c
+++ b/arch/mips/ralink/of.c
@@ -66,6 +66,8 @@ static int __init early_init_dt_find_mem
return 0;
}
+extern struct boot_param_header __image_dtb;
+
void __init plat_mem_setup(void)
{
set_io_port_base(KSEG1);
@@ -74,7 +76,7 @@ void __init plat_mem_setup(void)
* Load the builtin devicetree. This causes the chosen node to be
* parsed resulting in our memory appearing
*/
- __dt_setup_arch(__dtb_start);
+ __dt_setup_arch(&__image_dtb);