Re: libbsd: How to add an option for switching off IPv6 (or other BSD Kernel configurations)
Am 02.08.2016 um 12:21 schrieb Chris Johns: > On 2/08/2016 8:05 PM, Christian Mauderer wrote: >> Am 02.08.2016 um 08:57 schrieb Christian Mauderer: >>> Am 02.08.2016 um 04:09 schrieb Chris Johns: On 02/08/2016 00:04, Christian Mauderer wrote: >> [...] >>> > Are there any better ideas how to implement such an option? There are 2 parts that need be to changed to make this work. This assumes you will need to control the source being built. The first is the module descriptions in libbsd.py and then the generator. I suggest you look at the various module class methods used to add source and consider adding a 'section' argument which defaults to 'default' (always True). This would lets you move code into specific sections, for example: dhcpcd_defines='-D__FreeBSD__ -DTHERE_IS_NO_FORK ...' mod.addSourceFiles( [ 'dhcpcd/ipv6.c', 'dhcpcd/ipv6nd.c', ], mm.generator['source'](dhcpcd_defines), section = 'networking.ipv6_yes' ) Note, this definition generates something that is evaluated when waf runs so the 'section' populates a dict where the 'networking.ipv6_yes' key is tested for True or False depending what the user specifies. You could also change the class constructor so you have: mod = builder.Module('dhcpcd', section = 'networking.dhcp') The dot notation would allow control of the sources at the module level to finally get sorted out. The dhcpcd module becomes 'networking.dhcpcd' which means build if networking and dhcpcd are True. You could work down the dots checking at each point to make sure the module can be built. Currently module level user control has been left hanging with commented modules, eg '#mm.addModule(dev_usb_controller_add_on(mm)'. If the section 'usb.dev_usb_controller_add_on' is False by default that module is not built which is what we have now. The second part is in the waf script (wscript) which handles the user interface, ie parses --config="networking:ipv6=no,pink-frames-only,chrismac-buf-frames=64". I would add this code in a new Python module libbsd_opts.py and imported into libbsd_waf.py (generated) and called in the 'options' function in libbsd_waf.py. This would parse and populate a dict the generated module code uses. >>> >>> Thanks for the detailed description. I'll need some time to understand >>> everything but it looks like a good starting point. >>> >> [...] >>> >> >> Hello Chris, >> >> I think I managed to understand most of it even if I still only have a >> rough Idea where to start. >> >> If I'm right, you suggested two alternative possible methods: >> >> 1) Add the section-option as parameter to a addSourceFiles. This means >> it is only valid for some sources in a module. >> >> 2) Alternatively add it directly to the module. >> > > I am saying have both so all modules are provide a section. > > I only used the work section because it is the term used in INI files. > >> Did I understand you correct. Or did you mean that the section is added >> to both - the module and the source? > > Close, but how about annotating all source and then we can control it > better. > >> >> As far as I understand the first method, this could be also used for the >> define that depends on the option. Something like this: >> >> def dhcpcd(mm): >> mod = builder.Module('dhcpcd') >> dhcpcd_sources = >> [ >> 'dhcpcd/arp.c', >> 'dhcpcd/auth.c', >> ... >> ] >> dhcpcd_defines_base = '-D__FreeBSD__ -DTHERE_IS_NO_FORK ...' >> dhcpcd_defines_inet6 = dhcpcd_defines_base + ' -DINET6' >> mod.addSourceFiles( >> dhcpcd_sources, >> mm.generator['source'](dhcpcd_defines_base), >> section = 'networking.ipv6_no' >> ) >> mod.addSourceFiles( >> dhcpcd_sources, >> mm.generator['source'](dhcpcd_defines_inet6), >> section = 'networking.ipv6_yes' >> ) >> return mod >> > > It is close, however I suspect -DINET6 is need for all source when being > built. I will take a look and see what I can sort out. > >> I'm not sure how this would be possible with the second method. > > Let me take a closer look. > > Chris > Hello Chris, just for information: For a test I applied the necessary changes to switch off IPv6 manually. Of course we can't add this to the libbsd directly but it could be a reference what would be necessary. You can find the patch appended to this mail. It should be applied on top of 07176074bdfb53946e277e046ca3e2bc77726bf7 or later. Kind regards Christian -- embedded brains GmbH Christian Mauderer Dornierstr. 4 D-82178 Puchheim Germany
[PATCH 02/02] Added usb_ehternet controller and configured for Raspberry Pi.
--- freebsd/sys/dev/usb/controller/dwc_otg_fdt.c |4 + freebsd/sys/dev/usb/net/if_cdce.c | 1583 freebsd/sys/dev/usb/net/if_cdcereg.h | 105 ++ freebsd/sys/dev/usb/net/if_smsc.c | 1886 freebsd/sys/dev/usb/net/if_smscreg.h | 278 +++ freebsd/sys/dev/usb/net/usb_ethernet.c | 659 +++ freebsd/sys/dev/usb/net/usb_ethernet.h | 127 ++ freebsd/sys/dev/usb/usb_busdma.c |4 +- freebsd/sys/sys/sysctl.h |1 + libbsd.py |8 +- libbsd_waf.py |2 + rtemsbsd/include/bsp/nexus-devices.h | 17 +- .../include/rtems/bsd/test/network-config.h.in |2 + 13 files changed, 4669 insertions(+), 7 deletions(-) create mode 100644 freebsd/sys/dev/usb/net/if_cdce.c create mode 100644 freebsd/sys/dev/usb/net/if_cdcereg.h create mode 100644 freebsd/sys/dev/usb/net/if_smsc.c create mode 100644 freebsd/sys/dev/usb/net/if_smscreg.h create mode 100644 freebsd/sys/dev/usb/net/usb_ethernet.c create mode 100644 freebsd/sys/dev/usb/net/usb_ethernet.h diff --git a/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c b/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c index b06fa0a..598187b 100644 --- a/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c +++ b/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c @@ -224,5 +224,9 @@ driver_t dwc_otg_driver = { static devclass_t dwc_otg_devclass; +#ifndef __rtems__ DRIVER_MODULE(dwcotg, simplebus, dwc_otg_driver, dwc_otg_devclass, 0, 0); +#else /* __rtems__ */ +DRIVER_MODULE(dwcotg, nexus, dwc_otg_driver, dwc_otg_devclass, 0, 0); +#endif /* __rtems__ */ MODULE_DEPEND(dwcotg, usb, 1, 1, 1); diff --git a/freebsd/sys/dev/usb/net/if_cdce.c b/freebsd/sys/dev/usb/net/if_cdce.c new file mode 100644 index 000..ecab60e --- /dev/null +++ b/freebsd/sys/dev/usb/net/if_cdce.c @@ -0,0 +1,1583 @@ +#include + +/* $NetBSD: if_cdce.c,v 1.4 2004/10/24 12:50:54 augustss Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul + * Copyright (c) 2003-2005 Craig Boston + * Copyright (c) 2004 Daniel Hartmeier + * Copyright (c) 2009 Hans Petter Selasky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + *must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + *may be used to endorse or promote products derived from this software + *without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR + * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * USB Communication Device Class (Ethernet Networking Control Model) + * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf + */ + +/* + * USB Network Control Model (NCM) + * http://www.usb.org/developers/devclass_docs/NCM10.zip + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#defineUSB_DEBUG_VAR cdce_debug +#include +#include +#include +#include + +#include +#include + +static device_probe_t cdce_probe; +static device_attach_t cdce_attach; +static device_detach_t cdce_detach; +static device_suspend_t cdce_suspend; +static device_resume_t cdce_resume; +static usb_handle_request_t cdce_handle_request; + +static usb_callback_t cdc
[PATCH 01/02] USB driver bcm283x_dwcotg added.
--- freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c | 127 freebsd/sys/dev/usb/controller/dwc_otg_fdt.c | 228 + freebsd/sys/dev/usb/controller/dwc_otg_fdt.h | 39 libbsd.py | 3 + libbsd_waf.py | 4 +- rtemsbsd/include/bsp/nexus-devices.h | 21 ++ 6 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c create mode 100644 freebsd/sys/dev/usb/controller/dwc_otg_fdt.c create mode 100644 freebsd/sys/dev/usb/controller/dwc_otg_fdt.h diff --git a/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c b/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c new file mode 100644 index 000..4c148d4 --- /dev/null +++ b/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c @@ -0,0 +1,127 @@ +#include + +/* + * Copyright 2015 Andrew Turner. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#ifndef __rtems__ +#include +#endif + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#ifndef __rtems__ +#include +#else +#include +#include +#endif + +static device_probe_t bcm283x_dwc_otg_probe; +static device_attach_t bcm283x_dwc_otg_attach; + +static int +bcm283x_dwc_otg_probe(device_t dev) +{ + + #ifndef __rtems__ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-usb")) + return (ENXIO); + #endif + device_set_desc(dev, "DWC OTG 2.0 integrated USB controller (bcm283x)"); + + return (BUS_PROBE_VENDOR); +} + +static int +bcm283x_dwc_otg_attach(device_t dev) +{ + int err; + + #ifndef __rtems__ + + err = bcm2835_mbox_set_power_state(BCM2835_MBOX_POWER_ID_USB_HCD, TRUE); + if (err) + device_printf(dev, "failed to set power state, err=%d\n", err); + + #else + + bcm2835_set_power_state_entries power_state_usb; + power_state_usb.dev_id = bcm2835_mailbox_power_udid_usb_hcd; + power_state_usb.state = BCM2835_MAILBOX_SET_POWER_STATE_REQ_ON; + err = bcm2835_mailbox_set_power_state(&power_state_usb); + if (err) + device_printf(dev, "failed to set power state, err=%d\n", err); + + #endif + + return (dwc_otg_attach(dev)); +} + +static device_method_t bcm283x_dwc_otg_methods[] = { + /* bus interface */ + DEVMETHOD(device_probe, bcm283x_dwc_otg_probe), + DEVMETHOD(device_attach, bcm283x_dwc_otg_attach), + + DEVMETHOD_END +}; + +static devclass_t bcm283x_dwc_otg_devclass; + +DEFINE_CLASS_1(bcm283x_dwcotg, bcm283x_dwc_otg_driver, bcm283x_dwc_otg_methods, + sizeof(struct dwc_otg_fdt_softc), dwc_otg_driver); +#ifndef __rtems__ +DRIVER_MODULE(bcm283x_dwcotg, simplebus, bcm283x_dwc_otg_driver, + bcm283x_dwc_otg_devclass, 0, 0); +#else +DRIVER_MODULE(bcm283x_dwcotg, nexus, bcm283x_dwc_otg_driver, + bcm283x_dwc_otg_devclass, 0, 0); +#endif +MODULE_DEPEND(bcm283x_dwcotg, usb, 1, 1, 1); diff --git a/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c b/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c new file mode 100644 index 000..b06fa0a --- /dev/null +++ b/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c @@ -0,0 +1,228 @@ +#include + +/*- + * Copyright (c) 2012 Hans Petter Selasky. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are m