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