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