bellard | 08785f4 | 2004-01-04 18:12:46 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Laurent Vivier | 947aeab | 2018-04-09 13:52:12 +0200 | [diff] [blame] | 2 | # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390/HPPA/Xtensa/microblaze |
Laurent Vivier | e4d966c | 2017-01-26 09:04:47 +0100 | [diff] [blame] | 3 | # program execution by the kernel |
bellard | 08785f4 | 2004-01-04 18:12:46 +0000 | [diff] [blame] | 4 | |
Michael Weiser | bfe69cc | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 5 | qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \ |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 6 | mips mipsel mipsn32 mipsn32el mips64 mips64el \ |
Laurent Vivier | 947aeab | 2018-04-09 13:52:12 +0200 | [diff] [blame] | 7 | sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb microblaze microblazeel" |
bellard | 08785f4 | 2004-01-04 18:12:46 +0000 | [diff] [blame] | 8 | |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 9 | i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 10 | i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 11 | i386_family=i386 |
bellard | 08785f4 | 2004-01-04 18:12:46 +0000 | [diff] [blame] | 12 | |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 13 | i486_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 14 | i486_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 15 | i486_family=i386 |
| 16 | |
| 17 | alpha_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 18 | alpha_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 19 | alpha_family=alpha |
| 20 | |
| 21 | arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00' |
| 22 | arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 23 | arm_family=arm |
| 24 | |
| 25 | armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28' |
| 26 | armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Michael Weiser | 2ced93e | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 27 | armeb_family=armeb |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 28 | |
| 29 | sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 30 | sparc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 31 | sparc_family=sparc |
| 32 | |
| 33 | sparc32plus_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 34 | sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 35 | sparc32plus_family=sparc |
| 36 | |
| 37 | ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14' |
| 38 | ppc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 39 | ppc_family=ppc |
| 40 | |
| 41 | ppc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15' |
| 42 | ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 43 | ppc64_family=ppc |
| 44 | |
| 45 | ppc64le_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00' |
| 46 | ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00' |
| 47 | ppc64le_family=ppcle |
| 48 | |
| 49 | m68k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 50 | m68k_mask='\xff\xff\xff\xff\xff\xff\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 51 | m68k_family=m68k |
| 52 | |
| 53 | # FIXME: We could use the other endianness on a MIPS host. |
| 54 | |
| 55 | mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' |
| 56 | mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 57 | mips_family=mips |
| 58 | |
| 59 | mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' |
| 60 | mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 61 | mipsel_family=mips |
| 62 | |
| 63 | mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' |
| 64 | mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 65 | mipsn32_family=mips |
| 66 | |
| 67 | mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' |
| 68 | mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 69 | mipsn32el_family=mips |
| 70 | |
| 71 | mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' |
| 72 | mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 73 | mips64_family=mips |
| 74 | |
| 75 | mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' |
| 76 | mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 77 | mips64el_family=mips |
| 78 | |
| 79 | sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 80 | sh4_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 81 | sh4_family=sh4 |
| 82 | |
| 83 | sh4eb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 84 | sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 85 | sh4eb_family=sh4 |
| 86 | |
| 87 | s390x_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16' |
Laurent Vivier | daf238d | 2018-06-05 21:47:25 +0200 | [diff] [blame] | 88 | s390x_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 89 | s390x_family=s390x |
| 90 | |
| 91 | aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' |
| 92 | aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 93 | aarch64_family=arm |
| 94 | |
Michael Weiser | f772f21 | 2018-01-11 13:25:32 +0000 | [diff] [blame] | 95 | aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7' |
| 96 | aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Michael Weiser | 2ced93e | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 97 | aarch64_be_family=armeb |
Michael Weiser | f772f21 | 2018-01-11 13:25:32 +0000 | [diff] [blame] | 98 | |
Laurent Vivier | e4d966c | 2017-01-26 09:04:47 +0100 | [diff] [blame] | 99 | hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f' |
| 100 | hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 101 | hppa_family=hppa |
| 102 | |
Michael Clark | 25fa194 | 2018-03-03 01:32:59 +1300 | [diff] [blame] | 103 | riscv32_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' |
| 104 | riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 105 | riscv32_family=riscv |
| 106 | |
| 107 | riscv64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' |
| 108 | riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 109 | riscv64_family=riscv |
| 110 | |
Max Filippov | d409030 | 2018-02-28 14:16:08 -0800 | [diff] [blame] | 111 | xtensa_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00' |
| 112 | xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 113 | xtensa_family=xtensa |
| 114 | |
| 115 | xtensaeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e' |
| 116 | xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 117 | xtensaeb_family=xtensaeb |
| 118 | |
Laurent Vivier | 947aeab | 2018-04-09 13:52:12 +0200 | [diff] [blame] | 119 | microblaze_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xba\xab' |
| 120 | microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 121 | microblaze_family=microblaze |
| 122 | |
| 123 | microblazeel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba' |
| 124 | microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 125 | microblazeel_family=microblazeel |
| 126 | |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 127 | qemu_get_family() { |
| 128 | cpu=${HOST_ARCH:-$(uname -m)} |
| 129 | case "$cpu" in |
| 130 | amd64|i386|i486|i586|i686|i86pc|BePC|x86_64) |
| 131 | echo "i386" |
| 132 | ;; |
| 133 | mips*) |
| 134 | echo "mips" |
| 135 | ;; |
| 136 | "Power Macintosh"|ppc64|powerpc|ppc) |
| 137 | echo "ppc" |
| 138 | ;; |
| 139 | ppc64el|ppc64le) |
| 140 | echo "ppcle" |
| 141 | ;; |
Michael Weiser | 2ced93e | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 142 | arm|armel|armhf|arm64|armv[4-9]*l|aarch64) |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 143 | echo "arm" |
| 144 | ;; |
Michael Weiser | 2ced93e | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 145 | armeb|armv[4-9]*b|aarch64_be) |
| 146 | echo "armeb" |
| 147 | ;; |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 148 | sparc*) |
| 149 | echo "sparc" |
| 150 | ;; |
Michael Clark | 25fa194 | 2018-03-03 01:32:59 +1300 | [diff] [blame] | 151 | riscv*) |
| 152 | echo "riscv" |
| 153 | ;; |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 154 | *) |
| 155 | echo "$cpu" |
| 156 | ;; |
| 157 | esac |
| 158 | } |
| 159 | |
| 160 | usage() { |
| 161 | cat <<EOF |
| 162 | Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] |
| 163 | [--help][--credential yes|no][--exportdir PATH] |
| 164 | |
| 165 | Configure binfmt_misc to use qemu interpreter |
| 166 | |
| 167 | --help: display this usage |
| 168 | --qemu-path: set path to qemu interpreter ($QEMU_PATH) |
| 169 | --debian: don't write into /proc, |
| 170 | instead generate update-binfmts templates |
| 171 | --systemd: don't write into /proc, |
| 172 | instead generate file for systemd-binfmt.service |
Laurent Vivier | 3ff4845 | 2018-03-08 11:48:59 +0100 | [diff] [blame] | 173 | for the given CPU. If CPU is "ALL", generate a |
| 174 | file for all known cpus |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 175 | --exportdir: define where to write configuration files |
| 176 | (default: $SYSTEMDDIR or $DEBIANDIR) |
| 177 | --credential: if yes, credential and security tokens are |
| 178 | calculated according to the binary to interpret |
| 179 | |
| 180 | To import templates with update-binfmts, use : |
| 181 | |
| 182 | sudo update-binfmts --importdir ${EXPORTDIR:-$DEBIANDIR} --import qemu-CPU |
| 183 | |
| 184 | To remove interpreter, use : |
| 185 | |
| 186 | sudo update-binfmts --package qemu-CPU --remove qemu-CPU $QEMU_PATH |
| 187 | |
| 188 | With systemd, binfmt files are loaded by systemd-binfmt.service |
| 189 | |
| 190 | The environment variable HOST_ARCH allows to override 'uname' to generate |
| 191 | configuration files for a different architecture than the current one. |
| 192 | |
| 193 | where CPU is one of: |
| 194 | |
| 195 | $qemu_target_list |
| 196 | |
| 197 | EOF |
| 198 | } |
| 199 | |
| 200 | qemu_check_access() { |
| 201 | if [ ! -w "$1" ] ; then |
| 202 | echo "ERROR: cannot write to $1" 1>&2 |
| 203 | exit 1 |
| 204 | fi |
| 205 | } |
| 206 | |
| 207 | qemu_check_bintfmt_misc() { |
| 208 | # load the binfmt_misc module |
| 209 | if [ ! -d /proc/sys/fs/binfmt_misc ]; then |
| 210 | if ! /sbin/modprobe binfmt_misc ; then |
| 211 | exit 1 |
| 212 | fi |
| 213 | fi |
| 214 | if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then |
| 215 | if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then |
| 216 | exit 1 |
| 217 | fi |
| 218 | fi |
| 219 | |
| 220 | qemu_check_access /proc/sys/fs/binfmt_misc/register |
| 221 | } |
| 222 | |
| 223 | installed_dpkg() { |
| 224 | dpkg --status "$1" > /dev/null 2>&1 |
| 225 | } |
| 226 | |
| 227 | qemu_check_debian() { |
| 228 | if [ ! -e /etc/debian_version ] ; then |
| 229 | echo "WARNING: your system is not a Debian based distro" 1>&2 |
| 230 | elif ! installed_dpkg binfmt-support ; then |
| 231 | echo "WARNING: package binfmt-support is needed" 1>&2 |
| 232 | fi |
| 233 | qemu_check_access "$EXPORTDIR" |
| 234 | } |
| 235 | |
| 236 | qemu_check_systemd() { |
| 237 | if ! systemctl -q is-enabled systemd-binfmt.service ; then |
| 238 | echo "WARNING: systemd-binfmt.service is missing or disabled" 1>&2 |
| 239 | fi |
| 240 | qemu_check_access "$EXPORTDIR" |
| 241 | } |
| 242 | |
| 243 | qemu_generate_register() { |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame^] | 244 | flags="" |
| 245 | if [ "$CREDENTIAL" = "yes" ] ; then |
| 246 | flags="OC" |
| 247 | fi |
| 248 | |
| 249 | echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | qemu_register_interpreter() { |
| 253 | echo "Setting $qemu as binfmt interpreter for $cpu" |
| 254 | qemu_generate_register > /proc/sys/fs/binfmt_misc/register |
| 255 | } |
| 256 | |
| 257 | qemu_generate_systemd() { |
| 258 | echo "Setting $qemu as binfmt interpreter for $cpu for systemd-binfmt.service" |
| 259 | qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" |
| 260 | } |
| 261 | |
| 262 | qemu_generate_debian() { |
| 263 | cat > "$EXPORTDIR/qemu-$cpu" <<EOF |
| 264 | package qemu-$cpu |
| 265 | interpreter $qemu |
| 266 | magic $magic |
| 267 | mask $mask |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame^] | 268 | credential $CREDENTIAL |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 269 | EOF |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | qemu_set_binfmts() { |
| 273 | # probe cpu type |
| 274 | host_family=$(qemu_get_family) |
| 275 | |
| 276 | # register the interpreter for each cpu except for the native one |
| 277 | |
| 278 | for cpu in ${qemu_target_list} ; do |
| 279 | magic=$(eval echo \$${cpu}_magic) |
| 280 | mask=$(eval echo \$${cpu}_mask) |
| 281 | family=$(eval echo \$${cpu}_family) |
| 282 | |
| 283 | if [ "$magic" = "" ] || [ "$mask" = "" ] || [ "$family" = "" ] ; then |
| 284 | echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2 |
| 285 | continue |
| 286 | fi |
| 287 | |
| 288 | qemu="$QEMU_PATH/qemu-$cpu" |
| 289 | if [ "$cpu" = "i486" ] ; then |
| 290 | qemu="$QEMU_PATH/qemu-i386" |
| 291 | fi |
| 292 | |
| 293 | if [ "$host_family" != "$family" ] ; then |
| 294 | $BINFMT_SET |
| 295 | fi |
| 296 | done |
| 297 | } |
| 298 | |
| 299 | CHECK=qemu_check_bintfmt_misc |
| 300 | BINFMT_SET=qemu_register_interpreter |
| 301 | |
| 302 | SYSTEMDDIR="/etc/binfmt.d" |
| 303 | DEBIANDIR="/usr/share/binfmts" |
| 304 | |
| 305 | QEMU_PATH=/usr/local/bin |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame^] | 306 | CREDENTIAL=no |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 307 | |
| 308 | options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@") |
| 309 | eval set -- "$options" |
| 310 | |
| 311 | while true ; do |
| 312 | case "$1" in |
| 313 | -d|--debian) |
| 314 | CHECK=qemu_check_debian |
| 315 | BINFMT_SET=qemu_generate_debian |
| 316 | EXPORTDIR=${EXPORTDIR:-$DEBIANDIR} |
| 317 | ;; |
| 318 | -s|--systemd) |
| 319 | CHECK=qemu_check_systemd |
| 320 | BINFMT_SET=qemu_generate_systemd |
| 321 | EXPORTDIR=${EXPORTDIR:-$SYSTEMDDIR} |
| 322 | shift |
| 323 | # check given cpu is in the supported CPU list |
Laurent Vivier | 3ff4845 | 2018-03-08 11:48:59 +0100 | [diff] [blame] | 324 | if [ "$1" != "ALL" ] ; then |
| 325 | for cpu in ${qemu_target_list} ; do |
| 326 | if [ "$cpu" = "$1" ] ; then |
| 327 | break |
| 328 | fi |
| 329 | done |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 330 | |
Laurent Vivier | 3ff4845 | 2018-03-08 11:48:59 +0100 | [diff] [blame] | 331 | if [ "$cpu" = "$1" ] ; then |
| 332 | qemu_target_list="$1" |
| 333 | else |
| 334 | echo "ERROR: unknown CPU \"$1\"" 1>&2 |
| 335 | usage |
| 336 | exit 1 |
| 337 | fi |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 338 | fi |
| 339 | ;; |
| 340 | -Q|--qemu-path) |
| 341 | shift |
| 342 | QEMU_PATH="$1" |
| 343 | ;; |
| 344 | -e|--exportdir) |
| 345 | shift |
| 346 | EXPORTDIR="$1" |
| 347 | ;; |
| 348 | -h|--help) |
| 349 | usage |
| 350 | exit 1 |
| 351 | ;; |
| 352 | -c|--credential) |
| 353 | shift |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame^] | 354 | CREDENTIAL="$1" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 355 | ;; |
| 356 | *) |
| 357 | break |
| 358 | ;; |
| 359 | esac |
| 360 | shift |
| 361 | done |
| 362 | |
| 363 | $CHECK |
| 364 | qemu_set_binfmts |