4
4
#
5
5
# downloaded from https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh
6
6
7
- qemu_target_list=" i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \
8
- mips mipsel mipsn32 mipsn32el mips64 mips64el \
9
- sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb microblaze microblazeel"
7
+ # Enable automatic program execution by the kernel.
8
+
9
+ qemu_target_list=" i386 i486 alpha arm armeb sparc sparc32plus sparc64 \
10
+ ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \
11
+ sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \
12
+ microblaze microblazeel or1k x86_64"
10
13
11
14
i386_magic=' \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'
12
- i386_mask=' \xff\xff\xff\xff\xff\xfe\xfe\xff \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
15
+ i386_mask=' \xff\xff\xff\xff\xff\xfe\xfe\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
13
16
i386_family=i386
14
17
15
18
i486_magic=' \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00'
16
- i486_mask=' \xff\xff\xff\xff\xff\xfe\xfe\xff \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
19
+ i486_mask=' \xff\xff\xff\xff\xff\xfe\xfe\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
17
20
i486_family=i386
18
21
22
+ x86_64_magic=' \x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'
23
+ x86_64_mask=' \xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
24
+ x86_64_family=i386
25
+
19
26
alpha_magic=' \x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'
20
- alpha_mask=' \xff\xff\xff\xff\xff\xfe\xfe\xff \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
27
+ alpha_mask=' \xff\xff\xff\xff\xff\xfe\xfe\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
21
28
alpha_family=alpha
22
29
23
30
arm_magic=' \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
@@ -29,13 +36,17 @@ armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff
29
36
armeb_family=armeb
30
37
31
38
sparc_magic=' \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'
32
- sparc_mask=' \xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
39
+ sparc_mask=' \xff\xff\xff\xff\xff\xff\xff\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
33
40
sparc_family=sparc
34
41
35
42
sparc32plus_magic=' \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12'
36
- sparc32plus_mask=' \xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
43
+ sparc32plus_mask=' \xff\xff\xff\xff\xff\xff\xff\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
37
44
sparc32plus_family=sparc
38
45
46
+ sparc64_magic=' \x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b'
47
+ sparc64_mask=' \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
48
+ sparc64_family=sparc
49
+
39
50
ppc_magic=' \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'
40
51
ppc_mask=' \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
41
52
ppc_family=ppc
@@ -49,7 +60,7 @@ ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\x
49
60
ppc64le_family=ppcle
50
61
51
62
m68k_magic=' \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04'
52
- m68k_mask=' \xff\xff\xff\xff\xff\xff\xfe\xfe \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
63
+ m68k_mask=' \xff\xff\xff\xff\xff\xff\xfe\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
53
64
m68k_family=m68k
54
65
55
66
# FIXME: We could use the other endianness on a MIPS host.
@@ -79,11 +90,11 @@ mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\
79
90
mips64el_family=mips
80
91
81
92
sh4_magic=' \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00'
82
- sh4_mask=' \xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
93
+ sh4_mask=' \xff\xff\xff\xff\xff\xff\xff\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
83
94
sh4_family=sh4
84
95
85
96
sh4eb_magic=' \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a'
86
- sh4eb_mask=' \xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
97
+ sh4eb_mask=' \xff\xff\xff\xff\xff\xff\xff\x00 \xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
87
98
sh4eb_family=sh4
88
99
89
100
s390x_magic=' \x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'
@@ -126,6 +137,10 @@ microblazeel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\
126
137
microblazeel_mask=' \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
127
138
microblazeel_family=microblazeel
128
139
140
+ or1k_magic=' \x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c'
141
+ or1k_mask=' \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'
142
+ or1k_family=or1k
143
+
129
144
qemu_get_family () {
130
145
cpu=${HOST_ARCH:- $(uname -m)}
131
146
case " $cpu " in
@@ -163,21 +178,26 @@ usage() {
163
178
cat << EOF
164
179
Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]
165
180
[--help][--credential yes|no][--exportdir PATH]
181
+ [--persistent yes|no][--qemu-suffix SUFFIX]
166
182
167
183
Configure binfmt_misc to use qemu interpreter
168
184
169
- --help: display this usage
170
- --qemu-path: set path to qemu interpreter ($QEMU_PATH )
171
- --debian: don't write into /proc,
172
- instead generate update-binfmts templates
173
- --systemd: don't write into /proc,
174
- instead generate file for systemd-binfmt.service
175
- for the given CPU. If CPU is "ALL", generate a
176
- file for all known cpus
177
- --exportdir: define where to write configuration files
178
- (default: $SYSTEMDDIR or $DEBIANDIR )
179
- --credential: if yes, credential and security tokens are
180
- calculated according to the binary to interpret
185
+ --help: display this usage
186
+ --qemu-path: set path to qemu interpreter ($QEMU_PATH )
187
+ --qemu-suffix: add a suffix to the default interpreter name
188
+ --debian: don't write into /proc,
189
+ instead generate update-binfmts templates
190
+ --systemd: don't write into /proc,
191
+ instead generate file for systemd-binfmt.service
192
+ for the given CPU. If CPU is "ALL", generate a
193
+ file for all known cpus
194
+ --exportdir: define where to write configuration files
195
+ (default: $SYSTEMDDIR or $DEBIANDIR )
196
+ --credential: if yes, credential and security tokens are
197
+ calculated according to the binary to interpret
198
+ --persistent: if yes, the interpreter is loaded when binfmt is
199
+ configured and remains in memory. All future uses
200
+ are cloned from the open file.
181
201
182
202
To import templates with update-binfmts, use :
183
203
@@ -243,7 +263,15 @@ qemu_check_systemd() {
243
263
}
244
264
245
265
qemu_generate_register () {
246
- echo " :qemu-$cpu :M::$magic :$mask :$qemu :$FLAGS "
266
+ flags=" "
267
+ if [ " $CREDENTIAL " = " yes" ] ; then
268
+ flags=" OC"
269
+ fi
270
+ if [ " $PERSISTENT " = " yes" ] ; then
271
+ flags=" ${flags} F"
272
+ fi
273
+
274
+ echo " :qemu-$cpu :M::$magic :$mask :$qemu :$flags "
247
275
}
248
276
249
277
qemu_register_interpreter () {
@@ -262,10 +290,8 @@ package qemu-$cpu
262
290
interpreter $qemu
263
291
magic $magic
264
292
mask $mask
293
+ credential $CREDENTIAL
265
294
EOF
266
- if [ " $FLAGS " = " OC" ] ; then
267
- echo " credentials yes" >> " $EXPORTDIR /qemu-$cpu "
268
- fi
269
295
}
270
296
271
297
qemu_set_binfmts () {
@@ -284,11 +310,12 @@ qemu_set_binfmts() {
284
310
continue
285
311
fi
286
312
287
- qemu=" $QEMU_PATH /qemu-$cpu -static "
313
+ qemu=" $QEMU_PATH /qemu-$cpu "
288
314
if [ " $cpu " = " i486" ] ; then
289
- qemu=" $QEMU_PATH /qemu-i386-static "
315
+ qemu=" $QEMU_PATH /qemu-i386"
290
316
fi
291
317
318
+ qemu=" $qemu$QEMU_SUFFIX "
292
319
if [ " $host_family " != " $family " ] ; then
293
320
$BINFMT_SET
294
321
fi
@@ -302,9 +329,11 @@ SYSTEMDDIR="/etc/binfmt.d"
302
329
DEBIANDIR=" /usr/share/binfmts"
303
330
304
331
QEMU_PATH=/usr/local/bin
305
- FLAGS=" "
332
+ CREDENTIAL=no
333
+ PERSISTENT=no
334
+ QEMU_SUFFIX=" "
306
335
307
- options=$( getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- " $@ " )
336
+ options=$( getopt -o ds:Q:S: e:hc:p: -l debian,systemd:,qemu-path:,qemu-suffix:, exportdir:,help,credential:,persistent : -- " $@ " )
308
337
eval set -- " $options "
309
338
310
339
while true ; do
@@ -340,6 +369,10 @@ while true ; do
340
369
shift
341
370
QEMU_PATH=" $1 "
342
371
;;
372
+ -F|--qemu-suffix)
373
+ shift
374
+ QEMU_SUFFIX=" $1 "
375
+ ;;
343
376
-e|--exportdir)
344
377
shift
345
378
EXPORTDIR=" $1 "
@@ -350,11 +383,11 @@ while true ; do
350
383
;;
351
384
-c|--credential)
352
385
shift
353
- if [ " $1 " = " yes " ] ; then
354
- FLAGS= " OC "
355
- else
356
- FLAGS= " "
357
- fi
386
+ CREDENTIAL= " $1 "
387
+ ;;
388
+ -p|--persistent)
389
+ shift
390
+ PERSISTENT= " $1 "
358
391
;;
359
392
* )
360
393
break
0 commit comments