<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 18, 2020 at 8:26 PM Christian Mauderer <<a href="mailto:oss@c-mauderer.de">oss@c-mauderer.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 18/08/2020 11:25, Niteesh G. S. wrote:<br>
> How can we make this API FreeBSD compatible? We have to declare<br>
> defines for the OFW functions<br>
> Eg. #define OF_finddevice rtems_ofw_find_device<br>
<br>
I think that was the plan, wasn't it?<br></blockquote><div> </div><div><span class="gmail_default" style="font-size:small">Is everyone OK with this? I am going to start working on it. </span>I would like to</div><div>get at least one of my patches merge ready<span class="gmail_default" style="font-size:small"> </span><span class="gmail_default">before GSoC ends.</span> </div><div><div class="gmail_default" style="font-size:small">My other patches are somewhat dependent on this patch so I want to get</div><div class="gmail_default" style="font-size:small">this fixed first.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I also have a few questions now. If we do this change in libBSD and what</div><div class="gmail_default" style="font-size:small">about the imported drivers present in RTEMS? They have to define these</div><div class="gmail_default" style="font-size:small">translations locally in the driver itself. Or we should move openfirm.h into</div><div class="gmail_default" style="font-size:small">RTEMS. Both have their own problems. The first one will create a lot of</div><div class="gmail_default" style="font-size:small">redundant code And the second one has the following problems.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">1) Where to place openfirm.h in RTEMS?</div><div class="gmail_default" style="font-size:small">2) What about functions like OF_device_from_xref etc?</div><div class="gmail_default" style="font-size:small">These functions depend on the libBSD device struct one hack is to forward</div><div class="gmail_default" style="font-size:small">declare these in the openfirm.h implemented in RTEMS. Is everyone OK</div><div class="gmail_default" style="font-size:small">with this or is there any better solution to this?</div><div class="gmail_default" style="font-size:small">3) We also modify the interface is that fine with BSD-4 license?</div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> <br>
> Should I change the openfirm.h in libBSD to this use these defines instead<br>
> of calling the functions in openfirm.c? Though there are some<br>
> functions which<br>
> for which this cannot be done.<br>
> Eg: OF_device_from_xref<br>
> For this, we will have to use the implementation present in openfirm.c<br>
<br>
At least as long as no one implements a replacement, yes.<br>
<br>
> <br>
> <br>
> On Tue, Aug 18, 2020 at 7:57 AM Chris Johns <<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a><br>
> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>>> wrote:<br>
> <br>
> On 17/8/20 2:57 pm, Niteesh G. S. wrote:<br>
> > On Mon, Aug 17, 2020 at 3:49 AM Chris Johns <<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a><br>
> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>><br>
> > <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>>>> wrote:<br>
> ><br>
> > On 16/8/20 11:19 pm, Niteesh G. S. wrote:<br>
> > ><br>
> > > On Sun, Aug 16, 2020 at 2:25 PM Chris Johns<br>
> <<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>><br>
> > <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>>><br>
> > > <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>><br>
> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a> <mailto:<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>>>>> wrote:<br>
> > ><br>
> > > On 16/8/20 4:49 am, G S Niteesh Babu wrote:<br>
> > > > ---<br>
> > ><br>
> > > > +<br>
> > > > +#ifdef HAVE_CONFIG_H<br>
> > > > +#include "config.h"<br>
> > > > +#endif<br>
> > > > +<br>
> > > > +#include <bsp/fdt.h><br>
> > > > +#include <sys/param.h><br>
> > > > +#include <ofw/ofw.h><br>
> > > > +#include <libfdt.h><br>
> > > > +#include <assert.h><br>
> > > > +#include <rtems/sysinit.h><br>
> > > > +<br>
> > > > +const void *fdtp = NULL;<br>
> > > > +<br>
> > > > +static phandle_t rtems_fdt_offset_to_phandle( int<br>
> offset )<br>
> > > > +{<br>
> > > > + if (offset < 0) {<br>
> > > > + return 0;<br>
> > > > + }<br>
> > > > +<br>
> > > > + return (phandle_t)offset + fdt_off_dt_struct(fdtp);<br>
> > > > +}<br>
> > > > +<br>
> > > > +static int rtems_fdt_phandle_to_offset( phandle_t<br>
> handle )<br>
> > > > +{<br>
> > > > + int off;<br>
> > > > + int fdt_off;<br>
> > > > +<br>
> > > > + off = (int) handle;<br>
> > > > + fdt_off = fdt_off_dt_struct(fdtp);<br>
> > > > +<br>
> > > > + if (off < fdt_off) {<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + }<br>
> > > > +<br>
> > > > + return off - fdt_off;<br>
> > > > +}<br>
> > > > +<br>
> > > > +static void rtems_ofw_init( void ) {<br>
> > > > + int rv;<br>
> > > > + const void *fdt;<br>
> > > > + <br>
> > > > + fdt = bsp_fdt_get();<br>
> > > > +<br>
> > > > + rv = fdt_check_header(fdt);<br>
> > > > +<br>
> > > > + /*<br>
> > > > + * Is assert a good option to handle error?<br>
> > > > + * AFIAK there is no other way to recover from<br>
> invalid FDT.<br>
> > > > + * On providing an invalid FDT most driver's will<br>
> fail/crash anyway.<br>
> > > > + */<br>
> > ><br>
> > > If you want to fail with an error I suggest a documented<br>
> internal error. I<br>
> > > however would prefer we fail in degraded manner but I<br>
> understand this<br>
> > may not be<br>
> > > possible.<br>
> > ><br>
> > ><br>
> > > During the initial discussion, we discussed adding a new<br>
> error code in<br>
> > case of an<br>
> > > invalid FDT, something like BSP_INVALID_FDT. I had also sent<br>
> a patch but<br>
> > then we<br>
> > > decided not to add one(for some reason that I don't<br>
> remember). Instead, use<br>
> > > RTEMS_NOT_CONFIGURED. This has also been used in my previous<br>
> OFW patch.<br>
> ><br>
> > I am sorry I missed the discussion or I would have commented.<br>
> Currently the FDT<br>
> > support in RTEMS is hostile. If you build a u-boot image and<br>
> forget to add FDT<br>
> > support added you get a low level crash dump and that is<br>
> unfriendly. I woud like<br>
> > to this changed.<br>
> ><br>
> > So should we add a proper fatal code in case of invalid FDT or FDT<br>
> is not provided?<br>
> > ARM, POWERPC and RISCV are the only architectures in RTEMS that<br>
> use FDT.<br>
> > Can we add an FDT check inside start.S before bsp_fdt_copy? and<br>
> fail properly in<br>
> > case of an invalid FDT.<br>
> > Or is it a better idea to add the check inside bsp_fdt_copy but<br>
> bsp_fdt_copy is<br>
> > optional<br>
> > in architectures like ARM, RISCV it is compile time guarded with<br>
> > BSP_START_COPY_FDT_FROM_UBOOT<br>
> <br>
> The crash only happens when you run libbsd so I feel the issue is in<br>
> there. If<br>
> support has been added to libbsd for FDT for a specific arch and BSP<br>
> then the<br>
> libbsd start up (or what ever) needs to handle the the lack of FDT<br>
> support in a<br>
> better manner than a crash. This could a console message and an<br>
> `exit()` or a<br>
> fatal RTEMS error. I am not sure.<br>
> <br>
> I do not want to stall this work for this issue if it can be<br>
> resolved else<br>
> where. What is not clear to me is how this can be resolved at a<br>
> system level and<br>
> I would like to see libbsd cleaned up and made a little friendlier<br>
> for FDT<br>
> support but that is not what this effort is about. I am not across<br>
> all the<br>
> detail to know what is needed so I hope others will help here.<br>
> <br>
> Chris<br>
> <br>
> ><br>
> > > So should we add a new error code like BSP_INVALID_FDT and<br>
> fatal exit or just<br>
> > > use RTEMS_NOT_CONIGURED like the previous patch?<br>
> ><br>
> > Not configured is fine with me.<br>
> ><br>
> > Chris<br>
> > ><br>
> > ><br>
> > > > + assert(rv == 0);<br>
> > ><br>
> > > I would prefer we did not make this code dependent on<br>
> -DNDEBUG.<br>
> > ><br>
> > > Chris<br>
> > ><br>
> > > > +<br>
> > > > + fdtp = fdt;<br>
> > > > +}<br>
> > > > +<br>
> > > > +RTEMS_SYSINIT_ITEM(<br>
> > > > + rtems_ofw_init,<br>
> > > > + RTEMS_SYSINIT_BSP_PRE_DRIVERS,<br>
> > > > + RTEMS_SYSINIT_ORDER_FIRST<br>
> > > > +);<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_peer( phandle_t node )<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > +<br>
> > > > + if (node == 0) {<br>
> > > > + int root = fdt_path_offset(fdtp, "/");<br>
> > > > + return rtems_fdt_offset_to_phandle(root);<br>
> > > > + }<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > + if (offset < 0) {<br>
> > > > + return 0;<br>
> > > > + }<br>
> > > > +<br>
> > > > + offset = fdt_next_subnode(fdtp, offset);<br>
> > > > + return rtems_fdt_offset_to_phandle(offset);<br>
> > > > +}<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_child( phandle_t node )<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + if (offset < 0) {<br>
> > > > + return 0;<br>
> > > > + }<br>
> > > > +<br>
> > > > + offset = fdt_first_subnode(fdtp, offset);<br>
> > > > + return rtems_fdt_offset_to_phandle(offset);<br>
> > > > +}<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_parent( phandle_t node )<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + if (offset < 0) {<br>
> > > > + return 0;<br>
> > > > + }<br>
> > > > +<br>
> > > > + offset = fdt_parent_offset(fdtp, offset);<br>
> > > > + return rtems_fdt_offset_to_phandle(offset);<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_prop_len(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > + int len;<br>
> > > > + const void *prop;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + if (offset < 0) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + prop = fdt_getprop(fdtp, offset, propname, &len);<br>
> > > > +<br>
> > > > + if (prop == NULL && strcmp(propname, "name") == 0) {<br>
> > > > + fdt_get_name(fdtp, offset, &len);<br>
> > > > + return len + 1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (prop == NULL && strcmp(propname, "/chosen") == 0) {<br>
> > > > + if (strcmp(propname, "fdtbootcpu") == 0)<br>
> > > > + return sizeof(pcell_t);<br>
> > > > + if (strcmp(propname, "fdtmemreserv") == 0)<br>
> > > > + return 2 * sizeof(uint64_t) *<br>
> fdt_num_mem_rsv(fdtp);<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (prop == NULL) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + return len;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + void *buf,<br>
> > > > + size_t bufsize<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > + int len;<br>
> > > > + const void *prop;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + if (offset < 0) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + prop = fdt_getprop(fdtp, offset, propname, &len);<br>
> > > > +<br>
> > > > + if (prop == NULL && strcmp(propname, "name") == 0) {<br>
> > > > + fdt_get_name(fdtp, offset, &len);<br>
> > > > + return len + 1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (prop == NULL && strcmp(propname, "/chosen") == 0) {<br>
> > > > + if (strcmp(propname, "fdtbootcpu") == 0)<br>
> > > > + return sizeof(pcell_t);<br>
> > > > + if (strcmp(propname, "fdtmemreserv") == 0)<br>
> > > > + return 2 * sizeof(uint64_t) *<br>
> fdt_num_mem_rsv(fdtp);<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (prop == NULL) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + bcopy(prop, buf, MIN(len, bufsize));<br>
> > > > +<br>
> > > > + return len;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_enc_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *prop,<br>
> > > > + pcell_t *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t rv;<br>
> > > > +<br>
> > > > + assert(len % 4 == 0);<br>
> > > > + rv = rtems_ofw_get_prop(node, prop, buf, len);<br>
> > > > +<br>
> > > > + if (rv < 0) {<br>
> > > > + return rv;<br>
> > > > + }<br>
> > > > +<br>
> > > > + for (int i = 0; i < (len / 4); i++) {<br>
> > > > + buf[i] = fdt32_to_cpu(buf[i]);<br>
> > > > + }<br>
> > > > +<br>
> > > > + return rv;<br>
> > > > +}<br>
> > > > +<br>
> > > > +int rtems_ofw_has_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t rv;<br>
> > > > +<br>
> > > > + rv = rtems_ofw_get_prop_len(node, propname);<br>
> > > > + return rv >= 0 ? 1 : 0;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_search_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + void *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t rv;<br>
> > > > +<br>
> > > > + for (; node != 0; node = rtems_ofw_parent(node)) {<br>
> > > > + if ((rv = rtems_ofw_get_prop(node, propname, buf,<br>
> len) != -1)) {<br>
> > > > + return rv;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return -1;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_search_enc_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + pcell_t *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t rv;<br>
> > > > +<br>
> > > > + for (; node != 0; node = rtems_ofw_parent(node)) {<br>
> > > > + if ((rv = rtems_ofw_get_enc_prop(node, propname,<br>
> buf, len) !=<br>
> > -1)) {<br>
> > > > + return rv;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return -1;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_prop_alloc(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + void **buf<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t len;<br>
> > > > +<br>
> > > > + if ((len = rtems_ofw_get_prop_len(node, propname))<br>
> == -1) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + *buf = NULL;<br>
> > > > +<br>
> > > > + if (len > 0) {<br>
> > > > + *buf = malloc(len);<br>
> > > > +<br>
> > > > + if (rtems_ofw_get_prop(node, propname, *buf, len)<br>
> == -1) {<br>
> > > > + rtems_ofw_free(buf);<br>
> > > > + *buf = NULL;<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return len;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_prop_alloc_multi(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + int elsz,<br>
> > > > + void **buf<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t len;<br>
> > > > +<br>
> > > > + if ((len = rtems_ofw_get_prop_len(node, propname))<br>
> == -1 ||<br>
> > > > + (len % elsz != 0)) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + *buf = NULL;<br>
> > > > +<br>
> > > > + if (len > 0) {<br>
> > > > + *buf = malloc(len);<br>
> > > > +<br>
> > > > + if (rtems_ofw_get_prop(node, propname, *buf, len)<br>
> == -1) {<br>
> > > > + rtems_ofw_free(buf);<br>
> > > > + *buf = NULL;<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return (len / elsz);<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_enc_prop_alloc(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + void **buf<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t len;<br>
> > > > +<br>
> > > > + if ((len = rtems_ofw_get_prop_len(node, propname))<br>
> == -1) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + *buf = NULL;<br>
> > > > +<br>
> > > > + if (len > 0) {<br>
> > > > + *buf = malloc(len);<br>
> > > > +<br>
> > > > + if (rtems_ofw_get_enc_prop(node, propname, *buf,<br>
> len) == -1) {<br>
> > > > + rtems_ofw_free(buf);<br>
> > > > + *buf = NULL;<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return len;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_get_enc_prop_alloc_multi(<br>
> > > > + phandle_t node,<br>
> > > > + const char *propname,<br>
> > > > + int elsz,<br>
> > > > + void **buf<br>
> > > > +)<br>
> > > > +{<br>
> > > > + size_t len;<br>
> > > > +<br>
> > > > + if ((len = rtems_ofw_get_prop_len(node, propname))<br>
> == -1 ||<br>
> > > > + (len % elsz != 0)) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + *buf = NULL;<br>
> > > > +<br>
> > > > + if (len > 0) {<br>
> > > > + *buf = malloc(len);<br>
> > > > +<br>
> > > > + if (rtems_ofw_get_enc_prop(node, propname, *buf,<br>
> len) == -1) {<br>
> > > > + rtems_ofw_free(buf);<br>
> > > > + *buf = NULL;<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return (len / elsz);<br>
> > > > +}<br>
> > > > +<br>
> > > > +void rtems_ofw_free( void *buf )<br>
> > > > +{<br>
> > > > + free(buf);<br>
> > > > +}<br>
> > > > +<br>
> > > > +int rtems_ofw_next_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *previous,<br>
> > > > + char *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + const void *name;<br>
> > > > + const void *prop;<br>
> > > > + int offset;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + if (offset < 0) {<br>
> > > > + return -1;<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (previous == NULL) {<br>
> > > > + offset = fdt_first_property_offset(fdtp, offset);<br>
> > > > + } else {<br>
> > > > + fdt_for_each_property_offset(offset, fdtp, offset) {<br>
> > > > + prop = fdt_getprop_by_offset(fdtp, offset,<br>
> (const char<br>
> > **)&name, NULL);<br>
> > > > + if (prop == NULL)<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + if (strcmp(previous, name) != 0)<br>
> > > > + continue;<br>
> > > > +<br>
> > > > + offset = fdt_next_property_offset(fdtp, offset);<br>
> > > > + break;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (offset < 0)<br>
> > > > + return 0;<br>
> > > > +<br>
> > > > + prop = fdt_getprop_by_offset(fdtp, offset, (const<br>
> char **)&name,<br>
> > &offset);<br>
> > > > + if (prop == NULL)<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + strncpy(buf, name, len);<br>
> > > > +<br>
> > > > + return 1;<br>
> > > > +}<br>
> > > > +<br>
> > > > +int rtems_ofw_set_prop(<br>
> > > > + phandle_t node,<br>
> > > > + const char *name,<br>
> > > > + const void *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + if (offset < 0)<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + if (fdt_setprop_inplace(fdtp, offset, name, buf,<br>
> len) != 0)<br>
> > > > + return (fdt_setprop(fdtp, offset, name, buf, len));<br>
> > > > +<br>
> > > > + return 0;<br>
> > > > +}<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_find_device( const char *path )<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > +<br>
> > > > + offset = fdt_path_offset(fdtp, path);<br>
> > > > + if (offset < 0)<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + return rtems_fdt_offset_to_phandle(offset);<br>
> > > > +}<br>
> > > > +<br>
> > > > +static phandle_t rtems_ofw_get_effective_phandle(<br>
> > > > + phandle_t node,<br>
> > > > + phandle_t xref<br>
> > > > +)<br>
> > > > +{<br>
> > > > + phandle_t child;<br>
> > > > + phandle_t ref;<br>
> > > > +<br>
> > > > + for (child = rtems_ofw_child(node); child != 0; child =<br>
> > > rtems_ofw_peer(node)) {<br>
> > > > + ref = rtems_ofw_get_effective_phandle(child, xref);<br>
> > > > + if (ref != -1)<br>
> > > > + return ref;<br>
> > > > +<br>
> > > > + if (rtems_ofw_get_enc_prop(child, "phandle",<br>
> &ref, sizeof(ref))<br>
> > == -1 &&<br>
> > > > + rtems_ofw_get_enc_prop(child, "ibm,phandle",<br>
> &ref, sizeof(ref))<br>
> > > == -1 &&<br>
> > > > + rtems_ofw_get_enc_prop(child,<br>
> "linux,phandle", &ref,<br>
> > sizeof(ref))<br>
> > > == -1<br>
> > > > + ) {<br>
> > > > + continue;<br>
> > > > + }<br>
> > > > +<br>
> > > > + if (ref == xref)<br>
> > > > + return child;<br>
> > > > + }<br>
> > > > +<br>
> > > > + return -1;<br>
> > > > +}<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_node_from_xref( phandle_t xref )<br>
> > > > +{<br>
> > > > + phandle_t node;<br>
> > > > +<br>
> > > > + if ((node =<br>
> rtems_ofw_get_effective_phandle(rtems_ofw_peer(0), xref))<br>
> > > == -1)<br>
> > > > + return xref;<br>
> > > > +<br>
> > > > + return node;<br>
> > > > +}<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_xref_from_node( phandle_t node )<br>
> > > > +{<br>
> > > > + phandle_t ref;<br>
> > > > +<br>
> > > > + if (rtems_ofw_get_enc_prop(node, "phandle", &ref,<br>
> sizeof(ref))<br>
> > == -1 &&<br>
> > > > + rtems_ofw_get_enc_prop(node, "ibm,phandle", &ref,<br>
> > sizeof(ref)) ==<br>
> > > -1 &&<br>
> > > > + rtems_ofw_get_enc_prop(node, "linux,phandle",<br>
> &ref,<br>
> > sizeof(ref))<br>
> > > == -1)<br>
> > > > + {<br>
> > > > + return node;<br>
> > > > + }<br>
> > > > +<br>
> > > > + return ref;<br>
> > > > +}<br>
> > > > +<br>
> > > > +phandle_t rtems_ofw_instance_to_package( ihandle_t<br>
> instance )<br>
> > > > +{<br>
> > > > + return rtems_ofw_node_from_xref(instance);<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_package_to_path(<br>
> > > > + phandle_t node,<br>
> > > > + char *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > + int rv;<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(node);<br>
> > > > +<br>
> > > > + rv = fdt_get_path(fdtp, offset, buf, len);<br>
> > > > + if (rv != 0)<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + return rv;<br>
> > > > +}<br>
> > > > +<br>
> > > > +size_t rtems_ofw_instance_to_path(<br>
> > > > + ihandle_t instance,<br>
> > > > + char *buf,<br>
> > > > + size_t len<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int offset;<br>
> > > > + int rv;<br>
> > > > +<br>
> > > > + offset = rtems_ofw_instance_to_package(instance);<br>
> > > > + offset = rtems_fdt_phandle_to_offset(offset);<br>
> > > > +<br>
> > > > + rv = fdt_get_path(fdtp, offset, buf, len);<br>
> > > > + if (rv != 0)<br>
> > > > + return -1;<br>
> > > > +<br>
> > > > + return rv;<br>
> > > > +}<br>
> > > > +<br>
> > > > +int rtems_ofw_get_reg(<br>
> > > > + phandle_t node,<br>
> > > > + rtems_ofw_memory_area *buf,<br>
> > > > + size_t size<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int len;<br>
> > > > + int offset;<br>
> > > > + int nranges;<br>
> > > > + int nregs;<br>
> > > > + phandle_t parent;<br>
> > > > + rtems_ofw_ranges range;<br>
> > > > + const rtems_ofw_ranges *ptr;<br>
> > > > +<br>
> > > > + len = rtems_ofw_get_enc_prop(node, "reg", (pcell_t<br>
> *)buf, size);<br>
> > > > + if (len <= 0) {<br>
> > > > + return len;<br>
> > > > + }<br>
> > > > +<br>
> > > > + nregs = MIN(len, size) / sizeof(rtems_ofw_memory_area);<br>
> > > > +<br>
> > > > + for (parent = rtems_ofw_parent(node); parent > 0;<br>
> > > > + parent = rtems_ofw_parent(parent)) {<br>
> > > > +<br>
> > > > + offset = rtems_fdt_phandle_to_offset(parent);<br>
> > > > + ptr = fdt_getprop(fdtp, offset, "ranges", &len);<br>
> > > > +<br>
> > > > + if (len < 0) {<br>
> > > > + break;<br>
> > > > + }<br>
> > > > +<br>
> > > > + nranges = len / sizeof(rtems_ofw_ranges);<br>
> > > > +<br>
> > > > + offset = 0;<br>
> > > > + for (int i=0; i < nregs; i++) {<br>
> > > > + for (int j=0; j < nranges; j++) {<br>
> > > > + <br>
> > > > + range.parent_bus =<br>
> fdt32_to_cpu(ptr[j].parent_bus);<br>
> > > > + range.child_bus = fdt32_to_cpu(ptr[j].child_bus);<br>
> > > > + range.size = fdt32_to_cpu(ptr[j].size);<br>
> > > > +<br>
> > > > + if (buf[i].start >= range.child_bus &&<br>
> > > > + buf[i].start < range.child_bus +<br>
> range.size) {<br>
> > > > + offset = range.parent_bus - range.child_bus;<br>
> > > > + break;<br>
> > > > + }<br>
> > > > +<br>
> > > > + }<br>
> > > > + buf[i].start += offset;<br>
> > > > + }<br>
> > > > + }<br>
> > > > +<br>
> > > > + return nregs;<br>
> > > > +}<br>
> > > > +<br>
> > > > +int rtems_ofw_get_interrupts(<br>
> > > > + phandle_t node,<br>
> > > > + void *buf,<br>
> > > > + size_t size<br>
> > > > +)<br>
> > > > +{<br>
> > > > + int rv;<br>
> > > > +<br>
> > > > + rv = rtems_ofw_get_enc_prop(node, "interrupts",<br>
> buf, size);<br>
> > > > + return rv;<br>
> > > > +}<br>
> > > > +<br>
> > > > +bool rtems_ofw_node_status( phandle_t node )<br>
> > > > +{<br>
> > > > + int len;<br>
> > > > + const char buf[10];<br>
> > > > +<br>
> > > > + len = rtems_ofw_get_prop(node, "status", &buf[0],<br>
> sizeof(buf));<br>
> > > > + if ((len == -1) ||<br>
> > > > + (strncmp(buf, "okay", MIN(5, len)) == 0) ||<br>
> > > > + (strncmp(buf, "ok", MIN(3, len)) == 0)) {<br>
> > > > + return true;<br>
> > > > + }<br>
> > > > +<br>
> > > > + return false;<br>
> > > > +}<br>
> > > > diff --git a/spec/build/bsps/obj.yml<br>
> b/spec/build/bsps/obj.yml<br>
> > > > index 8809238057..141ba25f5e 100644<br>
> > > > --- a/spec/build/bsps/obj.yml<br>
> > > > +++ b/spec/build/bsps/obj.yml<br>
> > > > @@ -24,6 +24,9 @@ install:<br>
> > > > - bsps/include/bsp/u-boot.h<br>
> > > > - bsps/include/bsp/uart-output-char.h<br>
> > > > - bsps/include/bsp/utility.h<br>
> > > > +- destination: ${BSP_INCLUDEDIR}/ofw<br>
> > > > + source:<br>
> > > > + - bsps/include/ofw/ofw.h<br>
> > > > - destination: ${BSP_INCLUDEDIR}/libchip<br>
> > > > source:<br>
> > > > - bsps/include/libchip/am29lv160.h<br>
> > > > @@ -104,4 +107,5 @@ source:<br>
> > > > - bsps/shared/dev/serial/z85c30_reg.c<br>
> > > > - bsps/shared/start/bootcard.c<br>
> > > > - bsps/shared/rtems-version.c<br>
> > > > +- bsps/shared/ofw/ofw.c<br>
> > > > type: build<br>
> > > ><br>
> > ><br>
> ><br>
> <br>
> <br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
> <br>
</blockquote></div></div>