source: rtems-libbsd/libbsd.txt @ 65d6fa2

5-freebsd-12
Last change on this file since 65d6fa2 was e3e88e1, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 26, 2017 at 7:36:56 AM

Add CONTRIBUTING.md

  • Property mode set to 100644
File size: 38.4 KB
Line 
1RTEMS BSD Library Guide
2=======================
3:toc:
4:icons:
5:numbered:
6:website: http://www.rtems.org/
7
8RTEMS uses FreeBSD 9.2 as the source of its TCP/IP and USB stacks.
9This is a guide which captures information on the
10process of merging code from FreeBSD, building this library,
11RTEMS specific support files, and general guidelines on what
12modifications to the FreeBSD source are permitted.
13
14Goals of this effort are
15
16* update TCP/IP and provide USB in RTEMS,
17* ease updating to future FreeBSD versions,
18* ease tracking changes in FreeBSD code,
19* minimize manual changes in FreeBSD code, and
20* define stable kernel/device driver API which is implemented
21by both RTEMS and FreeBSD. This is the foundation of the port.
22
23We will work to push our changes upstream to the FreeBSD Project
24and minimize changes required at each update point.
25
26*******************************************************************************
27This is a work in progress and is very likely to be incomplete.
28Please help by adding to it.
29*******************************************************************************
30
31== Getting Started
32
33=== Tool Chain ===
34
35You need a tool chain for RTEMS based on at least RSB 4.12 April 2016 or later.
36
37=== Installation Overview ===
38
39. You must configure your BSP with the +--disable-networking+ option to disable
40the old network stack.  Make sure no header files of the old network stack are
41installed.
42
43. Clone the Git repository +git clone git://git.rtems.org/rtems-libbsd.git+.
44. Change into the RTEMS BSD library root directory.
45. Edit the `config.inc` configuration file and adjust it to your environment.
46. Run +waf configure ...+.
47. Run +waf+.
48. Run +waf install+.
49
50Refer to the README.waf for Waf building instructions.
51
52Make sure the submodules have been initialised and are updated. If a 'git
53status' says `rtems_waf` need updating run the submodule update command:
54
55 $ git submodule rtems_waf update
56
57=== Board Support Package Requirements ===
58
59The RTEMS version must be at least 4.12.  The Board Support Package (BSP)
60should support the
61http://www.rtems.org/onlinedocs/doxygen/cpukit/html/group\__rtems\__interrupt__extension.html[Interrupt Manager Extension]
62// The first underscores have to be masked to stop asciidoc interpreting them
63to make use of generic FreeBSD based drivers.
64
65The linker command file of the BSP must contain the following section
66definitions:
67
68-------------------------------------------------------------------------------
69.rtemsroset : {
70        KEEP (*(SORT(.rtemsroset.*)))
71}
72
73.rtemsrwset : {
74        KEEP (*(SORT(.rtemsrwset.*)))
75}
76-------------------------------------------------------------------------------
77
78The first output section can be placed in read-only memory.  The second output
79section must be placed in read-write memory.  The output section name is not
80relevant.  The output sections may also contain other input sections.
81
82=== Board Support Package Configuration and Build ===
83
84You need to configure RTEMS for the desired BSP and install it.  The BSP should
85be configured with a disabled network stack.  The BSD library containing the
86new network stack is a separate package.  Using a BSP installation containing
87the old network stack may lead to confusion and unpredictable results.
88
89The following script is used to build the `arm/xilinx_zynq_a9_qemu` BSP for
90our internal testing purposes:
91
92-------------------------------------------------------------------------------
93#!/bin/sh
94
95cd ${HOME}/sandbox
96rm -rf b-xilinx_zynq_a9_qemu
97mkdir b-xilinx_zynq_a9_qemu
98cd b-xilinx_zynq_a9_qemu
99${HOME}/git-rtems/configure \
100        --prefix=${HOME}/sandbox/install \
101        --target=arm-rtems4.12 \
102        --enable-rtemsbsp=xilinx_zynq_a9_qemu \
103        --disable-networking && \
104        make && \
105        make install
106-------------------------------------------------------------------------------
107
108The `arm/xilinx_zynq_a9_qemu` BSP running on the Qemu simulator has some
109benefits for development and test of the BSD library
110
111* it offers a NULL pointer read and write protection,
112* Qemu is a fast simulator,
113* Qemu provides support for GDB watchpoints,
114* Qemu provides support for virtual Ethernet networks, e.g. TUN and bridge
115devices (you can run multiple test instances on one virtual network).
116
117=== BSD Library Configuration and Build ===
118
119The build system based on the Waf build system. To build with Waf please refer
120to the README.waf file.
121
122===== Example Configuration =====
123
124In the BSD library source directory edit the file `config.inc`.  Continuing on
125the above, the `config.inc` used to match the above is:
126
127-------------------------------------------------------------------------------
128# Mandatory: Select your BSP and installation prefix
129TARGET = arm-rtems4.12
130BSP = xilinx_zynq_a9_qemu
131PREFIX = $(HOME)/sandbox/install
132
133# Optional: Separate installation base directory
134INSTALL_BASE = $(PREFIX)/$(TARGET)/$(BSP)
135
136# Optional: Network test configuration
137TEST_RUNNER = $(BSP)
138NET_CFG_SELF_IP = 10.0.0.2
139NET_CFG_NETMASK = 255.255.0.0
140NET_CFG_PEER_IP = 10.0.0.1
141NET_CFG_GATEWAY_IP = 10.0.0.1
142NET_TAP_INTERFACE = tap0
143-------------------------------------------------------------------------------
144
145=== BSD Library Initialization ===
146
147To initialise the BSD Library create a suitable rc.conf file. The FreeBSD man
148page rc.conf(5) provides the details needed to create a suitable format file:
149
150 https://www.freebsd.org/cgi/man.cgi?rc.conf
151
152You can call one of three functions to run the initialisation once BSD has
153initialised:
154
155 - rtems_bsd_run_etc_rc_conf: Run /etc/rc.conf.
156 - rtems_bsd_run_rc_conf: Run a user supplied file.
157 - rtems_bsd_run_rc_conf_script: Run the in memory line feed separated text string.
158
159For exapmle:
160
161 void
162 network_init(void)
163 {
164   rtems_status_code sc;
165
166   sc = rtems_bsd_initialize();
167   assert(sc == RTEMS_SUCCESSFUL);
168
169   rtems_bsd_run_etc_rc_conf(true); /* verbose = true */
170
171}
172
173By default the networking support is builtin. Other directives can be added and
174are found in 'machine/rtems-bsd-rc-conf-directives.h'. Please check the file
175for the list.
176
177The following network names are supported:
178
179  cloned_interfaces
180  ifconfig_'interface'
181  defaultrouter
182  hostname
183
184For example:
185
186 #
187 # My BSD initialisation.
188 #
189 hostname="myhost"
190 cloned_interfaces="vlan0 vlan1"
191 ifconfig_re0="inet inet 10.10.10.10 netmask 255.255.255.0"
192 fconfig_vlan0="inet 10.11.10.10 255.255.255.0 vlan 101 vlandev re0"
193 defaultrouter="10.10.10.1"
194
195You can also intialise the BSD library using code. The following code to
196initialize the BSD library:
197
198-------------------------------------------------------------------------------
199#include <assert.h>
200#include <sysexits.h>
201
202#include <machine/rtems-bsd-commands.h>
203#include <rtems/bsd/bsd.h>
204
205static void
206network_ifconfig_lo0(void)
207{
208        int exit_code;
209        char *lo0[] = {
210                "ifconfig",
211                "lo0",
212                "inet",
213                "127.0.0.1",
214                "netmask",
215                "255.255.255.0",
216                NULL
217        };
218        char *lo0_inet6[] = {
219                "ifconfig",
220                "lo0",
221                "inet6",
222                "::1",
223                "prefixlen",
224                "128",
225                NULL
226        };
227
228        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0), lo0);
229        assert(exit_code == EX_OK);
230
231        exit_code = rtems_bsd_command_ifconfig(RTEMS_BSD_ARGC(lo0_inet6), lo0_inet6);
232        assert(exit_code == EX_OK);
233}
234
235void
236network_init(void)
237{
238        rtems_status_code sc;
239
240        sc = rtems_bsd_initialize();
241        assert(sc == RTEMS_SUCCESSFUL);
242
243        network_ifconfig_lo0();
244}
245-------------------------------------------------------------------------------
246
247This performs the basic network stack initialization with a loopback interface.
248Further initialization must be done using the standard BSD network
249configuration commands
250http://www.freebsd.org/cgi/man.cgi?query=ifconfig&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[IFCONFIG(8)]
251using `rtems_bsd_command_ifconfig()` and
252http://www.freebsd.org/cgi/man.cgi?query=route&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[ROUTE(8)]
253using `rtems_bsd_command_route()`.  For an example please have a look at
254`testsuite/include/rtems/bsd/test/default-network-init.h`.
255
256=== Task Priorities and Stack Size ===
257
258The default task priority is 96 for the interrupt server task (name "IRQS"), 98
259for the timer server task (name "TIME") and 100 for all other tasks.  The
260application may provide their own implementation of the
261`rtems_bsd_get_task_priority()` function (for example in the module which calls
262`rtems_bsd_initialize()`) if different values are desired.
263
264The task stack size is determined by the `rtems_bsd_get_task_stack_size()`
265function which may be provided by the application in case the default is not
266appropriate.
267
268=== Size for Allocator Domains ===
269
270The size for an allocator domain can be specified via the
271`rtems_bsd_get_allocator_domain_size()` function.  The application may provide
272their own implementation of the `rtems_bsd_get_allocator_domain_size()`
273function (for example in the module which calls `rtems_bsd_initialize()`) if
274different values are desired.  The default size is 8MiB for all domains.
275
276== Network Stack Features
277
278http://roy.marples.name/projects/dhcpcd/index[DHCPCD(8)]:: DHCP client
279
280https://developer.apple.com/library/mac/documentation/Networking/Reference/DNSServiceDiscovery_CRef/Reference/reference.html[dns_sd.h]:: DNS Service Discovery
281
282http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-320.10/mDNSCore/mDNSEmbeddedAPI.h[mDNS]:: Multi-Cast DNS
283
284http://www.freebsd.org/cgi/man.cgi?query=unix&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[UNIX(4)]:: UNIX-domain protocol family
285
286http://www.freebsd.org/cgi/man.cgi?query=inet&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[INET(4)]:: Internet protocol family
287
288http://www.freebsd.org/cgi/man.cgi?query=inet6&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[INET6(4)]:: Internet protocol version 6 family
289
290http://www.freebsd.org/cgi/man.cgi?query=tcp&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[TCP(4)]:: Internet Transmission Control Protocol
291
292http://www.freebsd.org/cgi/man.cgi?query=udp&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[UDP(4)]:: Internet User Datagram Protocol
293
294http://www.freebsd.org/cgi/man.cgi?query=route&sektion=4&apropos=0&manpath=FreeBSD+9.2-RELEASE[ROUTE(4)]:: Kernel packet forwarding database
295
296http://www.freebsd.org/cgi/man.cgi?query=bpf&apropos=0&sektion=4&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[BPF(4)]:: Berkeley Packet Filter
297
298http://www.freebsd.org/cgi/man.cgi?query=socket&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[SOCKET(2)]:: Create an endpoint for communication
299
300http://www.freebsd.org/cgi/man.cgi?query=kqueue&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[KQUEUE(2)]:: Kernel event notification mechanism
301
302http://www.freebsd.org/cgi/man.cgi?query=select&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[SELECT(2)]:: Synchronous I/O multiplexing
303
304http://www.freebsd.org/cgi/man.cgi?query=poll&apropos=0&sektion=2&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[POLL(2)]:: Synchronous I/O multiplexing
305
306http://www.freebsd.org/cgi/man.cgi?query=route&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[ROUTE(8)]:: Manually manipulate the routing tables
307
308http://www.freebsd.org/cgi/man.cgi?query=ifconfig&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[IFCONFIG(8)]:: Configure network interface parameters
309
310http://www.freebsd.org/cgi/man.cgi?query=netstat&apropos=0&sektion=1&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[NETSTAT(1)]:: Show network status
311
312http://www.freebsd.org/cgi/man.cgi?query=ping&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[PING(8)]:: Send ICMP ECHO_REQUEST packets to network hosts
313
314http://www.freebsd.org/cgi/man.cgi?query=ping6&apropos=0&sektion=8&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[PING6(8)]:: Send ICMPv6 ECHO_REQUEST packets to network hosts
315
316http://www.freebsd.org/cgi/man.cgi?query=sysctl&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[SYSCTL(3)]:: Get or set system information
317
318http://www.freebsd.org/cgi/man.cgi?query=resolver&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[RESOLVER(3)]:: Resolver routines
319
320http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&sektion=3&apropos=0&manpath=FreeBSD+9.2-RELEASE[GETHOSTBYNAME(3)]:: Get network host entry
321
322== Network Interface Drivers
323
324=== Link Up/Down Events
325
326You can notifiy the application space of link up/down events in your network
327interface driver via the if_link_state_change(LINK_STATE_UP/LINK_STATE_DOWN)
328function.  The DHCPCD(8) client is a consumer of these events for example.
329Make sure that the interface flag IFF_UP and the interface driver flag
330IFF_DRV_RUNNING is set in case the link is up, otherwise ether_output() will
331return the error status ENETDOWN.
332
333== Shell Commands
334
335=== HOSTNAME(1)
336
337In addition to the standard options the RTEMS version of the HOSTNAME(1)
338command supports the -m flag to set/get the multicast hostname of the
339mDNS resolver instance.  See also rtems_mdns_sethostname() and
340rtems_mdns_gethostname().
341
342== Qemu
343
344Use the following script to set up a virtual network with three tap devices
345connected via one bridge device.
346
347-------------------------------------------------------------------------------
348#!/bin/sh -x
349
350user=`whoami`
351interfaces=(1 2 3)
352
353tap=qtap
354bri=qbri
355
356case $1 in
357        up)
358                sudo -i brctl addbr $bri
359                for i in ${interfaces[@]} ; do
360                        sudo -i tunctl -t $tap$i -u $user ;
361                        sudo -i ifconfig $tap$i up ;
362                        sudo -i brctl addif $bri $tap$i ;
363                done
364                sudo -i ifconfig $bri up
365                ;;
366        down)
367                for i in ${interfaces[@]} ; do
368                        sudo -i ifconfig $tap$i down ;
369                        sudo -i tunctl -d $tap$i ;
370                done
371                sudo -i ifconfig $bri down
372                sudo -i brctl delbr $bri
373                ;;
374esac
375-------------------------------------------------------------------------------
376
377Connect your Qemu instance to one of the tap devices, e.g.
378
379-------------------------------------------------------------------------------
380qemu-system-i386 -m 512 -boot a -cpu pentium3 \
381        -drive file=$HOME/qemu/pc386_fda,index=0,if=floppy,format=raw \
382        -drive file=fat:$HOME/qemu/hd,format=raw \
383        -net nic,model=e1000,macaddr=0e:b0:ba:5e:ba:11 \
384        -net tap,ifname=qtap1,script=no,downscript=no \
385        -nodefaults -nographic -serial stdio
386-------------------------------------------------------------------------------
387
388-------------------------------------------------------------------------------
389qemu-system-arm \
390        -serial null \
391        -serial mon:stdio \
392        -nographic \
393        -M xilinx-zynq-a9 \
394        -net nic,model=cadence_gem,macaddr=0e:b0:ba:5e:ba:11 \
395        -net tap,ifname=qtap1,script=no,downscript=no \
396        -m 256M \
397        -kernel build/arm-rtems4.12-xilinx_zynq_a9_qemu/media01.exe
398-------------------------------------------------------------------------------
399
400Make sure that each Qemu instance uses its own MAC address to avoid an address
401conflict (or otherwise use it as a test).
402
403To connect the Qemu instances with your local network use the following
404(replace 'eth0' with the network interface of your host).
405
406-------------------------------------------------------------------------------
407ifconfig eth0 0.0.0.0
408brctl addif qbri eth0
409dhclient qbri
410-------------------------------------------------------------------------------
411
412=== VDE and QEMU
413
414On FreeBSD you can create VDE or the Virtual Distributed Ethernet to create a
415network environment that does not need to run qemu as root or needing to drop
416the tap's privileges to run qemu.
417
418VDE creates a software switch with a default of 32 ports which means a single
419kernel tap can support 32 qemu networking sessions.
420
421To use VDE you need to build qemu with VDE support. The RSB can detect a VDE
422plug and enable VDE support in qemu when building. On FreeBSD install the VDE
423support with:
424
425 # pkg install -u vde2
426
427Build qemu with the RSB.
428
429To network create a bridge and a tap. The network is 10.10.1.0/24. On FreeBSD
430add to your /etc/rc.conf:
431
432 cloned_interfaces="bridge0 tap0"
433 autobridge_interfaces="bridge0"
434 autobridge_bridge0="re0 tap0"
435 ifconfig_re0="up"
436 ifconfig_tap0="up"
437 ifconfig_bridge0="inet 10.1.1.2 netmask 255.255.255.0"
438 defaultrouter="10.10.1.1"
439
440Start the VDE switch as root:
441
442 # sysctl net.link.tap.user_open=1
443 # sysctl net.link.tap.up_on_open=1
444 # vde_switch -d -s /tmp/vde1 -M /tmp/mgmt1 -tap tap0 -m 660 --mgmtmode 660
445 # chmod 660 /dev/tap0
446
447You can connect to the VDE switch's management channel using:
448
449 $ vdeterm /tmp/mgmt1
450
451To run qemu:
452
453 $ qemu-system-arm \
454        -serial null \
455        -serial mon:stdio \
456        -nographic \
457        -M xilinx-zynq-a9 \
458        -net nic,model=cadence_gem,macaddr=0e:b0:ba:5e:ba:11 \
459        -net vde,id=vde0,sock=/tmp/vde1
460        -m 256M \
461        -kernel build/arm-rtems4.12-xilinx_zynq_a9_qemu/rcconf02.exe
462
463== Issues and TODO
464
465* PCI support on x86 uses a quick and dirty hack, see pci_reserve_map().
466
467* Priority queues are broken with clustered scheduling.
468
469* Per-CPU data should be enabled once the new stack is ready for SMP.
470
471* Per-CPU NETISR(9) should be enabled onece the new stack is ready for SMP.
472
473* Multiple routing tables are not supported.  Every FIB value is set to zero
474  (= BSD_DEFAULT_FIB).
475
476* Process identifiers are not supported.  Every PID value is set to zero
477  (= BSD_DEFAULT_PID).
478
479* User credentials are not supported.  The following functions allow the
480  operation for everyone
481  - prison_equal_ip4(),
482  - chgsbsize(),
483  - cr_cansee(),
484  - cr_canseesocket() and
485  - cr_canseeinpcb().
486
487* A basic USB functionality test that is known to work on Qemu is desirable.
488
489* Adapt generic IRQ PIC interface code to Simple Vectored Interrupt Model
490  so that those architectures can use new TCP/IP and USB code.
491
492* freebsd-userspace/rtems/include/sys/syslog.h is a copy from the old
493  RTEMS TCP/IP stack. For some reason, the __printflike markers do not
494  compile in this environment. We may want to use the FreeBSD syslog.h
495  and get this addressed.
496
497* in_cksum implementations for architectures not supported by FreeBSD.
498  This will require figuring out where to put implementations that do
499  not originate from FreeBSD and are populated via the script.
500
501* MAC support functions are not thread-safe ("freebsd/lib/libc/posix1e/mac.c").
502
503* IFCONFIG(8): IEEE80211 support is disabled.  This module depends on a XML
504  parser and mmap().
505
506* get_cyclecount(): The implementation is a security problem.
507
508* What to do with the priority parameter present in the FreeBSD synchronization
509  primitives and the thread creation functions?
510
511* TASKQUEUE(9): Support spin mutexes.
512
513* ZONE(9): Review allocator lock usage in rtems-bsd-chunk.c.
514
515* KQUEUE(2): Choose proper lock for global kqueue list.
516
517* TIMEOUT(9): Maybe use special task instead of timer server to call
518  callout_tick().
519
520* sysctl_handle_opaque(): Implement reliable snapshots.
521
522* PING6(8): What to do with SIGALARM?
523
524* <sys/param.h>: Update Newlib to use a MSIZE of 256.
525
526* BPF(4): Add support for zero-copy buffers.
527
528* UNIX(4): Fix race conditions in the area of socket object and file node
529  destruction.  Add support for file descriptor transmission via control
530  messages.
531
532* PRINTF(9): Add support for log(), the %D format specifier is missing in the
533  normal printf() family.
534
535* Why is the interrupt server used?  The BSD interrupt handlers can block on
536synchronization primitives like mutexes.  This is in contrast to RTEMS
537interrupt service routines.  The BSPs using the generic interrupt support must
538implement the `bsp_interrupt_vector_enable()` and
539`bsp_interrupt_vector_disable()` routines.  They normally enable/disable a
540particular interrupt source at the interrupt controller.  This can be used to
541implement the interrupt server.  The interrupt server is a task that wakes-up
542in case an associated interrupt happens.  The interrupt source is disabled in
543a generic interrupt handler that wakes-up the interrupt server task.   Once the
544postponed interrupt processing is performed in the interrupt server the
545interrupt source is enabled again.
546
547* Convert all BSP linkcmds to use a linkcmds.base so the sections are
548easier to insert.
549
550* NIC Device Drivers
551- Only common PCI NIC drivers have been included in the initial set. These
552do not include any system on chip or ISA drivers.
553- PCI configuration probe does not appear to happen to determine if a
554NIC is in I/O or memory space. We have worked around this by using a
555static hint to tell the fxp driver the correct mode. But this needs to
556be addressed.
557- The ISA drivers require more BSD infrastructure to be addressed. This was
558outside the scope of the initial porting effort.
559
560== FreeBSD Source
561
562You should be able to rely on FreebSD manual pages and documentation
563for details on the code itself.
564
565== BSD Library Source
566
567== Initialization of the BSD Library
568
569The initialization of the BSD library is based on the FreeBSD SYSINIT(9)
570infrastructure.  The key to initializing a system is to ensure that the desired
571device drivers are explicitly pulled into the linked application.  This plus
572linking against the BSD library (`libbsd.a`) will pull in the necessary FreeBSD
573infrastructure.
574
575The FreeBSD kernel is not a library like the RTEMS kernel.  It is a bunch of
576object files linked together.  If we have a library, then creating the
577executable is simple.  We begin with a start symbol and recursively resolve all
578references.  With a bunch of object files linked together we need a different
579mechanism.  Most object files don't know each other.  Lets say we have a driver
580module.  The rest of the system has no references to this driver module.  The
581driver module needs a way to tell the rest of the system: Hey, kernel I am
582here, please use my services!
583
584This registration of independent components is performed by SYSINIT(9) and
585specializations:
586
587http://www.freebsd.org/cgi/man.cgi?query=SYSINIT
588
589The SYSINIT(9) uses some global data structures that are placed in a certain
590section.  In the linker command file we need this:
591
592-------------------------------------------------------------------------------
593.rtemsroset : {
594        KEEP (*(SORT(.rtemsroset.*)))
595}
596
597.rtemsrwset : {
598        KEEP (*(SORT(.rtemsrwset.*)))
599}
600-------------------------------------------------------------------------------
601
602This results for example in this executable layout:
603
604-------------------------------------------------------------------------------
605[...]
606 *(SORT(.rtemsroset.*))
607 .rtemsroset.bsd.modmetadata_set.begin
608                0x000000000025fe00        0x0 libbsd.a(rtems-bsd-init.o)
609                0x000000000025fe00                _bsd__start_set_modmetadata_set
610 .rtemsroset.bsd.modmetadata_set.content
611                0x000000000025fe00        0x8 libbsd.a(rtems-bsd-nexus.o)
612 .rtemsroset.bsd.modmetadata_set.content
613                0x000000000025fe08        0x4 libbsd.a(kern_module.o)
614[...]
615 .rtemsroset.bsd.modmetadata_set.content
616                0x000000000025fe68        0x4 libbsd.a(mii.o)
617 .rtemsroset.bsd.modmetadata_set.content
618                0x000000000025fe6c        0x4 libbsd.a(mii_bitbang.o)
619 .rtemsroset.bsd.modmetadata_set.end
620                0x000000000025fe70        0x0 libbsd.a(rtems-bsd-init.o)
621                0x000000000025fe70                _bsd__stop_set_modmetadata_set
622[...]
623.rtemsrwset     0x000000000030bad0      0x290
624 *(SORT(.rtemsrwset.*))
625 .rtemsrwset.bsd.sysinit_set.begin
626                0x000000000030bad0        0x0 libbsd.a(rtems-bsd-init.o)
627                0x000000000030bad0                _bsd__start_set_sysinit_set
628 .rtemsrwset.bsd.sysinit_set.content
629                0x000000000030bad0        0x4 libbsd.a(rtems-bsd-nexus.o)
630 .rtemsrwset.bsd.sysinit_set.content
631                0x000000000030bad4        0x8 libbsd.a(rtems-bsd-thread.o)
632 .rtemsrwset.bsd.sysinit_set.content
633                0x000000000030badc        0x4 libbsd.a(init_main.o)
634[...]
635 .rtemsrwset.bsd.sysinit_set.content
636                0x000000000030bd54        0x4 libbsd.a(frag6.o)
637 .rtemsrwset.bsd.sysinit_set.content
638                0x000000000030bd58        0x8 libbsd.a(uipc_accf.o)
639 .rtemsrwset.bsd.sysinit_set.end
640                0x000000000030bd60        0x0 libbsd.a(rtems-bsd-init.o)
641                0x000000000030bd60                _bsd__stop_set_sysinit_set
642[...]
643-------------------------------------------------------------------------------
644
645Here you can see, that some global data structures are collected into
646continuous memory areas.  This memory area can be identified by start and stop
647symbols.  This constructs a table of uniform items.
648
649The low level FreeBSD code calls at some time during the initialization the
650mi_startup() function (machine independent startup).  This function will sort
651the SYSINIT(9) set and call handler functions which perform further
652initialization.  The last step is the scheduler invocation.
653
654The SYSINIT(9) routines are run in mi_startup() which is called by
655rtems_bsd_initialize().
656
657This is also explained in "The Design and Implementation of the FreeBSD
658Operating System" section 14.3 "Kernel Initialization".
659
660In RTEMS we have a library and not a bunch of object files.  Thus we need a way
661to pull-in the desired services out of the libbsd.  Here the
662`rtems-bsd-sysinit.h` comes into play.  The SYSINIT(9) macros have been
663modified and extended for RTEMS in `<sys/kernel.h>`:
664
665-------------------------------------------------------------------------------
666#ifndef __rtems__
667#define C_SYSINIT(uniquifier, subsystem, order, func, ident)    \
668        static struct sysinit uniquifier ## _sys_init = {       \
669                subsystem,                                      \
670                order,                                          \
671                func,                                           \
672                (ident)                                         \
673        };                                                      \
674        DATA_SET(sysinit_set,uniquifier ## _sys_init)
675#else /* __rtems__ */
676#define SYSINIT_ENTRY_NAME(uniquifier)                          \
677        _bsd_ ## uniquifier ## _sys_init
678#define SYSINIT_REFERENCE_NAME(uniquifier)                      \
679        _bsd_ ## uniquifier ## _sys_init_ref
680#define C_SYSINIT(uniquifier, subsystem, order, func, ident)    \
681        struct sysinit SYSINIT_ENTRY_NAME(uniquifier) = {       \
682                subsystem,                                      \
683                order,                                          \
684                func,                                           \
685                (ident)                                         \
686        };                                                      \
687        RWDATA_SET(sysinit_set,SYSINIT_ENTRY_NAME(uniquifier))
688#define SYSINIT_REFERENCE(uniquifier)                           \
689        extern struct sysinit SYSINIT_ENTRY_NAME(uniquifier);   \
690        static struct sysinit const * const                     \
691        SYSINIT_REFERENCE_NAME(uniquifier) __used               \
692        = &SYSINIT_ENTRY_NAME(uniquifier)
693#define SYSINIT_MODULE_REFERENCE(mod)                           \
694        SYSINIT_REFERENCE(mod ## module)
695#define SYSINIT_DRIVER_REFERENCE(driver, bus)                   \
696        SYSINIT_MODULE_REFERENCE(driver ## _ ## bus)
697#define SYSINIT_DOMAIN_REFERENCE(dom)                           \
698        SYSINIT_REFERENCE(domain_add_ ## dom)
699#endif /* __rtems__ */
700-------------------------------------------------------------------------------
701
702Here you see that the SYSINIT(9) entries are no longer static.  The
703\*_REFERENCE() macros will create references to the corresponding modules which
704are later resolved by the linker.  The application has to provide an object
705file with references to all required FreeBSD modules.
706
707The FreeBSD device model is quite elaborated (with follow-ups):
708
709http://www.freebsd.org/cgi/man.cgi?query=driver
710
711The devices form a tree with the Nexus device at a high-level.  This Nexus
712device is architecture specific in FreeBSD.  In RTEMS we have our own Nexus
713device, see `rtemsbsd/bsp/bsp-bsd-nexus-devices.c`.
714
715=== SYSCTL_NODE Example
716
717During development, we had an undefined reference to
718_bsd_sysctl__net_children that we had trouble tracking down. Thanks to
719Chris Johns, we located it. He explained how to read SYSCTL_NODE
720definitions. This line from freebsd/netinet/in_proto.c is attempting
721to add the "inet" node to the parent node "_net".
722
723----
724SYSCTL_NODE(_net,      PF_INET,         inet,   CTLFLAG_RW, 0,
725        "Internet Family");
726----
727
728Our problem was that we could not find where _bsd_sysctl__net_children
729was defined. Chris suggested that when in doubt compile with -save-temps
730and look at the preprocessed .i files. But he did not need that. He
731explained that this the symbol name _bsd_sysctl__net_children was
732automatically generated by a SYSCTL_NODE as follows:
733
734* _bsd_ - added by RTEMS modifications to SYSCTL_NODE macro
735* sysctl_ - boilerplace added by SYSCTL_NODE macro
736* "" - empty string for parent node
737* net - name of SYSCTL_NODE
738* children - added by SYSCTL macros
739
740This was all generated by a support macro declaring the node as this:
741
742----
743struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name);
744----
745
746Given this information, we located this SYSCTL_NODE declaration in
747kern/kern_mib.c
748
749----
750SYSCTL_NODE(, CTL_KERN,   kern,   CTLFLAG_RW, 0,
751        "High kernel, proc, limits &c");
752----
753
754== Core FreeBSD APIs and RTEMS Replacements ==
755
756=== SX(9) (Shared/exclusive locks) ===
757
758http://www.freebsd.org/cgi/man.cgi?query=sx
759
760Binary semaphores (this neglects the ability to allow shared access).
761
762=== MUTEX(9) (Mutual exclusion) ===
763
764http://www.freebsd.org/cgi/man.cgi?query=mutex
765
766Binary semaphores (not recursive mutexes are not supported this way).
767
768=== RWLOCK(9) (Reader/writer lock) ===
769
770http://www.freebsd.org/cgi/man.cgi?query=rwlock
771
772POSIX r/w lock.
773
774=== RMLOCK(9) (Reader/writer lock optimized for mostly read access patterns) ===
775
776Note:  This object was implemented as a wrapper for RWLOCK in the rm_lock header file.
777
778http://www.freebsd.org/cgi/man.cgi?query=rmlock
779
780POSIX r/w lock.
781
782=== CONDVAR(9) (Condition variables) ===
783
784http://www.freebsd.org/cgi/man.cgi?query=condvar
785
786POSIX condition variables with modifications (hack).
787
788=== CALLOUT(9) (Timer functions) ===
789
790http://www.freebsd.org/cgi/man.cgi?query=callout
791
792Timer server.
793
794=== TASKQUEUE(9) (Asynchronous task execution) ===
795
796http://www.freebsd.org/cgi/man.cgi?query=taskqueue
797
798TBD.
799
800=== KTHREAD(9), KPROC(9) (Tasks) ===
801
802http://www.freebsd.org/cgi/man.cgi?query=kthread
803
804http://www.freebsd.org/cgi/man.cgi?query=kproc
805
806Tasks.
807
808=== ZONE(9) (Zone allocator) ===
809
810http://www.freebsd.org/cgi/man.cgi?query=zone
811
812TBD.
813
814=== devfs (Device file system) ===
815
816There is a minimal implementation based on IMFS. The mount point is fixed to
817"/dev". Note that the devfs is only used by the cdev subsystem. cdev has been
818adapted so that the full path (including the leading "/dev") is given to devfs.
819This saves some copy operations.
820
821devfs_create() first creates the full path and then creates an IMFS generic node
822for the device.
823
824TBD: remove empty paths on devfs_destroy().
825
826=== psignal (Signals) ===
827
828TBD.  Seems to be not needed.
829
830=== poll, select ===
831
832TBD.  Seems to be not needed.
833
834=== RMAN(9) (Resource management) ===
835
836http://www.freebsd.org/cgi/man.cgi?query=rman
837
838TBD.  Seems to be not needed.
839
840=== DEVCLASS(9), DEVICE(9), DRIVER(9), MAKE_DEV(9) (Device management) ===
841
842http://www.freebsd.org/cgi/man.cgi?query=devclass
843
844http://www.freebsd.org/cgi/man.cgi?query=device
845
846http://www.freebsd.org/cgi/man.cgi?query=driver
847
848http://www.freebsd.org/cgi/man.cgi?query=make_dev
849
850Use FreeBSD implementation as far as possible.  FreeBSD has a nice API for
851dynamic device handling.  It may be interesting for RTEMS to use this API
852internally in the future.
853
854=== BUS_SPACE(9), BUS_DMA(9) (Bus and DMA access) ===
855
856http://www.freebsd.org/cgi/man.cgi?query=bus_space
857
858http://www.freebsd.org/cgi/man.cgi?query=bus_dma
859
860Likely BSP dependent.  A default implementation for memory mapped linear access
861is easy to provide.  The current heap implementation supports all properties
862demanded by bus_dma (including the boundary constraint).
863
864== RTEMS Replacements by File Description ==
865
866Note:  Files with a status of USB are used by the USB test and have at least
867been partially tested.  If they contain both USB and Nic, then they are used
868by both and MAY contain methods that have not been tested yet.  Files that
869are only used by the Nic test are the most suspect.
870
871----
872rtems-libbsd File:      rtems-bsd-assert.c
873FreeBSD File:           rtems-bsd-config.h redefines BSD_ASSERT.
874Description:            This file contains the support method rtems_bsd_assert_func().
875Status:                 USB, Nic
876
877rtems-libbsd File:      rtems-bsd-autoconf.c
878FreeBSD File:           FreeBSD has BSP specific autoconf.c
879Description:            This file contains configuration methods that are used to setup the system.
880Status:                 USB
881
882rtems-libbsd File:      rtems-bsd-bus-dma.c
883FreeBSD File:           FreeBSD has BSP specific busdma_machdep.c
884Description:
885Status:                 USB, Nic
886
887rtems-libbsd File:      rtems-bsd-bus-dma-mbuf.c
888FreeBSD File:           FreeBSD has BSP specific busdma_machdep.c
889Description:
890Status:                 Nic
891
892rtems-libbsd File:      rtems-bsd-callout.c
893FreeBSD File:           kern/kern_timeout.c
894Description:
895Status:                 USB, Nic
896
897rtems-libbsd File:      rtems-bsd-cam.c
898FreeBSD File:           cam/cam_sim.c
899Description:
900Status:                 USB
901
902rtems-libbsd File:      rtems-bsd-condvar.c
903FreeBSD File:           kern/kern_condvar.c
904Description:
905Status:                 USB
906
907rtems-libbsd File:      rtems-bsd-copyinout.c
908FreeBSD File:           bsp specific copyinout.c )
909Description:            Note: The FreeBSD file is split with some methods being in rtems-bsd-support
910Status:                 Nic
911
912rtems-libbsd File:      rtems-bsd-delay.c
913FreeBSD File:           bsp specific file with multiple names
914Description:
915Status:                 USB, Nic
916
917rtems-libbsd File:      rtems-bsd-descrip.c
918FreeBSD File:           kern/kern_descrip.c
919Description:
920Status:                 Nic
921
922rtems-libbsd File:      rtems-bsd-generic.c
923FreeBSD File:           kern/sys_generic.c
924Description:
925Status:                 Nic
926
927rtems-libbsd File:      rtems-bsd-init.c
928FreeBSD File:           N/A
929Description:
930Status:                 USB, Nic
931
932rtems-libbsd File:      rtems-bsd-init-with-irq.c
933FreeBSD File:           N/A
934Description:
935Status:                 USB, Nic
936
937rtems-libbsd File:      rtems-bsd-jail.c
938FreeBSD File:           kern/kern_jail.c
939Description:
940Status:                 USB, Nic
941
942rtems-libbsd File:      rtems-bsd-lock.c
943FreeBSD File:           kern/subr_lock.c
944Description:
945Status:                 USB, Nic
946
947rtems-libbsd File:      rtems-bsd-log.c
948FreeBSD File:           kern/subr_prf.c
949Description:
950Status:                 Nic
951
952rtems-libbsd File:      rtems-bsd-malloc.c
953FreeBSD File:           kern/kern_malloc.c
954Description:
955Status:                 USB, Nic
956
957rtems-libbsd File:      rtems-bsd-mutex.c
958FreeBSD File:           kern/kern_mutex.c
959Description:
960Status:                 USB, Nic
961
962rtems-libbsd File:      rtems-bsd-newproc.c
963FreeBSD File:           N/A
964Description:
965Status:                 Nic
966
967rtems-libbsd File:      rtems-bsd-nexus.c
968FreeBSD File:           bsp specific nexus.c
969Description:
970Status:                 USB
971
972rtems-libbsd File:      rtems-bsd-panic.c
973FreeBSD File:           boot/common/panic.c
974Description:
975Status:                 USB, Nic
976
977rtems-libbsd File:      rtems-bsd-rwlock.c
978FreeBSD File:           kern_rwlock.c
979Description:
980Status:                 USB, Nic
981
982rtems-libbsd File:      rtems-bsd-shell.c
983FreeBSD File:           N/A
984Description:
985Status:                 USB
986
987rtems-libbsd File:      rtems-bsd-signal.c
988FreeBSD File:           kern/kern_sig.c
989Description:
990Status:                 Nic
991
992rtems-libbsd File:      rtems-bsd-smp.c
993FreeBSD File:           N/A
994Description:
995Status:                 Nic
996
997rtems-libbsd File:      rtems-bsd-support.c
998FreeBSD File:           bsp specific copyinout.c
999Description:            Note: the FreeBSD file is split with some methods being in rtems-bsd-copyinout.
1000Status:                 USB, Nic
1001
1002rtems-libbsd File:      rtems-bsd-sx.c
1003FreeBSD File:           kern/kern_sx.c
1004Description:            Status: USB, Nic
1005
1006rtems-libbsd File:      rtems-bsd-synch.c
1007FreeBSD File:           kern/kern_synch.c
1008Description:
1009Status:                 USB, Nic
1010
1011rtems-libbsd File:      rtems-bsd-syscalls.c
1012FreeBSD File:           User API for kern/uipc_syscalls.c
1013Description:
1014Status:                 Nic
1015
1016rtems-libbsd File:      rtems-bsd-sysctlbyname.c
1017FreeBSD File:           User API for sysctlbyname(3)
1018Description:
1019Status:
1020
1021rtems-libbsd File:      rtems-bsd-sysctl.c
1022FreeBSD File:           User API for sysctl(8)
1023Description:
1024Status:
1025
1026rtems-libbsd File:      rtems-bsd-sysctlnametomib.c
1027FreeBSD File:           User API for sysctlnametomib
1028Description:
1029Status:
1030
1031rtems-libbsd File:      rtems-bsd-taskqueue.c
1032FreeBSD File:           kern/subr_taskqueue.c
1033Description:
1034Status:                 Nic
1035
1036rtems-libbsd File:      rtems-bsd-thread.c
1037FreeBSD File:           kern/kern_kthread.c
1038Description:
1039Status:                 USB, Nic
1040
1041rtems-libbsd File:      rtems-bsd-timeout.c
1042FreeBSD File:           kern/kern_timeout.c
1043Description:
1044Status:                 Nic
1045
1046rtems-libbsd File:      rtems-bsd-timesupport.c
1047FreeBSD File:           kern/kern_clock.c
1048Description:
1049Status:                 Nic
1050
1051rtems-libbsd File:      rtems-bsd-vm_glue.c
1052FreeBSD File:           vm/vm_glue.c
1053Description:
1054Status:                 USB, Nic
1055----
1056
1057== Notes by File ==
1058
1059altq_subr.c - Arbitrary choices were made in this file that RTEMS would
1060not support tsc frequency change.  Additionally, the clock frequency
1061for machclk_freq is always measured for RTEMS.
1062
1063conf.h - In order to add make_dev and destroy_dev, variables in the cdev
1064structure that were not being used were conditionally compiled out. The
1065capability of supporting children did not appear to be needed and was
1066not implemented in the rtems version of these routines.
1067
1068== NICs Status ==
1069
1070----
1071Driver                  Symbol                          Status
1072======                  ======                          ======
1073RealTek                 _bsd_re_pcimodule_sys_init      Links
1074EtherExpress            _bsd_fxp_pcimodule_sys_init     Links
1075DEC tulip               _bsd_dc_pcimodule_sys_init      Links
1076Broadcom BCM57xxx       _bsd_bce_pcimodule_sys_init     Links
1077Broadcom BCM4401        _bsd_bfe_pcimodule_sys_init     Links
1078Broadcom BCM570x        _bsd_bge_pcimodule_sys_init     Needs Symbols (A)
1079E1000 IGB               _bsd_igb_pcimodule_sys_init     Links
1080E1000 EM                _bsd_em_pcimodule_sys_init      Links
1081Cadence                 ?                               Links, works.
1082----
1083
1084To add a NIC edit rtemsbsd/include/bsp/nexus-devices.h and add the driver
1085reference to the architecture and/or BSP. For example to add the RealTek driver
1086add:
1087
1088SYSINIT_DRIVER_REFERENCE(re, pci);
1089
1090and to add the MII PHY driver add:
1091
1092SYSINIT_DRIVER_REFERENCE(rge, miibus);
1093
1094The PC BSP has these entries.
1095
1096Symbols (A)
1097         pci_get_vpd_ident
1098
1099=== Cadence ===
1100
1101The cadence driver works on the Xilinx Zynq platform. The hardware checksum
1102support works on real hardware but does not seem to be supported on qemu
1103therefore the default state is to disable TXCSUM and RXCSUM and this can be
1104enabled from the shell with:
1105
1106  # ifconfig cgem0 rxcsum txcsum
1107
1108or with an ioctl call to the network interface driver with SIOCSIFCAP and the
1109mask IFCAP_TXCSUM and IFCAP_RXCSUM set.
1110
1111== PF (Firewall) ==
1112
1113It is possible to use PF as a firewall. See
1114[https://www.freebsd.org/doc/handbook/firewalls-pf.html] for details on the
1115range of functions and for how to configure the firewall.
1116
1117The following is necessary to use PF on RTEMS:
1118
1119- You have to provide a +/etc/pf.os+ file. The firewall can use it for passive
1120  OS fingerprinting. If you don't want to use this feature, the file may contain
1121  nothing except a line of comment (for example "# empty").
1122
1123- If some filters use protocol names (like tcp or udp) you have to provide a
1124  +/etc/protocols+ file.
1125
1126- If some filters use service names (like ssh or http) you have to provide a
1127  +/etc/services+ file.
1128
1129- Create a rule file (normally +/etc/pf.conf+). See the FreeBSD manual for the
1130  syntax.
1131
1132- Load the rule file using the pfctl command and enable pf. Please note that the
1133  pfctl command needs a lot of stack. You should use at least
1134  RTEMS_MINIMUM_STACK_SIZE + 8192 Bytes of stack. An example initialisation can
1135  look like follows:
1136
1137----
1138        int exit_code;
1139        char *params[] = {
1140                "pfctl",
1141                "-f",
1142                "/etc/pf.conf",
1143                "-e",
1144                NULL
1145        };
1146
1147        exit_code = rtems_bsd_command_pfctl(ARGC(params), params);
1148        assert(exit_code == EXIT_SUCCSESS);
1149----
1150
1151=== Known restrictions ===
1152
1153- Currently PF on RTEMS always uses the configuration for memory restricted
1154  systems (on FreeBSD that means systems with less than 100 MB RAM). This is
1155  fixed in +pfctl_init_options()+.
1156
1157== Problems to report to FreeBSD ==
1158
1159The MMAP_NOT_AVAILABLE define is inverted on its usage.  When it is
1160defined the mmap method is called. Additionally, it is not used
1161thoroughly. It is not used in the unmap portion of the source.
1162The file rec_open.c uses the define MMAP_NOT_AVAILABLE to wrap
1163the call to mmap and file rec_close.c uses the munmap method.
Note: See TracBrowser for help on using the repository browser.