Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
.\"	$NetBSD: compat_freebsd.8,v 1.19 2018/02/10 08:54:22 maxv Exp $
.\"	from: compat_linux.8,v 1.1 1995/03/05 23:30:36 fvdl Exp
.\"
.\" Copyright (c) 1995 Frank van der Linden
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"      This product includes software developed for the NetBSD Project
.\"      by Frank van der Linden
.\" 4. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd February 10, 2018
.Dt COMPAT_FREEBSD 8
.Os
.Sh NAME
.Nm compat_freebsd
.Nd setup procedure for running FreeBSD binaries
.Sh DESCRIPTION
.Bf -symbolic
compat_freebsd is not maintained anymore, and new FreeBSD binaries cannot
be expected to work.
The compat_freebsd feature is available in NetBSD only to support the
FreeBSD tw_cli driver.
.Ef
.Pp
.Nx
supports running
.Fx
binaries.
Most binaries should work, except programs that use
.Fx Ns -specific
features.
These include i386-specific calls, such as syscons utilities.
The
.Fx
compatibility feature is active for kernels compiled
with the
.Dv COMPAT_FREEBSD
option enabled.
.Pp
A lot of programs are dynamically linked.
This means, that you will also need the
.Fx
shared libraries that the program depends on, and the runtime
linker.
Also, you will need to create a
.Dq shadow root
directory for
.Fx
binaries on your
.Nx
system.
This directory is named
.Pa /emul/freebsd .
Any file operations done by
.Fx
programs run under
.Nx
will look in this directory first.
So, if a
.Fx
program opens, for example,
.Pa /etc/passwd ,
.Nx
will
first try to open
.Pa /emul/freebsd/etc/passwd ,
and if that does not exist open the
.Sq real
.Pa /etc/passwd
file.
It is recommended that you install
.Fx
packages that include configuration files, etc under
.Pa /emul/freebsd ,
to avoid naming conflicts with possible
.Nx
counterparts.
Shared libraries should also be installed in the shadow tree.
.Pp
Generally, you will need to look for the shared libraries that
.Fx
binaries depend on only the first few times that you install a
.Fx
program on your
.Nx
system.
After a while, you will have a sufficient set of
.Fx
shared libraries on your system to be able to run newly imported
.Fx
binaries without any extra work.
.Ss Setting up shared libraries
How to get to know which shared libraries
.Fx
binaries need, and where
to get them? Basically, there are 2 possibilities (when following
these instructions: you will need to be root on your
.Nx
system to do the necessary installation steps).
.Pp
.Bl -enum -compact
.It
You have access to a
.Fx
system.
In this case you can temporarily install the binary there, see what
shared libraries it needs, and copy them to your
.Nx
system.
Example: you have just ftp-ed the
.Fx
binary of SimCity.
Put it on the
.Fx
system you have access to, and check which shared libraries it
needs by running
.Sq ldd sim :
.Bd -literal -offset indent
me@freebsd% ldd /usr/local/lib/SimCity/res/sim
/usr/local/lib/SimCity/res/sim:
	-lXext.6 => /usr/X11R6/lib/libXext.so.6.0 (0x100c1000)
	-lX11.6 => /usr/X11R6/lib/libX11.so.6.0 (0x100c9000)
	-lc.2 => /usr/lib/libc.so.2.1 (0x10144000)
	-lm.2 => /usr/lib/libm.so.2.0 (0x101a7000)
	-lgcc.261 => /usr/lib/libgcc.so.261.0 (0x101bf000)
.Ed
.Pp
You would need go get all the files from the last column, and
put them under
.Pa /emul/freebsd .
This means you eventually have these files on your
.Nx
system:
.Bl -item -compact
.It
.Pa /emul/freebsd/usr/X11R6/lib/libXext.so.6.0
.It
.Pa /emul/freebsd/usr/X11R6/lib/libX11.so.6.0
.It
.Pa /emul/freebsd/usr/lib/libc.so.2.1
.It
.Pa /emul/freebsd/usr/lib/libm.so.2.0
.It
.Pa /emul/freebsd/usr/lib/libgcc.so.261.0
.El
.Pp
Note that if you already have a
.Fx
shared library with a matching major revision number to the first
column of the
.Ic ldd
output, you won't need to copy the file named
in the last column to your system, the one you already have should
work.
It is advisable to copy the shared library anyway if it is a newer version,
though.
You can remove the old one.
So, if you have these libraries on your system:
.Bl -item -compact
.It
.Pa /emul/freebsd/usr/lib/libc.so.2.0
.El
.Pp
and you find that the ldd output for a new binary you want to
install is:
.Bd -literal
\-lc.2 => /usr/lib/libc.so.2.1 (0x10144000)
.Ed
.Pp
You won't need to worry about copying
.Pa /usr/lib/libc.so.2.1
too, because the program should work fine with the slightly older version.
You can decide to replace the libc.so anyway, and that should leave
you with:
.Bl -item -compact
.It
.Pa /emul/freebsd/usr/lib/libc.so.2.1
.El
.Pp
Finally, you must make sure that you have the
.Fx
runtime linker and its config files on your system.
You should copy these files from the
.Fx
system to their appropriate place on your
.Nx
system (in the
.Pa /emul/freebsd
tree):
.Bl -item -compact
.It
.Pa usr/libexec/ld.so
.It
.Pa var/run/ld.so.hints
.El
.It
You don't have access to a
.Fx
system.
In that case, you should get the extra files you need from various ftp sites.
Information on where to look for the various files is appended
below.
For now, let's assume you know where to get the files.
.Pp
Retrieve the following files (from _one_ ftp site to avoid
any version mismatches), and install them under
.Pa /emul/freebsd
(i.e.
.Pa foo/bar
is installed as
.Pa /emul/freebsd/foo/bar ) :
.Bl -item -compact
.It
.Pa sbin/ldconfig
.It
.Pa usr/bin/ldd
.It
.Pa usr/lib/libc.so.x.y.z
.It
.Pa usr/libexec/ld.so
.El
.Pp
.Ic ldconfig
and
.Ic ldd
don't necessarily need to be under
.Pa /emul/freebsd ,
you can install them elsewhere in the system too.
Just make sure they don't conflict with their
.Nx
counterparts.
A good idea would be to install them in
.Pa /usr/local/bin
as
.Ic ldconfig-freebsd
and
.Ic ldd-freebsd .
.Pp
Run the
.Fx
ldconfig program with directory arguments in which the
.Fx
runtime linker should look for shared libs.
.Pa /usr/lib
are standard, you could run like the following:
.Bd -literal -offset indent
me@netbsd% mkdir -p /emul/freebsd/var/run
me@netbsd% touch /emul/freebsd/var/run/ld.so.hints
me@netbsd% ldconfig-freebsd /usr/X11R6/lib /usr/local/lib
.Ed
.Pp
Note that argument directories of ldconfig are
mapped to
.Pa /emul/freebsd/XXXX
by
.Nx Ns 's
compat code, and should exist as such on your system.
Make sure
.Pa /emul/freebsd/var/run/ld.so.hints
is existing when you run
.Fx Ns 's
ldconfig, if not, you may lose
.Nx Ns 's
.Pa /var/run/ld.so.hints .
.Fx
.Ic ldconfig
should be statically
linked, so it doesn't need any shared libraries by itself.
It will create the file
.Pa /emul/freebsd/var/run/ld.so.hints .
You should rerun the
.Fx
version of the ldconfig program each time you add a new shared library.
.Pp
You should now be set up for
.Fx
binaries which only need a shared libc.
You can test this by running the
.Fx
.Ic ldd
on itself.
Suppose that you have it installed as
.Ic ldd-freebsd ,
it should produce something like:
.Bd -literal -offset indent
me@netbsd% ldd-freebsd `which ldd-freebsd`
/usr/local/bin/ldd-freebsd:
	-lc.2 => /usr/lib/libc.so.2.1 (0x1001a000)
