目录(?)[+] 宋宝华 Barry Song <21cnbao@gmail.com> 1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pain in the ass”,引发ARM Linux社区的地震,随后ARM社区进行了一系列的 重大修正。在过去的ARM Linux中,arch/arm/plat-xxx和arch/arm/mach-xxx中充斥着大量的垃圾代码,相当多数的代码只是在描述板级细节,而这些板级细节对于内核来讲, 不过是垃圾,如板上的platform设备、resource、i2c_board_info、spi_board_info以及各种硬件的platform_data。读者有兴趣可以统计下常见的s3c2410、s3c6410等板级目录,代码量在数万行。 社区必须改变这种局面,于是PowerPC等其他体系架构下已经使用的Flattened Device Tree(FDT)进入ARM社区的视野。Device Tree是一种描述硬件的数据结构,它起源 于 OpenFirmware (OF)。在Linux 2.6中,ARM架构的板极硬件细节过多地被硬编码在arch/arm/plat-xxx和arch/arm/mach-xxx,采用Device Tree后,许多硬件的细节可以直接透过它传递给Linux,而不再需要在kernel中进行大量的冗余编码。 Device Tree由一系列被命名的结点(node)和属性(property)组成,而结点本身可包含子结点。所谓属性,其实就是成对出现的name和value。在Device Tree中,可描述 的信息包括(原先这些信息大多被hard code到kernel中):
01 The 1st cell is the interrupt type; 0 for SPI interrupts, 1 for PPI 02 interrupts. 03 04 The 2nd cell contains the interrupt number for the interrupt type. 05 SPI interrupts are in the range [0-987]. PPI interrupts are in the 06 range [0-15]. 07 08 The 3rd cell is the flags, encoded as follows: 09 bits[3:0] trigger type and level flags. 10 1 = low-to-high edge triggered 11 2 = high-to-low edge triggered 12 4 = active high level-sensitive 13 8 = active low level-sensitive 14 bits[15:8] PPI interrupt cpu mask. Each bit corresponds to each of 15 the 8 possible cpus attached to the GIC. A bit set to '1' indicated 16 the interrupt is wired to that CPU. Only valid for PPI interrupts.