RTEMS-libbsd generates drive device firmware

Recently, I am working on add a wireless network card driver to rtems-libbsd.
And it requires the firmware file to add the network card.
The network card chip i used is rtl8188eu, and then i show you how to generate firmware files in rtems-libbsd.

First, the firmware file generation is done by using make-build system(The rtems-libbsd contains the WAF Python Script Compilation and part of the make script, it can not bear to look, but RTEMS said it would be the only way in the future as compiled using WAF, even RTEMS core code is using Python script).

In the root directory of the source code, there are Makefile.todo files, modify this file to get the firmware file, Makefile.todo source code is as follows:

  1. LOCAL_INC = rtemsbsd/include/rtems/bsd/local  
  2.   
  3. LOCAL_SRC = rtemsbsd/local  
  4.   
  5. FREEBSD_SRC = freebsd-org  
  6.   
  7. TOOLS = freebsd-org/sys/tools  
  8.   
  9. GENERATED =  
  10. GENERATED += $(LOCAL_INC)/usb_if.h  
  11. GENERATED += $(LOCAL_SRC)/usb_if.c  
  12. GENERATED += $(LOCAL_INC)/bus_if.h  
  13. GENERATED += $(LOCAL_SRC)/bus_if.c  
  14. GENERATED += $(LOCAL_INC)/device_if.h  
  15. GENERATED += $(LOCAL_SRC)/device_if.c  
  16. GENERATED += $(LOCAL_INC)/usbdevs_data.h  
  17. GENERATED += $(LOCAL_INC)/usbdevs.h  
  18. GENERATED += $(LOCAL_INC)/ifdi_if.h  
  19. GENERATED += $(LOCAL_SRC)/ifdi_if.c  
  20. GENERATED += $(LOCAL_INC)/miibus_if.h  
  21. GENERATED += $(LOCAL_SRC)/miibus_if.c  
  22. GENERATED += $(LOCAL_INC)/miidevs.h  
  23. GENERATED += $(LOCAL_INC)/ofw_if.h  
  24. GENERATED += $(LOCAL_SRC)/ofw_if.c  
  25. GENERATED += $(LOCAL_INC)/ofw_bus_if.h  
  26. GENERATED += $(LOCAL_SRC)/ofw_bus_if.c  
  27. GENERATED += $(LOCAL_INC)/pci_if.h  
  28. GENERATED += $(LOCAL_SRC)/pci_if.c  
  29. GENERATED += $(LOCAL_INC)/pcib_if.h  
  30. GENERATED += $(LOCAL_SRC)/pcib_if.c  
  31. GENERATED += $(LOCAL_INC)/mmcbr_if.h  
  32. GENERATED += $(LOCAL_SRC)/mmcbr_if.c  
  33. GENERATED += $(LOCAL_INC)/mmcbus_if.h  
  34. GENERATED += $(LOCAL_SRC)/mmcbus_if.c  
  35. GENERATED += $(LOCAL_SRC)/rtwn-rtl8192cfwT.c  
  36. GENERATED += $(LOCAL_SRC)/runfw.c  
  37. GENERATED += rtemsbsd/include/machine/rtems-bsd-regdomain.h  
  38. GENERATED += rtemsbsd/rtems/rtems-bsd-regdomain.c  
  39.   
  40. all: $(GENERATED)  
  41.   
  42. $(LOCAL_INC)/usbdevs.h: $(FREEBSD_SRC)/sys/dev/usb/usbdevs  
  43.     awk -f $(TOOLS)/usbdevs2h.awk $< -h  
  44.     mv usbdevs.h $@  
  45.   
  46. $(LOCAL_INC)/usbdevs_data.h: $(FREEBSD_SRC)/sys/dev/usb/usbdevs  
  47.     awk -f $(TOOLS)/usbdevs2h.awk $< -d  
  48.     mv usbdevs_data.h $@  
  49.   
  50. $(LOCAL_INC)/usb_if.h: $(FREEBSD_SRC)/sys/dev/usb/usb_if.m  
  51.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  52.     mv usb_if.h $@  
  53.   
  54. $(LOCAL_SRC)/usb_if.c: $(FREEBSD_SRC)/sys/dev/usb/usb_if.m  
  55.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  56.     mv usb_if.c $@  
  57.   
  58. $(LOCAL_INC)/bus_if.h: $(FREEBSD_SRC)/sys/kern/bus_if.m  
  59.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  60.     mv bus_if.h $@  
  61.   
  62. $(LOCAL_SRC)/bus_if.c: $(FREEBSD_SRC)/sys/kern/bus_if.m  
  63.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  64.     mv bus_if.c $@  
  65.   
  66. $(LOCAL_INC)/device_if.h: $(FREEBSD_SRC)/sys/kern/device_if.m  
  67.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  68.     mv device_if.h $@  
  69.   
  70. $(LOCAL_SRC)/device_if.c: $(FREEBSD_SRC)/sys/kern/device_if.m  
  71.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  72.     mv device_if.c $@  
  73.   
  74. $(LOCAL_INC)/ifdi_if.h: $(FREEBSD_SRC)/sys/net/ifdi_if.m  
  75.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  76.     mv ifdi_if.h $@  
  77.   
  78. $(LOCAL_SRC)/ifdi_if.c: $(FREEBSD_SRC)/sys/net/ifdi_if.m  
  79.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  80.     mv ifdi_if.c $@  
  81.   
  82. $(LOCAL_INC)/miidevs.h: $(FREEBSD_SRC)/sys/dev/mii/miidevs  
  83.     awk -f $(TOOLS)/miidevs2h.awk $<  
  84.     mv miidevs.h $@  
  85.   
  86. $(LOCAL_INC)/miibus_if.h: $(FREEBSD_SRC)/sys/dev/mii/miibus_if.m  
  87.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  88.     mv miibus_if.h $@  
  89.   
  90. $(LOCAL_SRC)/miibus_if.c: $(FREEBSD_SRC)/sys/dev/mii/miibus_if.m  
  91.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  92.     mv miibus_if.c $@  
  93.   
  94. $(LOCAL_INC)/pci_if.h: $(FREEBSD_SRC)/sys/dev/pci/pci_if.m  
  95.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  96.     mv pci_if.h $@  
  97.   
  98. $(LOCAL_SRC)/pci_if.c: $(FREEBSD_SRC)/sys/dev/pci/pci_if.m  
  99.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  100.     mv pci_if.c $@  
  101.   
  102. $(LOCAL_INC)/pcib_if.h: $(FREEBSD_SRC)/sys/dev/pci/pcib_if.m  
  103.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  104.     mv pcib_if.h $@  
  105.   
  106. $(LOCAL_SRC)/pcib_if.c: $(FREEBSD_SRC)/sys/dev/pci/pcib_if.m  
  107.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  108.     mv pcib_if.c $@  
  109.   
  110. $(LOCAL_INC)/mmcbus_if.h: $(FREEBSD_SRC)/sys/dev/mmc/mmcbus_if.m  
  111.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  112.     mv mmcbus_if.h $@  
  113.   
  114. $(LOCAL_SRC)/mmcbus_if.c: $(FREEBSD_SRC)/sys/dev/mmc/mmcbus_if.m  
  115.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  116.     mv mmcbus_if.c $@  
  117.   
  118. $(LOCAL_INC)/mmcbr_if.h: $(FREEBSD_SRC)/sys/dev/mmc/mmcbr_if.m  
  119.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  120.     mv mmcbr_if.h $@  
  121.   
  122. $(LOCAL_SRC)/mmcbr_if.c: $(FREEBSD_SRC)/sys/dev/mmc/mmcbr_if.m  
  123.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  124.     mv mmcbr_if.c $@  
  125.   
  126. $(LOCAL_INC)/ofw_if.h: $(FREEBSD_SRC)/sys/dev/ofw/ofw_if.m  
  127.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  128.     mv ofw_if.h $@  
  129.   
  130. $(LOCAL_SRC)/ofw_if.c: $(FREEBSD_SRC)/sys/dev/ofw/ofw_if.m  
  131.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  132.     mv ofw_if.c $@  
  133.   
  134. $(LOCAL_INC)/ofw_bus_if.h: $(FREEBSD_SRC)/sys/dev/ofw/ofw_bus_if.m  
  135.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  136.     mv ofw_bus_if.h $@  
  137.   
  138. $(LOCAL_SRC)/ofw_bus_if.c: $(FREEBSD_SRC)/sys/dev/ofw/ofw_bus_if.m  
  139.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  140.     mv ofw_bus_if.c $@  
  141.   
  142. $(LOCAL_INC)/if_dwc_if.h: $(FREEBSD_SRC)/sys/dev/dwc/if_dwc_if.m  
  143.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  144.     mv if_dwc_if.h $@  
  145.   
  146. $(LOCAL_SRC)/if_dwc_if.c: $(FREEBSD_SRC)/sys/dev/dwc/if_dwc_if.m  
  147.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  148.     mv if_dwc_if.c $@  
  149.   
  150. $(LOCAL_INC)/gpio_if.h: $(FREEBSD_SRC)/sys/dev/gpio/gpio_if.m  
  151.     awk -f $(TOOLS)/makeobjops.awk $< -h  
  152.     mv gpio_if.h $@  
  153.   
  154. $(LOCAL_SRC)/gpio_if.c: $(FREEBSD_SRC)/sys/dev/gpio/gpio_if.m  
  155.     awk -f $(TOOLS)/makeobjops.awk $< -c  
  156.     mv gpio_if.c $@  
  157.   
  158. $(LOCAL_SRC)/rtwn-rtl8192cfwT.c: $(FREEBSD_SRC)/sys/contrib/dev/rtwn/rtwn-rtl8192cfwT.fw.uu  
  159.     uudecode -o /dev/stdout $< | python firmware-gen.py \  
  160.         -l "$(FREEBSD_SRC)/sys/contrib/dev/rtwn/LICENSE" \  
  161.         rtwn-rtl8192cfwT - $@  
  162.   
  163. $(LOCAL_SRC)/runfw.c: $(FREEBSD_SRC)/sys/contrib/dev/run/rt2870.fw.uu  
  164.     uudecode -o /dev/stdout $< | python firmware-gen.py \  
  165.         -l "$(FREEBSD_SRC)/sys/contrib/dev/run/LICENSE" \  
  166.         runfw - $@  
  167.   
  168. freebsd/usr.bin/netstat/nl_symbols.c: $(FREEBSD_SRC)/usr.bin/netstat/nlist_symbols  
  169.     awk '\  
  170.         BEGIN { \  
  171.         print "#include <sys/param.h>"; \  
  172.         print "#include <nlist.h>"; \  
  173.         print "const struct nlist nl[] = {"; \  
  174.         } \  
  175.         !/^\#/ { printf("\t{ .n_name = \"%s\" },\n", $$2); } \  
  176.         END { print "\t{ .n_name = NULL },\n};" } \  
  177.         ' < $< > $@ || rm -f $@  
  178.   
  179. freebsd/usr.bin/netstat/nl_defs.h: $(FREEBSD_SRC)/usr.bin/netstat/nlist_symbols  
  180.     awk '\  
  181.         BEGIN { \  
  182.         print "#include <nlist.h>"; \  
  183.         print "extern const struct nlist nl[];"; \  
  184.         i = 0; \  
  185.         } \  
  186.         !/^\#/ { printf("\#define\tN%s\t%s\n", toupper($$2), i++); }' \  
  187.         < $< > $@ || rm -f $@  
  188.   
  189. rtemsbsd/include/machine/rtems-bsd-regdomain.h: $(FREEBSD_SRC)/etc/regdomain.xml  
  190.     rtems-bin2c -H $< $@  
  191.   
  192. rtemsbsd/rtems/rtems-bsd-regdomain.c: $(FREEBSD_SRC)/etc/regdomain.xml  
  193.     rtems-bin2c -C $< $@  
  194.   
  195. clean:  
  196.     rm $(GENERATED)  