.Ed
.Pp
This being done, you are ready to install new
.Fx
binaries.
Whenever you install a new
.Fx
program, you should check if it needs shared libraries, and if so,
whether you have them installed in the
.Pa /emul/freebsd
tree.
To do this, you run the
.Fx
version
.Ic ldd
on the new program, and watch its output.
.Ic ldd
(see also the manual page for
.Xr ldd 1 )
will print a list
of shared libraries that the program depends on, in the
form -l<majorname> => <fullname>.
.Pp
If it prints
.Dq not found
instead of <fullname> it means that you need an extra library.
Which library this is, is shown
in <majorname>, which will be of the form XXXX.<N>
You will need to find a libXXXX.so.<N>.<mm> on a
.Fx
ftp site, and install it on your system.
The XXXX (name) and <N> (major
revision number) should match; the minor number(s) <mm> are
less important, though it is advised to take the most
recent version.
.Pp
.It
In some cases,
.Fx
binary needs access to certain device file.
For example,
.Fx
X server software needs
.Fx
.Pa /dev/ttyv0
for ioctls.
In this case, create a symbolic link from
.Pa /emul/freebsd/dev/ttyv0
to a
.Xr wscons 4
device file like
.Pa /dev/ttyE0 .
You will need to have at least
.Cd options WSDISPLAY_COMPAT_SYSCONS
and probably also
.Cd options WSDISPLAY_COMPAT_USL
in your kernel (see
.Xr options 4
and
.Xr wscons 4 ) .
.El
.Ss Finding the necessary files
.Em Note :
the information below is valid as of the time this
document was written (June, 1995), but certain details
such as names of ftp sites, directories and distribution names
may have changed by the time you read this.
.Pp
The
.Fx
distribution is available on a lot of ftp sites.
Sometimes the files are unpacked, and you can get the individual
files you need, but mostly they are stored in distribution sets,
usually consisting of subdirectories with gzipped tar files in them.
The ftp site for the distributions is:
.Lk ftp://ftp.FreeBSD.org/pub/FreeBSD
.Pp
This distribution consists of a number of tar-ed and gzipped files,
Normally, they're controlled by an install program, but you can
retrieve files
.Dq by hand
too.
The way to look something up is to retrieve all the files in the
distribution, and ``tar ztvf'' through them for the file you need.
Here is an example of a list of files that you might need.
.Bd -literal -offset indent
Needed                 Files

ld.so                  2.0-RELEASE/bindist/bindist.??
ldconfig               2.0-RELEASE/bindist/bindist.??
ldd                    2.0-RELEASE/bindist/bindist.??
libc.so.2              2.0-RELEASE/bindist/bindist.??
libX11.so.6.0          2.0-RELEASE/XFree86-3.1/XFree86-3.1-bin.tar.gz
libX11.so.6.0          XFree86-3.1.1/X311bin.tgz
libXt.so.6.0           2.0-RELEASE/XFree86-3.1/XFree86-3.1-bin.tar.gz
libXt.so.6.0           XFree86-3.1.1/X311bin.tgz
.\" libX11.so.3            oldlibs
.\" libXt.so.3             oldlibs
.Ed
.Pp
The files called
.Dq bindist.??
are tar-ed, gzipped and split, so you can extract contents by
.Dq cat bindist.?? | tar zpxf - .
.Pp
Extract the files from these gzipped tarfiles in your
.Pa /emul/freebsd
directory (possibly omitting or afterwards removing files you don't
need), and you are done.
.Sh BUGS
The information about
.Fx
distributions may become outdated.