<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">On Tue, May 5, 2020 at 11:46 PM Vijay Kumar Banerjee <<a href="mailto:vijay@rtems.org">vijay@rtems.org</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 5, 2020 at 10:40 PM Niteesh G. S. <<a href="mailto:niteesh.gs@gmail.com" target="_blank">niteesh.gs@gmail.com</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"><div dir="ltr"><div style="font-size:small">This is thread is about implementing OFW functions in RTEMS as part</div><div style="font-size:small">of my GSoC project. I would like to start off with this part since the refactoring</div><div style="font-size:small">work will somewhat depend on this.</div><div style="font-size:small"><br></div><div style="font-size:small">Implementing these functions into RTEMS will make porting drivers from</div><div style="font-size:small">FreeBSD to RTEMS easy. Currently, the drivers ported from freebsd implement</div><div style="font-size:small">the functions using libfdt variants but this causes a lot of code duplication.</div><div style="font-size:small">eg: bsps/arm/imx/start/imx_iomux.c</div><div style="font-size:small"><br></div><div style="font-size:small">My initial thoughts were to implement these functions one by one. But then</div><div style="font-size:small">Christian and Vijay mentioned about porting them from libbsd. I went</div><div style="font-size:small">through the OFW code in libbsd and have described my porting process below.</div><div style="font-size:small">Please have a look at it and let me know if I have missed something or you</div><div style="font-size:small">would like to improve things.</div><div style="font-size:small"><br></div><div style="font-size:small">The following files will be ported from libbsd</div><div style="font-size:small">prefix = freebsd/sys/dev/ofw</div><div style="font-size:small"><prefix>/openfirm.c</div><div style="font-size:small"><div><prefix>/openfirm.h</div><div><div><prefix>/ofw_fdt.c</div><div><prefix>/ofwvar.h</div><div><br></div><div>The main idea is to port openfirm.h but the other files are dependencies of openfirm.h</div><div><br></div></div></div></div></blockquote><div>Hi Niteesh,</div><div><br></div><div>The initial plan of your project was to implement the whole FDT support on RTEMS,</div><div>but there's already support through libbsd, so it might be a better solution to port any</div><div>remaining drivers from freebsd through libbsd and adapt the BSP drivers to use the</div><div>freebsd FDT stack. This needs some discussion and input from other people to form</div><div>the right plan and work accordingly.</div></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">But this would require even the smallest example to link to rtems-libbsd.<br></div><div class="gmail_default" style="font-size:small">Is it okay for this to happen?</div><div class="gmail_default" style="font-size:small">During the proposal period, Hesham also mentioned about this. I think the</div><div class="gmail_default" style="font-size:small">comments are still there in the google docs. And also won't this cause the drivers</div><div class="gmail_default" style="font-size:small">to initialized only after initialization of libbsd?</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:small"><div><div></div><div>After going through some open firmware documentation. I guess as far as RTEMS is </div><div>concerned we could avoid many functions like OF_init, OF_putchar, OF_test</div><div>and only care about functions defined under openfirm.h:105-142</div><div><br></div><div>But these functions have dependency on the automatically generated ofw_if.h and KOBJS.</div><div>But after a close inspection, I guess the KOBJSLOOKUP macro in ofw_if.h can be</div><div>redefined or replaced for RTEMS. Since all it does is call the respective functions defined in ofw_fdt_methods(ofw_fdt.c).</div><div><br></div></div></div></div></blockquote><div>The openfirm.h is already ported in libbsd and is being used by some driver ported</div><div>through libbsd (like i2c).</div></div></div></blockquote><div><div class="gmail_default" style="font-size:small">I understand this. Maybe I didn't explain this properly. The implementation of the</div><div class="gmail_default" style="font-size:small">functions in openfirm.c depends on functions in that automatically generated file.</div><div class="gmail_default" style="font-size:small">Then this generated file depends on KOBJS.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The functions in ofw_in.h(generated file) basically lookup for a particular function</div><div class="gmail_default" style="font-size:small">associated with kobj(ofw_obj).</div><div class="gmail_default" style="font-size:small">For eg: the OF_getprop in openfirm.c calls OFW_GETPROP(auto-generated)</div><div class="gmail_default" style="font-size:small">which then looks up for the ofw_fdt_get_prop(ofw_fdt.c) function associated with</div><div class="gmail_default" style="font-size:small">the ofw_obj.</div><div class="gmail_default" style="font-size:small">Based on this my initial intention was to redefine the KOBJSLOOKUP macro in</div><div class="gmail_default" style="font-size:small">RTEMS(rtems.git) to directly call the associated functions using some macro magic.</div><div class="gmail_default" style="font-size:small">But I now realized that this could be break when linked to rtems-libbsd.</div><div class="gmail_default" style="font-size:small"><br></div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>To help you understand the structure of the libbsd:</div><div>* The files in freebsd/ directory are already ported to RTEMS.</div><div>* The freebsd-org/ is the git submodule that has the original source of the freebsd.</div><div>* The rtemsbsd/ has the codes that we added to adapt the freebsd codes.</div><div><br></div><div>The *_if.h files are generally automatically generated from the *_if.m files.</div><div>The ofw_if.h has already been ported, you can find the generated header</div><div>file in rtemsbsd/include/rtems/bsd/local/ofw_if.h so there's no need to do it</div><div>again. If future if there's a need to do it, we generally add a recipe to build</div><div>the h files from the .m files in the Makefile.todo . You can have a look at it</div><div>if you want, it's simple to follow.</div><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"><div dir="ltr"><div style="font-size:small"><div><div></div><div>I had just spent a few hours going through the code. If I had missed something</div><div>please let me know.</div><div><br></div></div></div></div></blockquote><div>You're in the right direction. We need to wait a bit to get some input from</div><div>the community and progress accordingly.</div><div><br></div><div>Best regards,</div><div>Vijay </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:small"><div><div></div><div>Thanks,</div><div>Niteesh.</div><div></div></div><div></div></div></div>
</blockquote></div></div>
</blockquote></div></div>