此文章将提供可以用于测试其他常用的 of 函数成功运行的代码。
相关参考文章:SOC 教学教案
将测试的函数如下:
- of_device_is_compatible
- of_get_adddress
- of_translate_address
- of_address_to_resource
- of_iomap
相应部分将填入的代码如下:
// of_device_is_compatible int test_odic; test_odic = of_device_is_compatible(of_find_node_by_name(NULL, "fii-dt-driver"), "fii,fii-dt-driver"); printk(KERN_ERR "Compatible was successfully found via of_device_is_compatible \r\n"); printk(KERN_ERR "Return value : %d\n", test_odic); printk(KERN_ERR "\r\n"); // of_get_address const __be32 *test_oga; u64 test_oga_size; test_oga = of_get_address(of_find_node_by_name(NULL, "fii-dt-driver"), 0, &test_oga_size,NULL); printk(KERN_ERR "Address was successfully found via of_get_address \r\n"); printk(KERN_ERR "Return value : 0x%08x\n", test_oga); printk(KERN_ERR "\r\n"); // of_translate_address u64 test_ota; test_ota = of_translate_address(of_find_node_by_name(NULL, "fii-dt-driver"), test_oga); printk(KERN_ERR "Address was successfully translated via of_translate_address \r\n"); printk(KERN_ERR "Return value : 0x%08x\n", test_ota); printk(KERN_ERR "\r\n"); // of_address_to_resource int test_oatr; struct resource res; test_oatr = of_address_to_resource(of_find_node_by_name(NULL, "fii-dt-driver"), 0, &res); printk(KERN_ERR "Resource was successfully transfered via of_address_to_resource \n"); printk(KERN_ERR "Return value: %d \nProperty value is: 0x%08x\n", test_oatr, res); printk(KERN_ERR "\r\n"); // of_iomap void __iomem *test_oi; test_oi = of_iomap(of_find_node_by_name(NULL, "fii-dt-driver"), 0); printk(KERN_ERR "Mapping was successful via of_iomap \n"); printk(KERN_ERR "Return value: 0x%08x\n", test_oi);