bellard | 08785f4 | 2004-01-04 18:12:46 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Richard Henderson | ecbed72 | 2018-05-27 08:41:53 -0500 | [diff] [blame] | 2 | # Enable automatic program execution by the kernel. |
bellard | 08785f4 | 2004-01-04 18:12:46 +0000 | [diff] [blame] | 3 | |
Richard Henderson | 7c81570 | 2019-11-06 12:33:07 +0100 | [diff] [blame] | 4 | qemu_target_list="i386 i486 alpha arm armeb sparc sparc32plus sparc64 \ |
| 5 | ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \ |
Richard Henderson | ecbed72 | 2018-05-27 08:41:53 -0500 | [diff] [blame] | 6 | sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \ |
Song Gao | 0caebb9 | 2022-06-24 11:10:42 +0800 | [diff] [blame] | 7 | microblaze microblazeel or1k x86_64 hexagon loongarch64" |
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 | |
Laurent Vivier | b8dbfc9 | 2018-08-01 12:29:44 +0200 | [diff] [blame] | 17 | x86_64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00' |
| 18 | x86_64_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 19 | x86_64_family=i386 |
| 20 | |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 21 | 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] | 22 | 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] | 23 | alpha_family=alpha |
| 24 | |
| 25 | arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00' |
| 26 | arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 27 | arm_family=arm |
| 28 | |
| 29 | armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28' |
| 30 | 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] | 31 | armeb_family=armeb |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 32 | |
| 33 | 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] | 34 | 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] | 35 | sparc_family=sparc |
| 36 | |
| 37 | 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] | 38 | 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] | 39 | sparc32plus_family=sparc |
| 40 | |
Richard Henderson | 7c81570 | 2019-11-06 12:33:07 +0100 | [diff] [blame] | 41 | sparc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b' |
| 42 | sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 43 | sparc64_family=sparc |
| 44 | |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 45 | ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14' |
| 46 | ppc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 47 | ppc_family=ppc |
| 48 | |
| 49 | ppc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15' |
| 50 | ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 51 | ppc64_family=ppc |
| 52 | |
| 53 | ppc64le_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00' |
| 54 | ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00' |
| 55 | ppc64le_family=ppcle |
| 56 | |
| 57 | 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] | 58 | 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] | 59 | m68k_family=m68k |
| 60 | |
| 61 | # FIXME: We could use the other endianness on a MIPS host. |
| 62 | |
Andreas K. Hüttel | 77d119d | 2022-03-28 22:49:01 +0200 | [diff] [blame] | 63 | mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 64 | mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 65 | mips_family=mips |
| 66 | |
Andreas K. Hüttel | 77d119d | 2022-03-28 22:49:01 +0200 | [diff] [blame] | 67 | mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 68 | mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 69 | mipsel_family=mips |
| 70 | |
Andreas K. Hüttel | 77d119d | 2022-03-28 22:49:01 +0200 | [diff] [blame] | 71 | mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' |
| 72 | mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 73 | mipsn32_family=mips |
| 74 | |
Andreas K. Hüttel | 77d119d | 2022-03-28 22:49:01 +0200 | [diff] [blame] | 75 | mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' |
| 76 | mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 77 | mipsn32el_family=mips |
| 78 | |
| 79 | mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' |
Andreas K. Hüttel | 77d119d | 2022-03-28 22:49:01 +0200 | [diff] [blame] | 80 | mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 81 | mips64_family=mips |
| 82 | |
| 83 | mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' |
Andreas K. Hüttel | 77d119d | 2022-03-28 22:49:01 +0200 | [diff] [blame] | 84 | mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 85 | mips64el_family=mips |
| 86 | |
| 87 | 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] | 88 | 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] | 89 | sh4_family=sh4 |
| 90 | |
| 91 | 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] | 92 | 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] | 93 | sh4eb_family=sh4 |
| 94 | |
| 95 | 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] | 96 | 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] | 97 | s390x_family=s390x |
| 98 | |
| 99 | aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' |
| 100 | aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 101 | aarch64_family=arm |
| 102 | |
Michael Weiser | f772f21 | 2018-01-11 13:25:32 +0000 | [diff] [blame] | 103 | aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7' |
| 104 | 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] | 105 | aarch64_be_family=armeb |
Michael Weiser | f772f21 | 2018-01-11 13:25:32 +0000 | [diff] [blame] | 106 | |
Laurent Vivier | e4d966c | 2017-01-26 09:04:47 +0100 | [diff] [blame] | 107 | hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f' |
| 108 | hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 109 | hppa_family=hppa |
| 110 | |
Michael Clark | 25fa194 | 2018-03-03 01:32:59 +1300 | [diff] [blame] | 111 | riscv32_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' |
| 112 | riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 113 | riscv32_family=riscv |
| 114 | |
| 115 | riscv64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' |
| 116 | riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 117 | riscv64_family=riscv |
| 118 | |
Max Filippov | d409030 | 2018-02-28 14:16:08 -0800 | [diff] [blame] | 119 | xtensa_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00' |
| 120 | xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 121 | xtensa_family=xtensa |
| 122 | |
| 123 | xtensaeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e' |
| 124 | xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 125 | xtensaeb_family=xtensaeb |
| 126 | |
Laurent Vivier | 947aeab | 2018-04-09 13:52:12 +0200 | [diff] [blame] | 127 | microblaze_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xba\xab' |
| 128 | microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 129 | microblaze_family=microblaze |
| 130 | |
| 131 | microblazeel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba' |
| 132 | microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 133 | microblazeel_family=microblazeel |
| 134 | |
Richard Henderson | ecbed72 | 2018-05-27 08:41:53 -0500 | [diff] [blame] | 135 | or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c' |
| 136 | or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' |
| 137 | or1k_family=or1k |
| 138 | |
Taylor Simpson | 3e7a84e | 2021-02-07 23:46:24 -0600 | [diff] [blame] | 139 | hexagon_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xa4\x00' |
| 140 | hexagon_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 141 | hexagon_family=hexagon |
| 142 | |
Song Gao | 0caebb9 | 2022-06-24 11:10:42 +0800 | [diff] [blame] | 143 | loongarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x01' |
| 144 | loongarch64_mask='\xff\xff\xff\xff\xff\xff\xff\xfc\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
| 145 | loongarch64_family=loongarch |
| 146 | |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 147 | qemu_get_family() { |
| 148 | cpu=${HOST_ARCH:-$(uname -m)} |
| 149 | case "$cpu" in |
| 150 | amd64|i386|i486|i586|i686|i86pc|BePC|x86_64) |
| 151 | echo "i386" |
| 152 | ;; |
| 153 | mips*) |
| 154 | echo "mips" |
| 155 | ;; |
| 156 | "Power Macintosh"|ppc64|powerpc|ppc) |
| 157 | echo "ppc" |
| 158 | ;; |
| 159 | ppc64el|ppc64le) |
| 160 | echo "ppcle" |
| 161 | ;; |
Michael Weiser | 2ced93e | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 162 | arm|armel|armhf|arm64|armv[4-9]*l|aarch64) |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 163 | echo "arm" |
| 164 | ;; |
Michael Weiser | 2ced93e | 2018-01-11 13:25:33 +0000 | [diff] [blame] | 165 | armeb|armv[4-9]*b|aarch64_be) |
| 166 | echo "armeb" |
| 167 | ;; |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 168 | sparc*) |
| 169 | echo "sparc" |
| 170 | ;; |
Michael Clark | 25fa194 | 2018-03-03 01:32:59 +1300 | [diff] [blame] | 171 | riscv*) |
| 172 | echo "riscv" |
| 173 | ;; |
Song Gao | f8d1ae8 | 2022-07-05 14:59:42 +0800 | [diff] [blame] | 174 | loongarch*) |
| 175 | echo "loongarch" |
| 176 | ;; |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 177 | *) |
| 178 | echo "$cpu" |
| 179 | ;; |
| 180 | esac |
| 181 | } |
| 182 | |
| 183 | usage() { |
| 184 | cat <<EOF |
| 185 | Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] |
| 186 | [--help][--credential yes|no][--exportdir PATH] |
Laurent Vivier | 7155be7 | 2018-06-27 22:53:17 +0200 | [diff] [blame] | 187 | [--persistent yes|no][--qemu-suffix SUFFIX] |
Laurent Vivier | 6e1c0d7 | 2021-02-22 11:50:04 +0100 | [diff] [blame] | 188 | [--preserve-argv0 yes|no] |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 189 | |
| 190 | Configure binfmt_misc to use qemu interpreter |
| 191 | |
Laurent Vivier | 6e1c0d7 | 2021-02-22 11:50:04 +0100 | [diff] [blame] | 192 | --help: display this usage |
| 193 | --qemu-path: set path to qemu interpreter ($QEMU_PATH) |
| 194 | --qemu-suffix: add a suffix to the default interpreter name |
| 195 | --debian: don't write into /proc, |
| 196 | instead generate update-binfmts templates |
| 197 | --systemd: don't write into /proc, |
| 198 | instead generate file for systemd-binfmt.service |
| 199 | for the given CPU. If CPU is "ALL", generate a |
| 200 | file for all known cpus |
| 201 | --exportdir: define where to write configuration files |
| 202 | (default: $SYSTEMDDIR or $DEBIANDIR) |
| 203 | --credential: if yes, credential and security tokens are |
| 204 | calculated according to the binary to interpret |
| 205 | --persistent: if yes, the interpreter is loaded when binfmt is |
| 206 | configured and remains in memory. All future uses |
| 207 | are cloned from the open file. |
| 208 | --preserve-argv0 preserve argv[0] |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 209 | |
| 210 | To import templates with update-binfmts, use : |
| 211 | |
| 212 | sudo update-binfmts --importdir ${EXPORTDIR:-$DEBIANDIR} --import qemu-CPU |
| 213 | |
| 214 | To remove interpreter, use : |
| 215 | |
| 216 | sudo update-binfmts --package qemu-CPU --remove qemu-CPU $QEMU_PATH |
| 217 | |
| 218 | With systemd, binfmt files are loaded by systemd-binfmt.service |
| 219 | |
| 220 | The environment variable HOST_ARCH allows to override 'uname' to generate |
| 221 | configuration files for a different architecture than the current one. |
| 222 | |
| 223 | where CPU is one of: |
| 224 | |
| 225 | $qemu_target_list |
| 226 | |
| 227 | EOF |
| 228 | } |
| 229 | |
| 230 | qemu_check_access() { |
| 231 | if [ ! -w "$1" ] ; then |
| 232 | echo "ERROR: cannot write to $1" 1>&2 |
| 233 | exit 1 |
| 234 | fi |
| 235 | } |
| 236 | |
| 237 | qemu_check_bintfmt_misc() { |
| 238 | # load the binfmt_misc module |
| 239 | if [ ! -d /proc/sys/fs/binfmt_misc ]; then |
| 240 | if ! /sbin/modprobe binfmt_misc ; then |
| 241 | exit 1 |
| 242 | fi |
| 243 | fi |
| 244 | if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then |
| 245 | if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then |
| 246 | exit 1 |
| 247 | fi |
| 248 | fi |
| 249 | |
| 250 | qemu_check_access /proc/sys/fs/binfmt_misc/register |
| 251 | } |
| 252 | |
| 253 | installed_dpkg() { |
| 254 | dpkg --status "$1" > /dev/null 2>&1 |
| 255 | } |
| 256 | |
| 257 | qemu_check_debian() { |
| 258 | if [ ! -e /etc/debian_version ] ; then |
| 259 | echo "WARNING: your system is not a Debian based distro" 1>&2 |
| 260 | elif ! installed_dpkg binfmt-support ; then |
| 261 | echo "WARNING: package binfmt-support is needed" 1>&2 |
| 262 | fi |
| 263 | qemu_check_access "$EXPORTDIR" |
| 264 | } |
| 265 | |
| 266 | qemu_check_systemd() { |
| 267 | if ! systemctl -q is-enabled systemd-binfmt.service ; then |
| 268 | echo "WARNING: systemd-binfmt.service is missing or disabled" 1>&2 |
| 269 | fi |
| 270 | qemu_check_access "$EXPORTDIR" |
| 271 | } |
| 272 | |
| 273 | qemu_generate_register() { |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame] | 274 | flags="" |
| 275 | if [ "$CREDENTIAL" = "yes" ] ; then |
| 276 | flags="OC" |
| 277 | fi |
Laurent Vivier | 01ecd22 | 2018-06-27 22:53:16 +0200 | [diff] [blame] | 278 | if [ "$PERSISTENT" = "yes" ] ; then |
| 279 | flags="${flags}F" |
| 280 | fi |
Laurent Vivier | 6e1c0d7 | 2021-02-22 11:50:04 +0100 | [diff] [blame] | 281 | if [ "$PRESERVE_ARG0" = "yes" ] ; then |
| 282 | flags="${flags}P" |
| 283 | fi |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame] | 284 | |
| 285 | echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | qemu_register_interpreter() { |
| 289 | echo "Setting $qemu as binfmt interpreter for $cpu" |
| 290 | qemu_generate_register > /proc/sys/fs/binfmt_misc/register |
| 291 | } |
| 292 | |
| 293 | qemu_generate_systemd() { |
| 294 | echo "Setting $qemu as binfmt interpreter for $cpu for systemd-binfmt.service" |
| 295 | qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" |
| 296 | } |
| 297 | |
| 298 | qemu_generate_debian() { |
| 299 | cat > "$EXPORTDIR/qemu-$cpu" <<EOF |
| 300 | package qemu-$cpu |
| 301 | interpreter $qemu |
| 302 | magic $magic |
| 303 | mask $mask |
Silvano Cirujano Cuesta | e759413 | 2021-03-23 13:34:57 +0100 | [diff] [blame] | 304 | credentials $CREDENTIAL |
| 305 | preserve $PRESERVE_ARG0 |
| 306 | fix_binary $PERSISTENT |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 307 | EOF |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | qemu_set_binfmts() { |
| 311 | # probe cpu type |
| 312 | host_family=$(qemu_get_family) |
| 313 | |
| 314 | # register the interpreter for each cpu except for the native one |
| 315 | |
| 316 | for cpu in ${qemu_target_list} ; do |
| 317 | magic=$(eval echo \$${cpu}_magic) |
| 318 | mask=$(eval echo \$${cpu}_mask) |
| 319 | family=$(eval echo \$${cpu}_family) |
| 320 | |
| 321 | if [ "$magic" = "" ] || [ "$mask" = "" ] || [ "$family" = "" ] ; then |
| 322 | echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2 |
| 323 | continue |
| 324 | fi |
| 325 | |
| 326 | qemu="$QEMU_PATH/qemu-$cpu" |
| 327 | if [ "$cpu" = "i486" ] ; then |
| 328 | qemu="$QEMU_PATH/qemu-i386" |
| 329 | fi |
| 330 | |
Laurent Vivier | 7155be7 | 2018-06-27 22:53:17 +0200 | [diff] [blame] | 331 | qemu="$qemu$QEMU_SUFFIX" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 332 | if [ "$host_family" != "$family" ] ; then |
| 333 | $BINFMT_SET |
| 334 | fi |
| 335 | done |
| 336 | } |
| 337 | |
| 338 | CHECK=qemu_check_bintfmt_misc |
| 339 | BINFMT_SET=qemu_register_interpreter |
| 340 | |
| 341 | SYSTEMDDIR="/etc/binfmt.d" |
| 342 | DEBIANDIR="/usr/share/binfmts" |
| 343 | |
| 344 | QEMU_PATH=/usr/local/bin |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame] | 345 | CREDENTIAL=no |
Laurent Vivier | 01ecd22 | 2018-06-27 22:53:16 +0200 | [diff] [blame] | 346 | PERSISTENT=no |
Laurent Vivier | 6e1c0d7 | 2021-02-22 11:50:04 +0100 | [diff] [blame] | 347 | PRESERVE_ARG0=no |
Laurent Vivier | 7155be7 | 2018-06-27 22:53:17 +0200 | [diff] [blame] | 348 | QEMU_SUFFIX="" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 349 | |
Martin Wilck | 719fab3 | 2021-11-29 14:51:00 +0100 | [diff] [blame] | 350 | _longopts="debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,\ |
| 351 | persistent:,preserve-argv0:" |
| 352 | options=$(getopt -o ds:Q:S:e:hc:p:g:F: -l ${_longopts} -- "$@") |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 353 | eval set -- "$options" |
| 354 | |
| 355 | while true ; do |
| 356 | case "$1" in |
| 357 | -d|--debian) |
| 358 | CHECK=qemu_check_debian |
| 359 | BINFMT_SET=qemu_generate_debian |
| 360 | EXPORTDIR=${EXPORTDIR:-$DEBIANDIR} |
| 361 | ;; |
| 362 | -s|--systemd) |
| 363 | CHECK=qemu_check_systemd |
| 364 | BINFMT_SET=qemu_generate_systemd |
| 365 | EXPORTDIR=${EXPORTDIR:-$SYSTEMDDIR} |
| 366 | shift |
| 367 | # check given cpu is in the supported CPU list |
Laurent Vivier | 3ff4845 | 2018-03-08 11:48:59 +0100 | [diff] [blame] | 368 | if [ "$1" != "ALL" ] ; then |
| 369 | for cpu in ${qemu_target_list} ; do |
| 370 | if [ "$cpu" = "$1" ] ; then |
| 371 | break |
| 372 | fi |
| 373 | done |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 374 | |
Laurent Vivier | 3ff4845 | 2018-03-08 11:48:59 +0100 | [diff] [blame] | 375 | if [ "$cpu" = "$1" ] ; then |
| 376 | qemu_target_list="$1" |
| 377 | else |
| 378 | echo "ERROR: unknown CPU \"$1\"" 1>&2 |
| 379 | usage |
| 380 | exit 1 |
| 381 | fi |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 382 | fi |
| 383 | ;; |
| 384 | -Q|--qemu-path) |
| 385 | shift |
| 386 | QEMU_PATH="$1" |
| 387 | ;; |
Laurent Vivier | 7155be7 | 2018-06-27 22:53:17 +0200 | [diff] [blame] | 388 | -F|--qemu-suffix) |
| 389 | shift |
| 390 | QEMU_SUFFIX="$1" |
| 391 | ;; |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 392 | -e|--exportdir) |
| 393 | shift |
| 394 | EXPORTDIR="$1" |
| 395 | ;; |
| 396 | -h|--help) |
| 397 | usage |
| 398 | exit 1 |
| 399 | ;; |
| 400 | -c|--credential) |
| 401 | shift |
Laurent Vivier | 70a7798 | 2018-06-27 22:53:15 +0200 | [diff] [blame] | 402 | CREDENTIAL="$1" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 403 | ;; |
Laurent Vivier | 01ecd22 | 2018-06-27 22:53:16 +0200 | [diff] [blame] | 404 | -p|--persistent) |
| 405 | shift |
| 406 | PERSISTENT="$1" |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 407 | ;; |
Laurent Vivier | 6e1c0d7 | 2021-02-22 11:50:04 +0100 | [diff] [blame] | 408 | -g|--preserve-argv0) |
| 409 | shift |
| 410 | PRESERVE_ARG0="$1" |
| 411 | ;; |
Laurent Vivier | 3bef045 | 2016-01-29 17:07:31 +0100 | [diff] [blame] | 412 | *) |
| 413 | break |
| 414 | ;; |
| 415 | esac |
| 416 | shift |
| 417 | done |
| 418 | |
| 419 | $CHECK |
| 420 | qemu_set_binfmts |