]> git.sur5r.net Git - u-boot/blob - lib/libfdt/libfdt.swig
Merge branch 'master' of git://git.denx.de/u-boot-sh
[u-boot] / lib / libfdt / libfdt.swig
1 /* File: libfdt.i */
2 %module libfdt
3
4 %{
5 #define SWIG_FILE_WITH_INIT
6 #include "libfdt.h"
7 %}
8
9 %pythoncode %{
10 def Raise(errnum):
11     raise ValueError('Error %s' % fdt_strerror(errnum))
12
13 def Name(fdt, offset):
14     name, len = fdt_get_name(fdt, offset)
15     return name
16
17 def String(fdt, offset):
18     offset = fdt32_to_cpu(offset)
19     name = fdt_string(fdt, offset)
20     return name
21
22 def swap32(x):
23     return (((x << 24) & 0xFF000000) |
24             ((x <<  8) & 0x00FF0000) |
25             ((x >>  8) & 0x0000FF00) |
26             ((x >> 24) & 0x000000FF))
27
28 def fdt32_to_cpu(x):
29     return swap32(x)
30
31 def Data(prop):
32     set_prop(prop)
33     return get_prop_data()
34 %}
35
36 %include "typemaps.i"
37 %include "cstring.i"
38
39 %typemap(in) void* = char*;
40
41 typedef int fdt32_t;
42
43 struct fdt_property {
44         fdt32_t tag;
45         fdt32_t len;
46         fdt32_t nameoff;
47         char data[0];
48 };
49
50 /*
51  * This is a work-around since I'm not sure of a better way to copy out the
52  * contents of a string. This is used in dtoc/GetProps(). The intent is to
53  * pass in a pointer to a property and access the data field at the end of
54  * it. Ideally the Data() function above would be able to do this directly,
55  * but I'm not sure how to do that.
56  */
57 #pragma SWIG nowarn=454
58 %inline %{
59     static struct fdt_property *cur_prop;
60
61     void set_prop(struct fdt_property *prop) {
62         cur_prop = prop;
63     }
64 %}
65
66 %cstring_output_allocate_size(char **s, int *sz, free(*$1));
67 %inline %{
68     void get_prop_data(char **s, int *sz) {
69         *sz = fdt32_to_cpu(cur_prop->len);
70         *s = (char *)malloc(*sz);
71         if (!*s)
72             *sz = 0;
73         else
74             memcpy(*s, cur_prop + 1, *sz);
75     }
76 %}
77
78 const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen);
79 int fdt_path_offset(const void *fdt, const char *path);
80 int fdt_first_property_offset(const void *fdt, int nodeoffset);
81 int fdt_next_property_offset(const void *fdt, int offset);
82 const char *fdt_strerror(int errval);
83 const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
84                                                       int offset,
85                                                       int *OUTPUT);
86 const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT);
87 const char *fdt_string(const void *fdt, int stroffset);
88 int fdt_first_subnode(const void *fdt, int offset);
89 int fdt_next_subnode(const void *fdt, int offset);