This article provides the code for testing the of functions used for extracting the values of properties.
For related subjects, please refer to the SOC Table of Contents.
The functions we will be testing in chronological order in this section are:
- of_find_property
- of_property_count_elems_of_size
- of_property_read_u32_index
- of_property_read_u8_array
- of_property_read_u16_array
- of_property_read_u32_array
- of_property_read_u64_array
- of_property_read_u8
- of_property_read_u16
- of_property_read_u32
- of_property_read_u64
- of_n_addr_cells
- of_n_size_cells
The code to be inserted into the corresponding section is as follows:
// of_find_property int plen; struct property *test_ofp; test_ofp = of_find_property(of_find_node_by_name(NULL, "test_node1"), "compatible", &plen); printk(KERN_ERR "Compatible property of test_node1 was successfully found via of_find_property \r\n"); printk(KERN_ERR "Property name is: %s \r\n", test_ofp->name); printk(KERN_ERR "\r\n"); // of_property_count_elems_of_size int test_opceos; const char propname[] = "reg"; printk(KERN_ERR "propname = %d \r\n" , sizeof(propname)); test_opceos = of_property_count_elems_of_size(of_find_node_by_name(NULL, "fii-dt-driver"),"compatible", 1); printk(KERN_ERR "Compatible property of test_node1 was successfully found via of_property_count_elems_of_size \r\n"); printk(KERN_ERR "Property element count is: %d \r\n", test_opceos); printk(KERN_ERR "\r\n"); // of_property_read_u32_index u32 oprui_output; int ret = 0; ret = of_property_read_u32_index(of_find_node_by_name(NULL, "test_node1"), "test_array", 0,&oprui_output); printk(KERN_ERR "test_array of test_node1 was successfully found via of_property_read_u32_index \r\n"); printk(KERN_ERR "Property value at index 0 is: ret = %d, 0x%08x\r\n", ret, oprui_output); printk(KERN_ERR "\r\n"); ret = of_property_read_u32_index(of_find_node_by_name(NULL, "test_node1"), "test_array", 1,&oprui_output); printk(KERN_ERR "Property value at index 1 is: ret = %d, 0x%08x\r\n", ret, oprui_output); printk(KERN_ERR "\r\n"); ret = of_property_read_u32_index(of_find_node_by_name(NULL, "test_node1"), "test_array", 2,&oprui_output); printk(KERN_ERR "Property value at index 2 is: ret = %d, 0x%08x\r\n", ret, oprui_output); printk(KERN_ERR "\r\n"); ret = of_property_read_u32_index(of_find_node_by_name(NULL, "test_node1"), "test_array", 3,&oprui_output); printk(KERN_ERR "Property value at index 3 is: ret = %d, 0x%08x\r\n", ret, oprui_output); printk(KERN_ERR "\r\n"); ret = of_property_read_u32_index(of_find_node_by_name(NULL, "test_node1"), "test_array", 4,&oprui_output); printk(KERN_ERR "Property value at index 4 is: ret = %d, 0x%08x\r\n", ret, oprui_output); printk(KERN_ERR "\r\n"); printk(KERN_ERR "\r\n"); printk(KERN_ERR "---------------------------------------------------- \r\n"); printk(KERN_ERR "\r\n"); // of_property_read_u_array size_t elements; int i; // of_property_read_u8_array u8 test_opru8a_out[5]; int test_opru8a; elements = 5; test_opru8a = of_property_read_u8_array(of_find_node_by_name(NULL, "test_node1"),"test_array", test_opru8a_out, elements); printk(KERN_ERR "test_array of test_node1 was successfully found via of_property_read_u8_array \r\n"); for(i = 0; i < elements; i++){ printk(KERN_ERR "Return value : %d \nProperty value is: 0x%02x\r\n", test_opru8a,test_opru8a_out); } printk(KERN_ERR "\r\n"); elements = 5; test_opru8a = of_property_read_u8_array(of_find_node_by_name(NULL, "test_node2"),"u8_test_array", test_opru8a_out, elements); printk(KERN_ERR "u8_test_array of test_node2 was successfully found via of_property_read_u8_array \r\n"); for(i = 0; i < elements; i++){ printk(KERN_ERR "Return value : %d \nProperty value is: 0x%02x\r\n", test_opru8a,test_opru8a_out); } printk(KERN_ERR "\r\n"); // of_property_read_u16_array u16 test_opru16a_out[5]; int test_opru16a; elements = 5; test_opru16a = of_property_read_u16_array(of_find_node_by_name(NULL, "test_node1"),"test_array", test_opru16a_out, elements); printk(KERN_ERR "test_array of test_node1 was successfully found via of_property_read_u16_array \r\n"); for(i = 0; i < elements; i++){ printk(KERN_ERR "Return value : %d \nProperty value is: 0x%04x\r\n", test_opru16a,test_opru16a_out); } printk(KERN_ERR "\r\n"); elements = 5; test_opru16a = of_property_read_u16_array(of_find_node_by_name(NULL, "test_node2"),"u16_test_array", test_opru16a_out, elements); printk(KERN_ERR "u16_test_array of test_node2 was successfully found via of_property_read_u16_array \r\n"); for(i = 0; i < elements; i++){ printk(KERN_ERR "Return value : %d \nProperty value is: 0x%04x\r\n", test_opru16a,test_opru16a_out); } printk(KERN_ERR "\r\n"); // of_property_read_u32_array u32 test_opru32a_out[5]; int test_opru32a; elements = 5; test_opru32a = of_property_read_u32_array(of_find_node_by_name(NULL, "test_node2"),"u32_test_array", test_opru32a_out, elements); printk(KERN_ERR "u32_test_array of test_node2 was successfully found via of_property_read_u32_array \r\n"); for(i = 0; i < elements; i++){ printk(KERN_ERR "Return value : %d \nProperty value is: 0x%06x\r\n", test_opru32a,test_opru32a_out); } printk(KERN_ERR "\r\n"); // of_property_read_u64_array u64 test_opru64a_out[5]; int test_opru64a; elements = 5; test_opru64a = of_property_read_u64_array(of_find_node_by_name(NULL, "test_node2"),"u64_test_array", test_opru64a_out, elements); printk(KERN_ERR "u64_test_array of test_node2 was successfully found via of_property_read_u64_array \r\n"); for(i = 0; i < elements; i++){ printk(KERN_ERR "Return value : %d \nProperty value is: 0x%08x\r\n", test_opru64a,test_opru64a_out); } printk(KERN_ERR "\r\n"); printk(KERN_ERR "\r\n"); printk(KERN_ERR "---------------------------------------------------- \r\n"); printk(KERN_ERR "\r\n"); // of_property_read_u8 u8 test_opru8_out; int test_opru8; test_opru8 = of_property_read_u8(of_find_node_by_name(NULL, "test_node2"), "u8_test_array",&test_opru8_out); printk(KERN_ERR "u8_test_array of test_node2 was successfully found via of_property_read_u8 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%02x\r\n", test_opru8,test_opru8_out); printk(KERN_ERR "\r\n"); test_opru8 = of_property_read_u8(of_find_node_by_name(NULL, "test_node2"), "u8_test",&test_opru8_out); printk(KERN_ERR "u8_test of test_node2 was successfully found via of_property_read_u8 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%02x\r\n", test_opru8,test_opru8_out); printk(KERN_ERR "\r\n"); // of_property_read_u16 u16 test_opru16_out; int test_opru16; test_opru16 = of_property_read_u16(of_find_node_by_name(NULL, "test_node2"),"u16_test_array", &test_opru16_out); printk(KERN_ERR "u16_test_array of test_node2 was successfully found via of_property_read_u16 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%04x\r\n", test_opru16,test_opru16_out); printk(KERN_ERR "\r\n"); test_opru16 = of_property_read_u16(of_find_node_by_name(NULL, "test_node2"), "u16_test",&test_opru16_out); printk(KERN_ERR "u16_test of test_node2 was successfully found via of_property_read_u16 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%04x\r\n", test_opru16,test_opru16_out); printk(KERN_ERR "\r\n"); // of_property_read_u32 u32 test_opru32_out; int test_opru32; test_opru32 = of_property_read_u32(of_find_node_by_name(NULL, "test_node2"),"u32_test_array", &test_opru32_out); printk(KERN_ERR "u32_test_array of test_node2 was successfully found via of_property_read_u32 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%06x\r\n", test_opru32,test_opru32_out); printk(KERN_ERR "\r\n"); test_opru32 = of_property_read_u32(of_find_node_by_name(NULL, "test_node2"), "u32_test",&test_opru32_out); printk(KERN_ERR "u32_test of test_node2 was successfully found via of_property_read_u32 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%06x\r\n", test_opru32,test_opru32_out); printk(KERN_ERR "\r\n"); // of_property_read_u64 u64 test_opru64_out; int test_opru64; test_opru64 = of_property_read_u64(of_find_node_by_name(NULL, "test_node2"),"u64_test_array", &test_opru64_out); printk(KERN_ERR "u64_test_array of test_node2 was successfully found via of_property_read_u64 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%08x\r\n", test_opru64,test_opru64_out); printk(KERN_ERR "\r\n"); test_opru64 = of_property_read_u64(of_find_node_by_name(NULL, "test_node2"), "u64_test",&test_opru64_out); printk(KERN_ERR "u64_test of test_node2 was successfully found via of_property_read_u64 \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: 0x%08x\r\n", test_opru64,test_opru64_out); printk(KERN_ERR "\r\n"); printk(KERN_ERR "---------------------------------------------------- \r\n"); printk(KERN_ERR "\r\n"); // of_property_read_string const char *test_oprs_out; int test_oprs; test_oprs = of_property_read_string(of_find_node_by_name(NULL, "test_node1"), "status",&test_oprs_out); printk(KERN_ERR "status was successfully found via of_property_read_string \r\n"); printk(KERN_ERR "Return value : %d \nProperty value is: %s\r\n", test_oprs, test_oprs_out); printk(KERN_ERR "\r\n"); // of_n_addr_cells int test_onac; test_onac = of_n_addr_cells(of_find_node_by_name(NULL, "fii-dt-driver")); printk(KERN_ERR "Address Cells was successfully found via of_n_addr_cells \r\n"); printk(KERN_ERR "Return value : %d\n", test_onac); printk(KERN_ERR "\r\n"); // of_n_size_cells int test_onsc; test_onsc = of_n_size_cells(of_find_node_by_name(NULL, "fii-dt-driver")); printk(KERN_ERR "Size Cells was successfully found via of_n_size_cells \r\n"); printk(KERN_ERR "Return value : %d\n", test_onsc);