[8f5adbc] | 1 | RTEMS BSD USB and TCP/IP Developers Guide |
---|
| 2 | ========================================= |
---|
| 3 | Joel Sherrill <joel.sherrill@oarcorp.com> |
---|
| 4 | :Author Initials: JRS |
---|
| 5 | :toc: |
---|
| 6 | :icons: |
---|
| 7 | :numbered: |
---|
| 8 | :website: http://www.rtems.org/ |
---|
| 9 | |
---|
| 10 | RTEMS uses FreeBSD as the source of its TCP/IP and USB stacks. |
---|
| 11 | This is a developers guide which captures information on the |
---|
| 12 | process of merging code from FreeBSD, building this library, |
---|
| 13 | RTEMS specific support files, and general guidelines on what |
---|
| 14 | modifications to the FreeBSD source are permitted. |
---|
| 15 | |
---|
[e392fdb7] | 16 | Goals of this effort are: |
---|
| 17 | |
---|
| 18 | * Update TCP/IP and provide USB in RTEMS |
---|
| 19 | * Ease updating to future FreeBSD versions |
---|
| 20 | * Ease tracking changes in FreeBSD code |
---|
| 21 | * Minimize manual changes in FreeBSD code |
---|
| 22 | * Define stable kernel/device driver API which is implemented |
---|
| 23 | by both RTEMS and FreeBSD. This is the foundation of the port. |
---|
| 24 | |
---|
| 25 | We will work to push our changes upstream to the FreeBSD Project |
---|
| 26 | and minimize changes required at each update point. |
---|
| 27 | |
---|
[8f5adbc] | 28 | ************************************************************** |
---|
| 29 | This is a work in progress and is very likely to be incomplete. |
---|
| 30 | Please help by adding to it. |
---|
| 31 | ************************************************************** |
---|
| 32 | |
---|
| 33 | == Source Code Version Information |
---|
| 34 | |
---|
[e8b7066] | 35 | * FreeBSD 8.2 SVN r255967 |
---|
[8f5adbc] | 36 | * RTEMS 4.11 |
---|
| 37 | - BSP must have support for all new BSD sys sections |
---|
| 38 | - It is preferable if the BSP uses linkcmds.base. |
---|
| 39 | - BSP must be from an architecture with Programmable Interrupt Controller |
---|
| 40 | interrupt model. |
---|
| 41 | |
---|
[e8b7066] | 42 | The latest port uses the FreeBSD sources as a Git submodule which will |
---|
| 43 | generally be referred to as the FreeBSD source in this document. Previously a |
---|
| 44 | FreeBSD 8.2 SVN checkout was used. The SVN checkout command corresponding to |
---|
| 45 | the current Git submodule commit is this |
---|
| 46 | svn co http://svn.freebsd.org/base/releng/8.2 -r255967 freebsd-8.2 |
---|
[e392fdb7] | 47 | |
---|
[560eccf] | 48 | == Issues and To Do |
---|
[d652c3b] | 49 | * Per-CPU data should be enabled once the new stack is ready for SMP. |
---|
| 50 | |
---|
| 51 | * Per-CPU NETISR(9) should be enabled onece the new stack is ready for SMP. |
---|
| 52 | |
---|
[549488b] | 53 | * Multiple routing tables are not supported. Every FIB value is set to zero |
---|
| 54 | (= BSD_DEFAULT_FIB). |
---|
| 55 | |
---|
[cc5f4b2] | 56 | * Process identifiers are not supported. Every PID value is set to zero |
---|
| 57 | (= BSD_DEFAULT_PID). |
---|
| 58 | |
---|
[69b29a0] | 59 | * User credentials are not supported. The following functions allow the |
---|
| 60 | operation for everyone |
---|
| 61 | - prison_equal_ip4(), |
---|
| 62 | - chgsbsize(), |
---|
| 63 | - cr_cansee(), |
---|
| 64 | - cr_canseesocket() and |
---|
| 65 | - cr_canseeinpcb(). |
---|
| 66 | |
---|
[560eccf] | 67 | * Sebastian Huber and Joel Sherrill discussed the need for a a basic USB |
---|
| 68 | functionality test that is known to work on qemu pc. |
---|
| 69 | |
---|
[8f5adbc] | 70 | * Adapt generic IRQ PIC interface code to Simple Vectored Interrupt Model |
---|
| 71 | so that those architectures can use new TCP/IP and USB code. |
---|
[560eccf] | 72 | |
---|
[78e3181] | 73 | * freebsd-userspace/rtems/include/sys/syslog.h is a copy from the old |
---|
| 74 | RTEMS TCP/IP stack. For some reason, the __printflike markers do not |
---|
| 75 | compile in this environment. We may want to use the FreeBSD syslog.h |
---|
| 76 | and get this addressed. |
---|
| 77 | |
---|
[8f5adbc] | 78 | * in_cksum implementations for architectures not supported by FreeBSD. |
---|
| 79 | This will require figuring out where to put implementations that do |
---|
| 80 | not originate from FreeBSD and are populated via the script. |
---|
[560eccf] | 81 | |
---|
| 82 | * linker section issues: I have undefined symbols for |
---|
[362782e] | 83 | `_bsd__start_set_sysinit_set` and `_bsd__stop_set_sysinit_set`. |
---|
[560eccf] | 84 | Is this the only type of new section magic? What about the old sysctl_set? |
---|
| 85 | I added this to my linkcmds. |
---|
| 86 | |
---|
[cdf6024] | 87 | * MAC support functions are not thread-safe ("freebsd/lib/libc/posix1e/mac.c"). |
---|
| 88 | |
---|
[c14bb23] | 89 | * IFCONFIG(8): IEEE80211 support is disabled. This module depends on a XML |
---|
| 90 | parser and mmap(). |
---|
| 91 | |
---|
[560eccf] | 92 | [listing] |
---|
| 93 | ---- |
---|
| 94 | /* sysinit section? */ |
---|
| 95 | . = ALIGN (16); |
---|
| 96 | _bsd__start_set_sysinit_set = .; |
---|
| 97 | *(set_sys_init_*); |
---|
| 98 | _bsd__stop_set_sysinit_set = .; |
---|
| 99 | |
---|
| 100 | ---- |
---|
| 101 | |
---|
[362782e] | 102 | * Why is the interrupt server used? The BSD interrupt handlers can block on |
---|
| 103 | synchronization primitives like mutexes. This is in contrast to RTEMS |
---|
| 104 | interrupt service routines. The BSPs using the generic interrupt support must |
---|
| 105 | implement the `bsp_interrupt_vector_enable()` and |
---|
| 106 | `bsp_interrupt_vector_disable()` routines. They normally enable/disable a |
---|
| 107 | particular interrupt source at the interrupt controller. This can be used to |
---|
| 108 | implement the interrupt server. The interrupt server is a task that wakes-up |
---|
| 109 | in case an associated interrupt happens. The interrupt source is disabled in |
---|
| 110 | a generic interrupt handler that wakes-up the interrupt server task. Once the |
---|
| 111 | postponed interrupt processing is performed in the interrupt server the |
---|
| 112 | interrupt source is enabled again. |
---|
| 113 | |
---|
[560eccf] | 114 | * Convert all BSP linkcmds to use a linkcmds.base so the sections are |
---|
| 115 | easier to insert. |
---|
| 116 | |
---|
| 117 | * rtems-bsd-init-with-irq.c: |
---|
| 118 | rtems_bsd_initialize_with_interrupt_server() has reference to |
---|
| 119 | rtems_interrupt_server_initialize() and this method is unimplemented |
---|
| 120 | - XXX BSP implements pieces |
---|
| 121 | - BSPs using this software stack must support it apparently. |
---|
| 122 | - What about Simple Vectored architectures? |
---|
| 123 | |
---|
[78e3181] | 124 | * We carried over use of notepad 0 for per task information. This should |
---|
| 125 | be changed. |
---|
| 126 | |
---|
[560eccf] | 127 | * maxproc variable referenced by rtems-bsd-resource.c. What should it |
---|
| 128 | be set to? |
---|
| 129 | |
---|
| 130 | * ngroups_max variable referenced by rtems-bsd-prot.c. - What should |
---|
| 131 | it be set to? |
---|
[8f5adbc] | 132 | |
---|
[86bc9a7] | 133 | * NIC Device Drivers |
---|
[78e3181] | 134 | - Only common PCI NIC drivers have been included in the initial set. These |
---|
| 135 | do not include any system on chip or ISA drivers. |
---|
| 136 | - PCI configuration probe does not appear to happen to determine if a |
---|
| 137 | NIC is in I/O or memory space. We have worked around this by using a |
---|
| 138 | static hint to tell the fxp driver the correct mode. But this needs to |
---|
| 139 | be addressed. |
---|
[86bc9a7] | 140 | - The ISA drivers require more BSD infrastructure to be addressed. This was |
---|
| 141 | outside the scope of the initial porting effort. |
---|
| 142 | |
---|
[8f5adbc] | 143 | == FreeBSD Source |
---|
| 144 | |
---|
| 145 | You should be able to rely on FreebSD manual pages and documentation |
---|
| 146 | for details on the code itself. |
---|
| 147 | |
---|
| 148 | === Automatically Generated FreeBSD Files |
---|
| 149 | |
---|
| 150 | The FreeBSD source tarball includes a file named Makefile.rtems which |
---|
[455aa3a] | 151 | has stanzas to automatically generate some files using awk. For details |
---|
| 152 | on this, see http://www.freebsd.org/cgi/man.cgi?query=kobj&apropos=0&sektion=0&manpath=FreeBSD+9.0-RELEASE&arch=default&format=html |
---|
[8f5adbc] | 153 | |
---|
[455aa3a] | 154 | XXX This needs more detail. |
---|
[8f5adbc] | 155 | |
---|
| 156 | === Rules for Modifying FreeBSD Source |
---|
| 157 | |
---|
| 158 | * Only add lines. Subtract code by added "ifndef __rtems__". This makes |
---|
| 159 | merging easier in the future. |
---|
| 160 | |
---|
| 161 | == libbsd Source |
---|
| 162 | |
---|
| 163 | === What is in git |
---|
| 164 | |
---|
| 165 | The git source is a self-contained kit with FreeBSD and RTEMS components |
---|
| 166 | pre-merged. The Makefile in this kit is automatically generated. |
---|
| 167 | |
---|
| 168 | Any changes to sources in the freebsd or contrib directories will need to |
---|
| 169 | be merged upstream into our master FreeBSD svn checkout. |
---|
| 170 | |
---|
[c90c212] | 171 | The FreeBSD sources managed in the rtems-libbsd git repository (e.g. contrib |
---|
[560eccf] | 172 | and freebsd directories) contain the "managed" version of the |
---|
| 173 | FreeBSD source. The FreeBSD SVN source is the "master" version. The |
---|
| 174 | freebsd-to-rtems.py script is used to transfer files between the two |
---|
[c90c212] | 175 | trees. In general terms, if you have modified FreeBSD (i.e. anything in the |
---|
| 176 | freebsd directory) in the rtems-libbsd tree, you will need to run the script |
---|
| 177 | in "revert" or "reverse" mode using the -R switch. This will copy the source |
---|
| 178 | back to your local copy of the FreeBSD source so you can run "svn diff" against |
---|
| 179 | the upstream FreeBSD source. If you want to transfer source files from the |
---|
| 180 | FreeBSD SVN checkout to the rtems-libbsd tree, then you must run the script in |
---|
| 181 | "forward" mode (the default). |
---|
[560eccf] | 182 | |
---|
[c90c212] | 183 | === Building rtems-libbsd source |
---|
[8f5adbc] | 184 | |
---|
[455aa3a] | 185 | You need to configure RTEMS for the desired BSP and install it. The |
---|
| 186 | following is the script used to build the powerpc/psim BSP for our |
---|
| 187 | internal testing purposes: |
---|
| 188 | |
---|
| 189 | [listing] |
---|
| 190 | ---- |
---|
| 191 | #! /bin/sh |
---|
| 192 | |
---|
| 193 | cd ${HOME}/newbsd |
---|
| 194 | rm -rf b-psim |
---|
| 195 | mkdir b-psim |
---|
| 196 | cd b-psim |
---|
| 197 | ../git/rtems/configure --target=powerpc-rtems4.11 \ |
---|
| 198 | --enable-rtemsbsp=psim --disable-networking \ |
---|
| 199 | --enable-tests=samples \ |
---|
| 200 | --prefix=${HOME}/newbsd/bsp-install >c.log 2>&1 && \ |
---|
| 201 | make >b.log 2>&1 && \ |
---|
| 202 | make install >i.log 2>&1 |
---|
| 203 | echo $? |
---|
| 204 | ---- |
---|
| 205 | |
---|
| 206 | Then edit the file config.inc to set RTEMS_MAKEFILE_PATH appropriately |
---|
| 207 | to indicate the ${prefix}/${target}/${BSP}. Continuing on the above, |
---|
| 208 | the config.inc used to match the above is: |
---|
| 209 | |
---|
| 210 | [listing] |
---|
| 211 | ---- |
---|
| 212 | RTEMS_MAKEFILE_PATH = ${HOME}/newbsd/bsp-install/powerpc-rtems4.11/psim/ |
---|
| 213 | INSTALL_BASE = ${HOME}/newbsd/install |
---|
| 214 | ---- |
---|
| 215 | |
---|
[c90c212] | 216 | The above installs the rtems-libbsd kit into a separate place from |
---|
| 217 | RTEMS and the BSP. The rtems-libbsd tests are built against an installed |
---|
| 218 | image of the rtems-libbsd. By keeping it in a separate installation point |
---|
[455aa3a] | 219 | from RTEMS itself, this makes it easier to remove a libbsd installation |
---|
| 220 | and have a clean test point. |
---|
[8f5adbc] | 221 | |
---|
| 222 | [listing] |
---|
| 223 | ---- |
---|
| 224 | make |
---|
| 225 | make install |
---|
| 226 | make -C testsuite |
---|
| 227 | ---- |
---|
| 228 | |
---|
| 229 | At this point, we expect multiple linker errors. That is what we are |
---|
| 230 | currently working on. |
---|
| 231 | |
---|
| 232 | === Organization |
---|
| 233 | |
---|
| 234 | The top level directory contains a few directories and files. The following |
---|
| 235 | are important to understand: |
---|
| 236 | |
---|
| 237 | * freebsd-to-rtems.py - script to convert to and free FreeBSD and RTEMS trees |
---|
| 238 | * Makefile - automatically generated |
---|
| 239 | * contrib/ - from FreeBSD by script. |
---|
| 240 | * freebsd/ - from FreeBSD by script. |
---|
| 241 | * rtemsbsd/ - RTEMS specific implementations of FreeBSD kernel support routines. |
---|
| 242 | * testsuite/ - RTEMS specific tests |
---|
| 243 | * libbsd.txt - Documentation in Asciidoc |
---|
| 244 | |
---|
[c90c212] | 245 | == Moving Code Between FreeBSD SVN and rtems-libbsd |
---|
[e392fdb7] | 246 | |
---|
| 247 | The script freebsd-to-rtems.py is used to copy code from FreeBSD to the |
---|
[c90c212] | 248 | rtems-libbsd tree and to reverse this process. This script attempts to |
---|
[e392fdb7] | 249 | automate this process as much as possible and performs some transformations |
---|
| 250 | on the FreeBSD code. Its command line arguments are shown below: |
---|
| 251 | |
---|
| 252 | [listing] |
---|
| 253 | ---- |
---|
| 254 | freebsd-to-rtems.py [args] |
---|
| 255 | -?|-h|--help print this and exit |
---|
| 256 | -d|--dry-run run program but no modifications |
---|
[7326d96] | 257 | -D|--diff provide diff of files between trees |
---|
[e392fdb7] | 258 | -e|--early-exit evaluate arguments, print results, and exit |
---|
| 259 | -m|--makefile just generate Makefile |
---|
| 260 | -R|--reverse default FreeBSD -> RTEMS, reverse that |
---|
| 261 | -r|--rtems RTEMS directory |
---|
| 262 | -f|--freebsd FreeBSD directory |
---|
| 263 | -v|--verbose enable verbose output mode |
---|
| 264 | ---- |
---|
| 265 | |
---|
| 266 | In its default mode of operation, freebsd-to-rtems.py is used to copy code |
---|
[c90c212] | 267 | from FreeBSD to the rtems-libbsd tree and perform transformations. In forward |
---|
[e392fdb7] | 268 | mode, the script may be requested to just generate the Makefile. |
---|
| 269 | |
---|
| 270 | In "reverse mode", this script undoes those transformations and copies |
---|
| 271 | the source code back to the FreeBSD SVN tree. This allows us to do |
---|
| 272 | 'svn diff', evaluate changes made by the RTEMS Project, and report changes |
---|
| 273 | back to FreeBSD upstream. |
---|
| 274 | |
---|
| 275 | In either mode, the script may be asked to perform a dry-run or be verbose. |
---|
| 276 | Also, in either mode, the script is also smart enough to avoid copying over |
---|
| 277 | files which have not changed. This means that the timestamps of files are |
---|
| 278 | not changed unless the contents change. The script will also report the |
---|
| 279 | number of files which changed. In verbose mode, the script will print |
---|
| 280 | the name of the files which are changed. |
---|
| 281 | |
---|
| 282 | The following is an example forward run with no changes. |
---|
| 283 | |
---|
| 284 | [listing] |
---|
| 285 | ---- |
---|
| 286 | $ ~/newbsd/git/libbsd-8.2/freebsd-to-rtems.py \ |
---|
| 287 | -r /home/joel/newbsd/git/libbsd-8.2 \ |
---|
| 288 | -f /home/joel/newbsd/libbsd/freebsd-8.2 -v |
---|
| 289 | Verbose: yes |
---|
| 290 | Dry Run: no |
---|
| 291 | Only Generate Makefile: no |
---|
| 292 | RTEMS Directory: /home/joel/newbsd/git/libbsd-8.2 |
---|
| 293 | FreeBSD Directory: /home/joel/newbsd/libbsd/freebsd-8.2 |
---|
| 294 | Direction: forward |
---|
| 295 | Generating into /home/joel/newbsd/git/libbsd-8.2 |
---|
| 296 | 0 files were changed. |
---|
| 297 | ---- |
---|
| 298 | |
---|
[7326d96] | 299 | The script may also be used to generate a diff in either forward or reverse |
---|
| 300 | direction. |
---|
| 301 | |
---|
[c90c212] | 302 | == Initialization of rtems-libbsd |
---|
[455aa3a] | 303 | |
---|
[c90c212] | 304 | The initialization of the rtems-libbsd is based on the FreeBSD SYSINIT(9) |
---|
[8a4f070] | 305 | infrastructure. The key to initializing a system is to ensure that the desired |
---|
| 306 | device drivers are explicitly pulled into the linked application. This plus |
---|
| 307 | linking against the libbsd library will pull in the necessary FreeBSD |
---|
| 308 | infrastructure. |
---|
[455aa3a] | 309 | |
---|
[8a4f070] | 310 | The FreeBSD kernel is not a library like the RTEMS kernel. It is a bunch of |
---|
| 311 | object files linked together. If we have a library, then creating the |
---|
| 312 | executable is simple. We begin with a start symbol and recursively resolve all |
---|
| 313 | references. With a bunch of object files linked together we need a different |
---|
| 314 | mechanism. Most object files don't know each other. Lets say we have a driver |
---|
| 315 | module. The rest of the system has no references to this driver module. The |
---|
| 316 | driver module needs a way to tell the rest of the system: Hey, kernel I am |
---|
| 317 | here, please use my services! |
---|
[455aa3a] | 318 | |
---|
[8a4f070] | 319 | This registration of independent components is performed by SYSINIT(9) and |
---|
| 320 | specializations: |
---|
| 321 | |
---|
| 322 | http://www.freebsd.org/cgi/man.cgi?query=SYSINIT |
---|
| 323 | |
---|
| 324 | The SYSINIT(9) uses some global data structures that are placed in a certain |
---|
| 325 | section. In the linker command file we need this: |
---|
| 326 | |
---|
| 327 | [listing] |
---|
| 328 | ---- |
---|
| 329 | .robsdsets : { |
---|
| 330 | _bsd__start_set_modmetadata_set = .; |
---|
| 331 | *(_bsd_set_modmetadata_set); |
---|
| 332 | _bsd__stop_set_modmetadata_set = .; |
---|
| 333 | _bsd__start_set_sysctl_set = .; |
---|
| 334 | *(_bsd_set_sysctl_set); |
---|
| 335 | _bsd__stop_set_sysctl_set = .; |
---|
| 336 | } > REGION_RODATA AT > REGION_RODATA_LOAD |
---|
| 337 | |
---|
| 338 | .rwbsdsets : { |
---|
| 339 | _bsd__start_set_sysinit_set = .; |
---|
| 340 | *(_bsd_set_sysinit_set); |
---|
| 341 | _bsd__stop_set_sysinit_set = .; |
---|
| 342 | } > REGION_DATA AT > REGION_DATA_LOAD |
---|
| 343 | ---- |
---|
| 344 | |
---|
| 345 | Here you can see, that these global data structures are collected into |
---|
| 346 | continuous memory areas. This memory area can be identified by start and stop |
---|
| 347 | symbols. This constructs a table of uniform items. |
---|
| 348 | |
---|
| 349 | The low level FreeBSD code calls at some time during the initialization the |
---|
| 350 | mi_startup() function (machine independent startup). This function will sort |
---|
| 351 | the SYSINIT(9) set and call handler functions which perform further |
---|
| 352 | initialization. The last step is the scheduler invocation. |
---|
| 353 | |
---|
| 354 | The SYSINIT(9) routines are run in mi_startup() which is called by |
---|
| 355 | rtems_bsd_initialize(). |
---|
| 356 | |
---|
| 357 | This is also explained in "The Design and Implementation of the FreeBSD |
---|
| 358 | Operating System" section 14.3 "Kernel Initialization". |
---|
| 359 | |
---|
| 360 | In RTEMS we have a library and not a bunch of object files. Thus we need a way |
---|
| 361 | to pull-in the desired services out of the libbsd. Here the |
---|
| 362 | "rtems-bsd-sysinit.h" comes into play. The SYSINIT(9) macros have been |
---|
| 363 | modified and extended for RTEMS in "sys/kernel.h": |
---|
| 364 | |
---|
| 365 | [listing] |
---|
| 366 | ---- |
---|
| 367 | #ifndef __rtems__ |
---|
| 368 | #define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ |
---|
| 369 | static struct sysinit uniquifier ## _sys_init = { \ |
---|
| 370 | subsystem, \ |
---|
| 371 | order, \ |
---|
| 372 | func, \ |
---|
| 373 | (ident) \ |
---|
| 374 | }; \ |
---|
| 375 | DATA_SET(sysinit_set,uniquifier ## _sys_init) |
---|
| 376 | #else /* __rtems__ */ |
---|
| 377 | #define SYSINIT_ENTRY_NAME(uniquifier) \ |
---|
| 378 | _bsd_ ## uniquifier ## _sys_init |
---|
| 379 | #define SYSINIT_REFERENCE_NAME(uniquifier) \ |
---|
| 380 | _bsd_ ## uniquifier ## _sys_init_ref |
---|
| 381 | #define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ |
---|
| 382 | struct sysinit SYSINIT_ENTRY_NAME(uniquifier) = { \ |
---|
| 383 | subsystem, \ |
---|
| 384 | order, \ |
---|
| 385 | func, \ |
---|
| 386 | (ident) \ |
---|
| 387 | }; \ |
---|
| 388 | DATA_SET(sysinit_set,SYSINIT_ENTRY_NAME(uniquifier)) |
---|
| 389 | #define SYSINIT_REFERENCE(uniquifier) \ |
---|
| 390 | extern struct sysinit SYSINIT_ENTRY_NAME(uniquifier); \ |
---|
| 391 | static struct sysinit const * const \ |
---|
| 392 | SYSINIT_REFERENCE_NAME(uniquifier) __used \ |
---|
| 393 | = &SYSINIT_ENTRY_NAME(uniquifier) |
---|
| 394 | #define SYSINIT_MODULE_REFERENCE(mod) \ |
---|
| 395 | SYSINIT_REFERENCE(mod ## module) |
---|
| 396 | #define SYSINIT_DRIVER_REFERENCE(driver, bus) \ |
---|
| 397 | SYSINIT_MODULE_REFERENCE(driver ## _ ## bus) |
---|
| 398 | #endif /* __rtems__ */ |
---|
| 399 | ---- |
---|
| 400 | |
---|
| 401 | Here you see that the SYSINIT(9) entries are no longer static. The |
---|
| 402 | *_REFERENCE() macros will create references to the corresponding modules which |
---|
| 403 | are later resolved by the linker. The application has to provide an object |
---|
| 404 | file with references to all required FreeBSD modules. |
---|
| 405 | |
---|
| 406 | The FreeBSD device model is quite elaborated (with follow-ups): |
---|
| 407 | |
---|
| 408 | http://www.freebsd.org/cgi/man.cgi?query=driver |
---|
| 409 | |
---|
| 410 | The devices form a tree with the Nexus device at a high-level. This Nexus |
---|
| 411 | device is architecture specific in FreeBSD. In RTEMS we have our own Nexus |
---|
| 412 | device, see "rtems-bsd-nexus.c". It uses a table to add child devices: |
---|
| 413 | |
---|
| 414 | [listing] |
---|
| 415 | ---- |
---|
| 416 | const char *const _bsd_nexus_devices [] = { |
---|
| 417 | #ifdef NEED_USB_OHCI |
---|
| 418 | "ohci", |
---|
| 419 | #endif |
---|
| 420 | #ifdef NEED_USB_EHCI |
---|
| 421 | "ehci", |
---|
| 422 | #endif |
---|
| 423 | #ifdef NEED_SDHC |
---|
| 424 | "sdhci", |
---|
| 425 | #endif |
---|
| 426 | NULL |
---|
| 427 | }; |
---|
| 428 | ---- |
---|
| 429 | |
---|
| 430 | This table must be provided by the application. |
---|
[00ee241] | 431 | |
---|
| 432 | === SYSCTL_NODE Example |
---|
| 433 | |
---|
| 434 | During development, we had an undefined reference to |
---|
| 435 | _bsd_sysctl__net_children that we had trouble tracking down. Thanks to |
---|
| 436 | Chris Johns, we located it. He explained how to read SYSCTL_NODE |
---|
| 437 | definitions. This line from freebsd/netinet/in_proto.c is attempting |
---|
| 438 | to add the "inet" node to the parent node "_net". |
---|
| 439 | |
---|
| 440 | [listing] |
---|
| 441 | ---- |
---|
| 442 | SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0, |
---|
| 443 | "Internet Family"); |
---|
| 444 | ---- |
---|
| 445 | |
---|
| 446 | Our problem was that we could not find where _bsd_sysctl__net_children |
---|
| 447 | was defined. Chris suggested that when in doubt compile with -save-temps |
---|
| 448 | and look at the preprocessed .i files. But he did not need that. He |
---|
| 449 | explained that this the symbol name _bsd_sysctl__net_children was |
---|
| 450 | automatically generated by a SYSCTL_NODE as follows: |
---|
| 451 | |
---|
| 452 | * _bsd_ - added by RTEMS modifications to SYSCTL_NODE macro |
---|
| 453 | * sysctl_ - boilerplace added by SYSCTL_NODE macro |
---|
| 454 | * "" - empty string for parent node |
---|
| 455 | * net - name of SYSCTL_NODE |
---|
| 456 | * children - added by SYSCTL macros |
---|
| 457 | |
---|
| 458 | This was all generated by a support macro declaring the node as this: |
---|
| 459 | |
---|
| 460 | [listing] |
---|
| 461 | ---- |
---|
| 462 | struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name); |
---|
| 463 | ---- |
---|
| 464 | |
---|
| 465 | Given this information, we located this SYSCTL_NODE declaration in |
---|
| 466 | kern/kern_mib.c |
---|
| 467 | |
---|
| 468 | [listing] |
---|
| 469 | ---- |
---|
| 470 | SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0, |
---|
| 471 | "High kernel, proc, limits &c"); |
---|
| 472 | ---- |
---|
| 473 | |
---|
[c03e095] | 474 | == Core FreeBSD APIs and RTEMS Replacements == |
---|
| 475 | |
---|
| 476 | === SX(9) (Shared/exclusive locks) === |
---|
| 477 | |
---|
| 478 | http://www.freebsd.org/cgi/man.cgi?query=sx |
---|
| 479 | |
---|
| 480 | Binary semaphores (this neglects the ability to allow shared access). |
---|
| 481 | |
---|
| 482 | === MUTEX(9) (Mutual exclusion) === |
---|
| 483 | |
---|
| 484 | http://www.freebsd.org/cgi/man.cgi?query=mutex |
---|
| 485 | |
---|
| 486 | Binary semaphores (not recursive mutexes are not supported this way). |
---|
| 487 | |
---|
| 488 | === RWLOCK(9) (Reader/writer lock) === |
---|
| 489 | |
---|
| 490 | http://www.freebsd.org/cgi/man.cgi?query=rwlock |
---|
| 491 | |
---|
| 492 | POSIX r/w lock. |
---|
| 493 | |
---|
| 494 | === RMLOCK(9) (Reader/writer lock optimized for mostly read access patterns) === |
---|
| 495 | |
---|
[5ab1e1d] | 496 | Note: This object was implemented as a wrapper for RWLOCK in the rm_lock header file. |
---|
| 497 | |
---|
[c03e095] | 498 | http://www.freebsd.org/cgi/man.cgi?query=rmlock |
---|
| 499 | |
---|
| 500 | POSIX r/w lock. |
---|
| 501 | |
---|
| 502 | === CONDVAR(9) (Condition variables) === |
---|
| 503 | |
---|
| 504 | http://www.freebsd.org/cgi/man.cgi?query=condvar |
---|
| 505 | |
---|
| 506 | POSIX condition variables with modifications (hack). |
---|
| 507 | |
---|
| 508 | === CALLOUT(9) (Timer functions) === |
---|
| 509 | |
---|
| 510 | http://www.freebsd.org/cgi/man.cgi?query=callout |
---|
| 511 | |
---|
| 512 | Timer server. |
---|
| 513 | |
---|
| 514 | === TASKQUEUE(9) (Asynchronous task execution) === |
---|
| 515 | |
---|
| 516 | http://www.freebsd.org/cgi/man.cgi?query=taskqueue |
---|
| 517 | |
---|
| 518 | TBD. |
---|
| 519 | |
---|
| 520 | === KTHREAD(9), KPROC(9) (Tasks) === |
---|
| 521 | |
---|
| 522 | http://www.freebsd.org/cgi/man.cgi?query=kthread |
---|
| 523 | |
---|
| 524 | http://www.freebsd.org/cgi/man.cgi?query=kproc |
---|
| 525 | |
---|
| 526 | Tasks. |
---|
| 527 | |
---|
| 528 | === ZONE(9) (Zone allocator) === |
---|
| 529 | |
---|
| 530 | http://www.freebsd.org/cgi/man.cgi?query=zone |
---|
| 531 | |
---|
| 532 | TBD. |
---|
| 533 | |
---|
| 534 | === devfs (Device file system) === |
---|
| 535 | |
---|
| 536 | Dummy, IMFS or new implementation (currently dummy). |
---|
| 537 | |
---|
| 538 | === psignal (Signals) === |
---|
| 539 | |
---|
| 540 | TBD. Seems to be not needed. |
---|
| 541 | |
---|
| 542 | === poll, select === |
---|
| 543 | |
---|
| 544 | TBD. Seems to be not needed. |
---|
| 545 | |
---|
| 546 | === RMAN(9) (Resource management) === |
---|
| 547 | |
---|
| 548 | http://www.freebsd.org/cgi/man.cgi?query=rman |
---|
| 549 | |
---|
| 550 | TBD. Seems to be not needed. |
---|
| 551 | |
---|
| 552 | === DEVCLASS(9), DEVICE(9), DRIVER(9), MAKE_DEV(9) (Device management) === |
---|
| 553 | |
---|
| 554 | http://www.freebsd.org/cgi/man.cgi?query=devclass |
---|
| 555 | |
---|
| 556 | http://www.freebsd.org/cgi/man.cgi?query=device |
---|
| 557 | |
---|
| 558 | http://www.freebsd.org/cgi/man.cgi?query=driver |
---|
| 559 | |
---|
| 560 | http://www.freebsd.org/cgi/man.cgi?query=make_dev |
---|
| 561 | |
---|
| 562 | Use FreeBSD implementation as far as possible. FreeBSD has a nice API for |
---|
| 563 | dynamic device handling. It may be interesting for RTEMS to use this API |
---|
| 564 | internally in the future. |
---|
| 565 | |
---|
| 566 | === BUS_SPACE(9), BUS_DMA(9) (Bus and DMA access) === |
---|
| 567 | |
---|
| 568 | http://www.freebsd.org/cgi/man.cgi?query=bus_space |
---|
| 569 | |
---|
| 570 | http://www.freebsd.org/cgi/man.cgi?query=bus_dma |
---|
| 571 | |
---|
| 572 | Likely BSP dependent. A default implementation for memory mapped linear access |
---|
| 573 | is easy to provide. The current heap implementation supports all properties |
---|
| 574 | demanded by bus_dma (including the boundary constraint). |
---|
[5ab1e1d] | 575 | |
---|
[7586492] | 576 | == RTEMS Replacements by File Description == |
---|
[5ab1e1d] | 577 | |
---|
| 578 | Note: Files with a status of USB are used by the USB test and have at least |
---|
| 579 | been partially tested. If they contain both USB and Nic, then they are used |
---|
| 580 | by both and MAY contain methods that have not been tested yet. Files that |
---|
| 581 | are only used by the Nic test are the most suspect. |
---|
| 582 | |
---|
[fb4c8a9] | 583 | [listing] |
---|
| 584 | ---- |
---|
[5ab1e1d] | 585 | rtems-libbsd File: rtems-bsd-assert.c |
---|
| 586 | FreeBSD File: rtems-bsd-config.h redefines BSD_ASSERT. |
---|
| 587 | Description: This file contains the support method rtems_bsd_assert_func(). |
---|
| 588 | Status: USB, Nic |
---|
| 589 | |
---|
| 590 | rtems-libbsd File: rtems-bsd-autoconf.c |
---|
| 591 | FreeBSD File: FreeBSD has BSP specific autoconf.c |
---|
| 592 | Description: This file contains configuration methods that are used to setup the system. |
---|
| 593 | Status: USB |
---|
| 594 | |
---|
| 595 | rtems-libbsd File: rtems-bsd-bus-dma.c |
---|
| 596 | FreeBSD File: FreeBSD has BSP specific busdma_machdep.c |
---|
| 597 | Description: |
---|
| 598 | Status: USB, Nic |
---|
| 599 | |
---|
| 600 | rtems-libbsd File: rtems-bsd-bus-dma-mbuf.c |
---|
| 601 | FreeBSD File: FreeBSD has BSP specific busdma_machdep.c |
---|
| 602 | Description: |
---|
| 603 | Status: Nic |
---|
| 604 | |
---|
| 605 | rtems-libbsd File: rtems-bsd-callout.c |
---|
| 606 | FreeBSD File: kern/kern_timeout.c |
---|
| 607 | Description: |
---|
| 608 | Status: USB, Nic |
---|
| 609 | |
---|
| 610 | rtems-libbsd File: rtems-bsd-cam.c |
---|
| 611 | FreeBSD File: cam/cam_sim.c |
---|
| 612 | Description: |
---|
| 613 | Status: USB |
---|
| 614 | |
---|
| 615 | rtems-libbsd File: rtems-bsd-condvar.c |
---|
| 616 | FreeBSD File: kern/kern_condvar.c |
---|
| 617 | Description: |
---|
| 618 | Status: USB |
---|
| 619 | |
---|
| 620 | rtems-libbsd File: rtems-bsd-copyinout.c |
---|
| 621 | FreeBSD File: bsp specific copyinout.c ) |
---|
| 622 | Description: Note: The FreeBSD file is split with some methods being in rtems-bsd-support |
---|
| 623 | Status: Nic |
---|
| 624 | |
---|
| 625 | rtems-libbsd File: rtems-bsd-delay.c |
---|
| 626 | FreeBSD File: bsp specific file with multiple names |
---|
| 627 | Description: |
---|
| 628 | Status: USB, Nic |
---|
| 629 | |
---|
| 630 | rtems-libbsd File: rtems-bsd-descrip.c |
---|
| 631 | FreeBSD File: kern/kern_descrip.c |
---|
| 632 | Description: |
---|
| 633 | Status: Nic |
---|
| 634 | |
---|
| 635 | rtems-libbsd File: rtems-bsd-generic.c |
---|
| 636 | FreeBSD File: kern/sys_generic.c |
---|
| 637 | Description: |
---|
| 638 | Status: Nic |
---|
| 639 | |
---|
| 640 | rtems-libbsd File: rtems-bsd-init.c |
---|
| 641 | FreeBSD File: N/A |
---|
| 642 | Description: |
---|
| 643 | Status: USB, Nic |
---|
| 644 | |
---|
| 645 | rtems-libbsd File: rtems-bsd-init-with-irq.c |
---|
| 646 | FreeBSD File: N/A |
---|
| 647 | Description: |
---|
| 648 | Status: USB, Nic |
---|
| 649 | |
---|
| 650 | rtems-libbsd File: rtems-bsd-jail.c |
---|
| 651 | FreeBSD File: kern/kern_jail.c |
---|
| 652 | Description: |
---|
| 653 | Status: USB, Nic |
---|
| 654 | |
---|
| 655 | rtems-libbsd File: rtems-bsd-lock.c |
---|
| 656 | FreeBSD File: kern/subr_lock.c |
---|
| 657 | Description: |
---|
| 658 | Status: USB, Nic |
---|
| 659 | |
---|
| 660 | rtems-libbsd File: rtems-bsd-log.c |
---|
| 661 | FreeBSD File: kern/subr_prf.c |
---|
| 662 | Description: |
---|
| 663 | Status: Nic |
---|
| 664 | |
---|
| 665 | rtems-libbsd File: rtems-bsd-malloc.c |
---|
| 666 | FreeBSD File: kern/kern_malloc.c |
---|
| 667 | Description: |
---|
| 668 | Status: USB, Nic |
---|
| 669 | |
---|
| 670 | rtems-libbsd File: rtems-bsd-mutex.c |
---|
| 671 | FreeBSD File: kern/kern_mutex.c |
---|
| 672 | Description: |
---|
| 673 | Status: USB, Nic |
---|
| 674 | |
---|
| 675 | rtems-libbsd File: rtems-bsd-newproc.c |
---|
| 676 | FreeBSD File: N/A |
---|
| 677 | Description: |
---|
| 678 | Status: Nic |
---|
| 679 | |
---|
| 680 | rtems-libbsd File: rtems-bsd-nexus.c |
---|
| 681 | FreeBSD File: bsp specific nexus.c |
---|
| 682 | Description: |
---|
| 683 | Status: USB |
---|
| 684 | |
---|
| 685 | rtems-libbsd File: rtems-bsd-panic.c |
---|
| 686 | FreeBSD File: boot/common/panic.c |
---|
| 687 | Description: |
---|
| 688 | Status: USB, Nic |
---|
| 689 | |
---|
| 690 | rtems-libbsd File: rtems-bsd-rwlock.c |
---|
| 691 | FreeBSD File: kern_rwlock.c |
---|
| 692 | Description: |
---|
| 693 | Status: USB, Nic |
---|
| 694 | |
---|
| 695 | rtems-libbsd File: rtems-bsd-shell.c |
---|
| 696 | FreeBSD File: N/A |
---|
| 697 | Description: |
---|
| 698 | Status: USB |
---|
| 699 | |
---|
| 700 | rtems-libbsd File: rtems-bsd-signal.c |
---|
| 701 | FreeBSD File: kern/kern_sig.c |
---|
| 702 | Description: |
---|
| 703 | Status: Nic |
---|
| 704 | |
---|
| 705 | rtems-libbsd File: rtems-bsd-smp.c |
---|
| 706 | FreeBSD File: N/A |
---|
| 707 | Description: |
---|
| 708 | Status: Nic |
---|
| 709 | |
---|
| 710 | rtems-libbsd File: rtems-bsd-support.c |
---|
| 711 | FreeBSD File: bsp specific copyinout.c |
---|
| 712 | Description: Note: the FreeBSD file is split with some methods being in rtems-bsd-copyinout. |
---|
| 713 | Status: USB, Nic |
---|
| 714 | |
---|
| 715 | rtems-libbsd File: rtems-bsd-sx.c |
---|
| 716 | FreeBSD File: kern/kern_sx.c |
---|
| 717 | Description: Status: USB, Nic |
---|
| 718 | |
---|
| 719 | rtems-libbsd File: rtems-bsd-synch.c |
---|
| 720 | FreeBSD File: kern/kern_synch.c |
---|
| 721 | Description: |
---|
| 722 | Status: USB, Nic |
---|
| 723 | |
---|
| 724 | rtems-libbsd File: rtems-bsd-syscalls.c |
---|
| 725 | FreeBSD File: User API for kern/uipc_syscalls.c |
---|
| 726 | Description: |
---|
| 727 | Status: Nic |
---|
| 728 | |
---|
| 729 | rtems-libbsd File: rtems-bsd-sysctlbyname.c |
---|
| 730 | FreeBSD File: User API for sysctlbyname(3) |
---|
| 731 | Description: |
---|
| 732 | Status: |
---|
| 733 | |
---|
| 734 | rtems-libbsd File: rtems-bsd-sysctl.c |
---|
| 735 | FreeBSD File: User API for sysctl(8) |
---|
| 736 | Description: |
---|
| 737 | Status: |
---|
| 738 | |
---|
| 739 | rtems-libbsd File: rtems-bsd-sysctlnametomib.c |
---|
| 740 | FreeBSD File: User API for sysctlnametomib |
---|
| 741 | Description: |
---|
| 742 | Status: |
---|
| 743 | |
---|
| 744 | rtems-libbsd File: rtems-bsd-taskqueue.c |
---|
| 745 | FreeBSD File: kern/subr_taskqueue.c |
---|
| 746 | Description: |
---|
| 747 | Status: Nic |
---|
| 748 | |
---|
| 749 | rtems-libbsd File: rtems-bsd-thread.c |
---|
| 750 | FreeBSD File: kern/kern_kthread.c |
---|
| 751 | Description: |
---|
| 752 | Status: USB, Nic |
---|
| 753 | |
---|
| 754 | rtems-libbsd File: rtems-bsd-timeout.c |
---|
| 755 | FreeBSD File: kern/kern_timeout.c |
---|
| 756 | Description: |
---|
| 757 | Status: Nic |
---|
| 758 | |
---|
| 759 | rtems-libbsd File: rtems-bsd-timesupport.c |
---|
| 760 | FreeBSD File: kern/kern_clock.c |
---|
| 761 | Description: |
---|
| 762 | Status: Nic |
---|
| 763 | |
---|
| 764 | rtems-libbsd File: rtems-bsd-vm_glue.c |
---|
| 765 | FreeBSD File: vm/vm_glue.c |
---|
| 766 | Description: |
---|
| 767 | Status: USB, Nic |
---|
[fb4c8a9] | 768 | ---- |
---|
| 769 | |
---|
| 770 | == Notes by File == |
---|
[7586492] | 771 | |
---|
[fb4c8a9] | 772 | altq_subr.c - Arbitrary choices were made in this file that RTEMS would |
---|
| 773 | not support tsc frequency change. Additionally, the clock frequency |
---|
| 774 | for machclk_freq is always measured for RTEMS. |
---|
| 775 | |
---|
| 776 | conf.h - In order to add make_dev and destroy_dev, variables in the cdev |
---|
| 777 | structure that were not being used were conditionally compiled out. The |
---|
| 778 | capability of supporting children did not appear to be needed and was |
---|
| 779 | not implemented in the rtems version of these routines. |
---|
| 780 | |
---|
[7586492] | 781 | == NICs Status == |
---|
| 782 | |
---|
[fb4c8a9] | 783 | [listing] |
---|
| 784 | ---- |
---|
[7586492] | 785 | Driver Symbol Status |
---|
| 786 | ====== ====== ====== |
---|
| 787 | RealTek _bsd_re_pcimodule_sys_init Links |
---|
| 788 | EtherExpress _bsd_fxp_pcimodule_sys_init Links |
---|
| 789 | DEC tulip _bsd_dc_pcimodule_sys_init Links |
---|
| 790 | Broadcom BCM57xxx _bsd_bce_pcimodule_sys_init Links |
---|
| 791 | Broadcom BCM4401 _bsd_bfe_pcimodule_sys_init Links |
---|
| 792 | Broadcom BCM570x _bsd_bge_pcimodule_sys_init Needs Symbols (A) |
---|
[fb4c8a9] | 793 | E1000 IGB _bsd_igb_pcimodule_sys_init Links |
---|
| 794 | E1000 EM _bsd_em_pcimodule_sys_init Links |
---|
| 795 | ---- |
---|
[7586492] | 796 | |
---|
| 797 | |
---|
| 798 | Symbols (A) |
---|
| 799 | pci_get_vpd_ident |
---|
[99dc0d7] | 800 | |
---|
| 801 | == Problems to report to FreeBSD == |
---|
| 802 | |
---|
| 803 | The MMAP_NOT_AVAILABLE define is inverted on its usage. When it is |
---|
| 804 | defined the mmap method is called. Additionally, it is not used |
---|
| 805 | thoroughly. It is not used in the unmap portion of the source. |
---|
[808a6b2] | 806 | The file rec_open.c uses the define MMAP_NOT_AVAILABLE to wrap |
---|
| 807 | the call to mmap and file rec_close.c uses the munmap method. |
---|
[99dc0d7] | 808 | |
---|
| 809 | |
---|
| 810 | |
---|