File indexing completed on 2025-05-11 08:24:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <tmacros.h>
0033 #include <stdio.h>
0034 #include <stdlib.h>
0035 #include <libfdt.h>
0036 #include <sys/endian.h>
0037 #include <bsp/fdt.h>
0038 #include <ofw/ofw.h>
0039 #include <ofw/ofw_test.h>
0040 #include <rtems/score/isr.h>
0041
0042 #include "some.h"
0043
0044 #define BUF_SIZE 100
0045
0046 const char rtems_test_name[] = "OFW 01";
0047 static const void *test_bin = NULL;
0048
0049 const void *__wrap_bsp_fdt_get(void);
0050 const void *__real_bsp_fdt_get(void);
0051
0052 const void *__wrap_bsp_fdt_get(void)
0053 {
0054 uintptr_t sp;
0055
0056 sp = (uintptr_t) __builtin_frame_address(0);
0057 RTEMS_OBFUSCATE_VARIABLE(sp);
0058
0059
0060
0061
0062
0063 if (
0064 (sp < (uintptr_t) _ISR_Stack_area_begin ||
0065 sp >= (uintptr_t) _ISR_Stack_area_end) &&
0066 test_bin != NULL
0067 ) {
0068 return test_bin;
0069 }
0070
0071 #ifdef BSP_FDT_IS_SUPPORTED
0072 return __real_bsp_fdt_get();
0073 #else
0074 return some_bin;
0075 #endif
0076 }
0077
0078 static void Init(rtems_task_argument arg)
0079 {
0080 int rv;
0081 phandle_t d;
0082 phandle_t l;
0083 phandle_t t;
0084 phandle_t c;
0085 phandle_t a;
0086 phandle_t b;
0087 phandle_t q;
0088 phandle_t root;
0089 phandle_t temp;
0090 uint32_t *arr;
0091 char buf[BUF_SIZE];
0092 char *bufp;
0093 ssize_t buf_len;
0094 rtems_ofw_memory_area reg;
0095 rtems_ofw_memory_area regs[2];
0096 rtems_vector_number intr;
0097 rtems_vector_number intrs[2];
0098 TEST_BEGIN();
0099 buf_len = sizeof(buf);
0100
0101
0102
0103
0104
0105 test_bin = some_bin;
0106 rtems_ofw_init();
0107
0108
0109
0110
0111
0112
0113 root = rtems_ofw_find_device("/");
0114 rtems_test_assert(root == 56);
0115
0116 root = rtems_ofw_peer(0);
0117 rtems_test_assert(root == 56);
0118
0119 d = rtems_ofw_child(root);
0120 temp = rtems_ofw_find_device("/d");
0121 rtems_test_assert(d == temp);
0122
0123 temp = rtems_ofw_parent(d);
0124 rtems_test_assert(root == temp);
0125
0126 rv = rtems_ofw_get_prop(d, "e", buf, buf_len);
0127 rtems_test_assert(rv != -1);
0128 rtems_test_assert(strcmp(buf, "f") == 0);
0129
0130 rv = rtems_ofw_has_prop(d, "g");
0131 rtems_test_assert(rv == 1);
0132
0133 rv = rtems_ofw_get_prop_len(root, "model");
0134 rtems_test_assert(rv == 2);
0135
0136 rv = rtems_ofw_next_prop(d, "e", buf, buf_len);
0137 rtems_test_assert(rv == 1);
0138 rtems_test_assert(strcmp(buf, "g") == 0);
0139
0140 l = rtems_ofw_find_device("/m@1248");
0141 rv = rtems_ofw_search_prop(l, "model", buf, buf_len);
0142 rtems_test_assert(rv != -1);
0143 rtems_test_assert(strcmp(buf, "c") == 0);
0144
0145 rv = rtems_ofw_get_prop_alloc(root, "compatible", (void **)&bufp);
0146 rtems_test_assert(rv != -1);
0147 rtems_test_assert(strcmp(bufp, "a,b") == 0);
0148
0149 rtems_ofw_free(bufp);
0150 rv = rtems_ofw_get_prop_alloc_multi(l, "n", sizeof(*arr), (void **)&arr);
0151 rtems_test_assert(rv == 2);
0152 rtems_test_assert(arr[0] == htobe32(0xdeadbeef));
0153 rtems_test_assert(arr[1] == htobe32(0x12345678));
0154
0155 rv = rtems_ofw_get_enc_prop_alloc_multi(l, "n", sizeof(*arr), (void **)&arr);
0156 rtems_test_assert(rv == 2);
0157 rtems_test_assert(arr[0] == 0xdeadbeef);
0158 rtems_test_assert(arr[1] == 0x12345678);
0159
0160 t = rtems_ofw_find_device("/t");
0161 rv = rtems_ofw_next_prop(t, "u", buf, buf_len);
0162 rtems_test_assert(rv == 0);
0163
0164 rv = rtems_ofw_next_prop(d, "e", buf, buf_len);
0165 rtems_test_assert(rv == 1);
0166
0167 a = rtems_ofw_find_device("/a");
0168 rv = rtems_ofw_get_reg(a, ®, sizeof(reg));
0169 rtems_test_assert(rv == 1);
0170 rtems_test_assert(reg.start == 0x1234);
0171 rtems_test_assert(reg.size == 0x10);
0172
0173 b = rtems_ofw_find_device("/a/b");
0174 rv = rtems_ofw_get_reg(b, ®s[0], sizeof(regs));
0175 rtems_test_assert(rv == 2);
0176 rtems_test_assert(regs[0].start == 0x8234);
0177 rtems_test_assert(regs[0].size == 0x10);
0178 rtems_test_assert(regs[1].start == 0xf468);
0179 rtems_test_assert(regs[1].size == 0x10);
0180
0181 c = rtems_ofw_find_device("/c");
0182 rv = rtems_ofw_get_reg(c, ®, sizeof(reg));
0183 rtems_test_assert(rv == -1);
0184
0185 a = rtems_ofw_find_device("/a");
0186 rv = rtems_ofw_get_interrupts(a, &intr, sizeof(intr));
0187 rtems_test_assert(rv == 1);
0188 rtems_test_assert(intr == 0x1);
0189
0190 c = rtems_ofw_find_device("/c");
0191 rv = rtems_ofw_get_interrupts(c, &intrs[0], sizeof(intrs));
0192 rtems_test_assert(rv == 2);
0193 rtems_test_assert(intrs[0] == 0x1);
0194 rtems_test_assert(intrs[1] == 0x2);
0195
0196 q = rtems_ofw_find_device("/c/q");
0197 rv = rtems_ofw_node_status(q);
0198 rtems_test_assert(rv == true);
0199
0200 TEST_END();
0201 test_bin = NULL;
0202 rtems_test_exit(0);
0203 }
0204
0205 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0206 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0207
0208 #define CONFIGURE_MAXIMUM_TASKS 1
0209
0210 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0211
0212 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0213
0214 #define CONFIGURE_INIT
0215
0216 #include <rtems/confdefs.h>