blob: ccd7f76770d9ca314664e8a397a0696d0f275a1a [file] [log] [blame]
Mayank Groverf3b78182017-12-19 13:31:30 +05301
2#ifndef UFDT_UTIL_H
3#define UFDT_UTIL_H
4
5#include "fdt_internal.h"
6#include "ufdt_types.h"
7
8static const char *tag_name(uint32_t tag) {
9 switch (tag) {
10 case FDT_BEGIN_NODE:
11 return "FDT_BEGIN_NODE";
12 case FDT_END_NODE:
13 return "FDT_END_NODE";
14 case FDT_PROP:
15 return "FDT_PROP";
16 case FDT_END:
17 return "FDT_END";
18 }
19 return "";
20}
21
22static const char *get_name(void *fdtp, struct ufdt_node *node) {
23 if (!fdtp || !node) return NULL;
24
25 const struct fdt_node_header *nh;
26 const struct fdt_property *prop;
27
28 uint32_t tag = tag_of(node);
29
30 switch (tag) {
31 case FDT_BEGIN_NODE:
32 nh = (const struct fdt_node_header *)node->fdt_tag_ptr;
33 return nh->name;
34 case FDT_PROP:
35 prop = (const struct fdt_property *)node->fdt_tag_ptr;
36 return fdt_string(fdtp, fdt32_to_cpu(prop->nameoff));
37 default:
38 return "";
39 }
40}
41
42static const void *value_of(const struct ufdt_node *node) {
43 if (!node) {
44 dto_error( "Failed to get value since tree or node is NULL\n");
45 return NULL;
46 }
47 return node->fdt_tag_ptr;
48}
49
50static int get_hash_len(const char *str, int len) {
51 int res = 0;
52 for (int i = 0; i < len; i++) {
53 res = res * HASH_BASE;
54 res = res + str[i];
55 }
56 return res;
57}
58static int get_hash(const char *str) { return get_hash_len(str, dto_strlen(str)); }
59
60#endif /* UFDT_UTIL_H */