First add:

  1. GENERATED += $(LOCAL_SRC)/rtwn-rtl8192cfwT.c  
This corresponds to the firmware of rtl8192cu, and then a method for these goals:

  1. $(LOCAL_SRC)/rtwn-rtl8192cfwT.c: $(FREEBSD_SRC)/sys/contrib/dev/rtwn/rtwn-rtl8192cfwT.fw.uu  
  2.     uudecode -o /dev/stdout $< | python firmware-gen.py \  
  3.         -l "$(FREEBSD_SRC)/sys/contrib/dev/rtwn/LICENSE" \  
  4.         rtwn-rtl8192cfwT - $@  


As can be seen, my method needs FreeBSD source code support, in rtems-libbsd, the FreeBSD-org folder contains the FreeBSD master branch source code.

The source files required for the firmware file are as follows:



Using Git clone, clone the rtems-libbsd source to local, but the default freeBSD-org folder is empty. Therefore, you need the following command to move freeBSD clone to the folder:
  1. git submodule update  


After the analysis of the generation of firmware file ,we add rtl8188eu firmware to generate the code, add in the Makefile.todo:
  1. git submodule update  
  1. $(LOCAL_SRC)/rtwn-rtl8188eufw.c: $(FREEBSD_SRC)/sys/contrib/dev/rtwn/rtwn-rtl8188eufw.fw.uu  
  2. <span style="white-space:pre">  </span>uudecode -o /dev/stdout $< | python firmware-gen.py \  
  3. <span style="white-space:pre">  </span>    -l "$(FREEBSD_SRC)/sys/contrib/dev/rtwn/LICENSE" \  
  4. <span style="white-space:pre">  </span>    rtwn-rtl8188eufw - $@  




Then compile:


  1. make -f Makefile.todo  


Successful compilation will generate the corresponding firmware C file under the rtemsbsd/local folder, and then add the file in the libbsd.py script and run the command:

  1. ./freebsd-to-rtems.py  

We can update this file in libbsd_waf.py, and finally you can compile it with waf. So, the firmware file is already generated, so how do you apply it?

Adding the following modules in nexus-devices.h means loading the firmware module:
  1. SYSINIT_REFERENCE(rtwn_rtl8188eufw);  

评论

此博客中的热门博文

RTEMS USB support for BBB document

RTEMS Network Transplantation - rtems system initialization process analysis

Work Product Submission