| 
									
										
										
										
											2004-01-04 18:12:46 +00:00
										 |  |  | #!/bin/sh
 | 
					
						
							| 
									
										
										
										
											2018-05-27 08:41:53 -05:00
										 |  |  | # Enable automatic program execution by the kernel. | 
					
						
							| 
									
										
										
										
											2004-01-04 18:12:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 12:33:07 +01:00
										 |  |  | qemu_target_list="i386 i486 alpha arm armeb sparc sparc32plus sparc64 \
 | 
					
						
							|  |  |  | ppc ppc64 ppc64le m68k mips mipsel mipsn32 mipsn32el mips64 mips64el \
 | 
					
						
							| 
									
										
										
										
											2018-05-27 08:41:53 -05:00
										 |  |  | sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb \
 | 
					
						
							| 
									
										
										
										
											2022-06-24 11:10:42 +08:00
										 |  |  | microblaze microblazeel or1k x86_64 hexagon loongarch64"
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | i386_family=i386 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | i486_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | i486_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | i486_family=i386 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 12:29:44 +02:00
										 |  |  | x86_64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00' | 
					
						
							|  |  |  | x86_64_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | x86_64_family=i386 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | alpha_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | alpha_mask='\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | alpha_family=alpha | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00' | 
					
						
							|  |  |  | arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | arm_family=arm | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28' | 
					
						
							|  |  |  | armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2018-01-11 13:25:33 +00:00
										 |  |  | armeb_family=armeb | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | sparc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | sparc_family=sparc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sparc32plus_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | sparc32plus_family=sparc | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 12:33:07 +01:00
										 |  |  | sparc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2b' | 
					
						
							|  |  |  | sparc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							|  |  |  | sparc64_family=sparc | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14' | 
					
						
							|  |  |  | ppc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							|  |  |  | ppc_family=ppc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ppc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15' | 
					
						
							|  |  |  | ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							|  |  |  | ppc64_family=ppc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ppc64le_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00' | 
					
						
							|  |  |  | ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00' | 
					
						
							|  |  |  | ppc64le_family=ppcle | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | m68k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | m68k_mask='\xff\xff\xff\xff\xff\xff\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | m68k_family=m68k | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # FIXME: We could use the other endianness on a MIPS host. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 22:49:01 +02:00
										 |  |  | 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' | 
					
						
							|  |  |  | 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' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | mips_family=mips | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 22:49:01 +02:00
										 |  |  | 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' | 
					
						
							|  |  |  | 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' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | mipsel_family=mips | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 22:49:01 +02:00
										 |  |  | 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' | 
					
						
							|  |  |  | 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' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | mipsn32_family=mips | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 22:49:01 +02:00
										 |  |  | 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' | 
					
						
							|  |  |  | 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' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | mipsn32el_family=mips | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' | 
					
						
							| 
									
										
										
										
											2022-03-28 22:49:01 +02:00
										 |  |  | mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | mips64_family=mips | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' | 
					
						
							| 
									
										
										
										
											2022-03-28 22:49:01 +02:00
										 |  |  | mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | mips64el_family=mips | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | sh4_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | sh4_family=sh4 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sh4eb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | sh4eb_family=sh4 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | s390x_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16' | 
					
						
							| 
									
										
										
										
											2018-06-05 21:47:25 +02:00
										 |  |  | s390x_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | s390x_family=s390x | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' | 
					
						
							|  |  |  | aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | aarch64_family=arm | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-11 13:25:32 +00:00
										 |  |  | aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7' | 
					
						
							|  |  |  | aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							| 
									
										
										
										
											2018-01-11 13:25:33 +00:00
										 |  |  | aarch64_be_family=armeb | 
					
						
							| 
									
										
										
										
											2018-01-11 13:25:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-26 09:04:47 +01:00
										 |  |  | hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f' | 
					
						
							|  |  |  | hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							|  |  |  | hppa_family=hppa | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 01:32:59 +13:00
										 |  |  | riscv32_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' | 
					
						
							|  |  |  | riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | riscv32_family=riscv | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | riscv64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' | 
					
						
							|  |  |  | riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | riscv64_family=riscv | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 14:16:08 -08:00
										 |  |  | xtensa_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00' | 
					
						
							|  |  |  | xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | xtensa_family=xtensa | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | xtensaeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e' | 
					
						
							|  |  |  | xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							|  |  |  | xtensaeb_family=xtensaeb | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 13:52:12 +02:00
										 |  |  | microblaze_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xba\xab' | 
					
						
							|  |  |  | microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | microblaze_family=microblaze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | microblazeel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba' | 
					
						
							|  |  |  | microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | microblazeel_family=microblazeel | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-27 08:41:53 -05:00
										 |  |  | or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5c' | 
					
						
							|  |  |  | or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' | 
					
						
							|  |  |  | or1k_family=or1k | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-07 23:46:24 -06:00
										 |  |  | hexagon_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xa4\x00' | 
					
						
							|  |  |  | hexagon_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | hexagon_family=hexagon | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-24 11:10:42 +08:00
										 |  |  | loongarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x01' | 
					
						
							|  |  |  | loongarch64_mask='\xff\xff\xff\xff\xff\xff\xff\xfc\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' | 
					
						
							|  |  |  | loongarch64_family=loongarch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | qemu_get_family() { | 
					
						
							|  |  |  |     cpu=${HOST_ARCH:-$(uname -m)} | 
					
						
							|  |  |  |     case "$cpu" in | 
					
						
							|  |  |  |     amd64|i386|i486|i586|i686|i86pc|BePC|x86_64) | 
					
						
							|  |  |  |         echo "i386" | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     mips*) | 
					
						
							|  |  |  |         echo "mips" | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     "Power Macintosh"|ppc64|powerpc|ppc) | 
					
						
							|  |  |  |         echo "ppc" | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     ppc64el|ppc64le) | 
					
						
							|  |  |  |         echo "ppcle" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2018-01-11 13:25:33 +00:00
										 |  |  |     arm|armel|armhf|arm64|armv[4-9]*l|aarch64) | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |         echo "arm" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2018-01-11 13:25:33 +00:00
										 |  |  |     armeb|armv[4-9]*b|aarch64_be) | 
					
						
							|  |  |  |         echo "armeb" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |     sparc*) | 
					
						
							|  |  |  |         echo "sparc" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2018-03-03 01:32:59 +13:00
										 |  |  |     riscv*) | 
					
						
							|  |  |  |         echo "riscv" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2022-07-05 14:59:42 +08:00
										 |  |  |     loongarch*) | 
					
						
							|  |  |  |         echo "loongarch" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |     *) | 
					
						
							|  |  |  |         echo "$cpu" | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | usage() { | 
					
						
							|  |  |  |     cat <<EOF | 
					
						
							|  |  |  | Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] | 
					
						
							|  |  |  |                            [--help][--credential yes|no][--exportdir PATH] | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:17 +02:00
										 |  |  |                            [--persistent yes|no][--qemu-suffix SUFFIX] | 
					
						
							| 
									
										
										
										
											2021-02-22 11:50:04 +01:00
										 |  |  |                            [--preserve-argv0 yes|no] | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |        Configure binfmt_misc to use qemu interpreter | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-22 11:50:04 +01:00
										 |  |  |        --help:          display this usage | 
					
						
							|  |  |  |        --qemu-path:     set path to qemu interpreter ($QEMU_PATH) | 
					
						
							|  |  |  |        --qemu-suffix:   add a suffix to the default interpreter name | 
					
						
							|  |  |  |        --debian:        don't write into /proc, | 
					
						
							|  |  |  |                         instead generate update-binfmts templates | 
					
						
							|  |  |  |        --systemd:       don't write into /proc, | 
					
						
							|  |  |  |                         instead generate file for systemd-binfmt.service | 
					
						
							|  |  |  |                         for the given CPU. If CPU is "ALL", generate a | 
					
						
							|  |  |  |                         file for all known cpus | 
					
						
							|  |  |  |        --exportdir:     define where to write configuration files | 
					
						
							|  |  |  |                         (default: $SYSTEMDDIR or $DEBIANDIR) | 
					
						
							|  |  |  |        --credential:    if yes, credential and security tokens are | 
					
						
							|  |  |  |                         calculated according to the binary to interpret | 
					
						
							|  |  |  |        --persistent:    if yes, the interpreter is loaded when binfmt is | 
					
						
							|  |  |  |                         configured and remains in memory. All future uses | 
					
						
							|  |  |  |                         are cloned from the open file. | 
					
						
							|  |  |  |        --preserve-argv0 preserve argv[0] | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     To import templates with update-binfmts, use : | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sudo update-binfmts --importdir ${EXPORTDIR:-$DEBIANDIR} --import qemu-CPU | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     To remove interpreter, use : | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sudo update-binfmts --package qemu-CPU --remove qemu-CPU $QEMU_PATH | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     With systemd, binfmt files are loaded by systemd-binfmt.service | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     The environment variable HOST_ARCH allows to override 'uname' to generate | 
					
						
							|  |  |  |     configuration files for a different architecture than the current one. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     where CPU is one of: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $qemu_target_list | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EOF | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_check_access() { | 
					
						
							|  |  |  |     if [ ! -w "$1" ] ; then | 
					
						
							|  |  |  |         echo "ERROR: cannot write to $1" 1>&2 | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_check_bintfmt_misc() { | 
					
						
							|  |  |  |     # load the binfmt_misc module | 
					
						
							|  |  |  |     if [ ! -d /proc/sys/fs/binfmt_misc ]; then | 
					
						
							|  |  |  |       if ! /sbin/modprobe binfmt_misc ; then | 
					
						
							|  |  |  |           exit 1 | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then | 
					
						
							|  |  |  |       if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then | 
					
						
							|  |  |  |           exit 1 | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qemu_check_access /proc/sys/fs/binfmt_misc/register | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | installed_dpkg() { | 
					
						
							|  |  |  |     dpkg --status "$1" > /dev/null 2>&1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_check_debian() { | 
					
						
							|  |  |  |     if [ ! -e /etc/debian_version ] ; then | 
					
						
							|  |  |  |         echo "WARNING: your system is not a Debian based distro" 1>&2 | 
					
						
							|  |  |  |     elif ! installed_dpkg binfmt-support ; then | 
					
						
							|  |  |  |         echo "WARNING: package binfmt-support is needed" 1>&2 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     qemu_check_access "$EXPORTDIR" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_check_systemd() { | 
					
						
							|  |  |  |     if ! systemctl -q is-enabled systemd-binfmt.service ; then | 
					
						
							|  |  |  |         echo "WARNING: systemd-binfmt.service is missing or disabled" 1>&2 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     qemu_check_access "$EXPORTDIR" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_generate_register() { | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:15 +02:00
										 |  |  |     flags="" | 
					
						
							|  |  |  |     if [ "$CREDENTIAL" = "yes" ] ; then | 
					
						
							|  |  |  |         flags="OC" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:16 +02:00
										 |  |  |     if [ "$PERSISTENT" = "yes" ] ; then | 
					
						
							|  |  |  |         flags="${flags}F" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2021-02-22 11:50:04 +01:00
										 |  |  |     if [ "$PRESERVE_ARG0" = "yes" ] ; then | 
					
						
							|  |  |  |         flags="${flags}P" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags" | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_register_interpreter() { | 
					
						
							|  |  |  |     echo "Setting $qemu as binfmt interpreter for $cpu" | 
					
						
							|  |  |  |     qemu_generate_register > /proc/sys/fs/binfmt_misc/register | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_generate_systemd() { | 
					
						
							|  |  |  |     echo "Setting $qemu as binfmt interpreter for $cpu for systemd-binfmt.service" | 
					
						
							|  |  |  |     qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_generate_debian() { | 
					
						
							|  |  |  |     cat > "$EXPORTDIR/qemu-$cpu" <<EOF | 
					
						
							|  |  |  | package qemu-$cpu | 
					
						
							|  |  |  | interpreter $qemu | 
					
						
							|  |  |  | magic $magic | 
					
						
							|  |  |  | mask $mask | 
					
						
							| 
									
										
										
										
											2021-03-23 13:34:57 +01:00
										 |  |  | credentials $CREDENTIAL | 
					
						
							|  |  |  | preserve $PRESERVE_ARG0 | 
					
						
							|  |  |  | fix_binary $PERSISTENT | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | EOF | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qemu_set_binfmts() { | 
					
						
							|  |  |  |     # probe cpu type | 
					
						
							|  |  |  |     host_family=$(qemu_get_family) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # register the interpreter for each cpu except for the native one | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for cpu in ${qemu_target_list} ; do | 
					
						
							|  |  |  |         magic=$(eval echo \$${cpu}_magic) | 
					
						
							|  |  |  |         mask=$(eval echo \$${cpu}_mask) | 
					
						
							|  |  |  |         family=$(eval echo \$${cpu}_family) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if [ "$magic" = "" ] || [ "$mask" = "" ] || [ "$family" = "" ] ; then | 
					
						
							|  |  |  |             echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2 | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         qemu="$QEMU_PATH/qemu-$cpu" | 
					
						
							|  |  |  |         if [ "$cpu" = "i486" ] ; then | 
					
						
							|  |  |  |             qemu="$QEMU_PATH/qemu-i386" | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:17 +02:00
										 |  |  |         qemu="$qemu$QEMU_SUFFIX" | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |         if [ "$host_family" != "$family" ] ; then | 
					
						
							|  |  |  |             $BINFMT_SET | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CHECK=qemu_check_bintfmt_misc | 
					
						
							|  |  |  | BINFMT_SET=qemu_register_interpreter | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SYSTEMDDIR="/etc/binfmt.d" | 
					
						
							|  |  |  | DEBIANDIR="/usr/share/binfmts" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QEMU_PATH=/usr/local/bin | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:15 +02:00
										 |  |  | CREDENTIAL=no | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:16 +02:00
										 |  |  | PERSISTENT=no | 
					
						
							| 
									
										
										
										
											2021-02-22 11:50:04 +01:00
										 |  |  | PRESERVE_ARG0=no | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:17 +02:00
										 |  |  | QEMU_SUFFIX="" | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 14:51:00 +01:00
										 |  |  | _longopts="debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,\
 | 
					
						
							|  |  |  | persistent:,preserve-argv0:"
 | 
					
						
							|  |  |  | options=$(getopt -o ds:Q:S:e:hc:p:g:F: -l ${_longopts} -- "$@") | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  | eval set -- "$options" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | while true ; do | 
					
						
							|  |  |  |     case "$1" in | 
					
						
							|  |  |  |     -d|--debian) | 
					
						
							|  |  |  |         CHECK=qemu_check_debian | 
					
						
							|  |  |  |         BINFMT_SET=qemu_generate_debian | 
					
						
							|  |  |  |         EXPORTDIR=${EXPORTDIR:-$DEBIANDIR} | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     -s|--systemd) | 
					
						
							|  |  |  |         CHECK=qemu_check_systemd | 
					
						
							|  |  |  |         BINFMT_SET=qemu_generate_systemd | 
					
						
							|  |  |  |         EXPORTDIR=${EXPORTDIR:-$SYSTEMDDIR} | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |         # check given cpu is in the supported CPU list | 
					
						
							| 
									
										
										
										
											2018-03-08 11:48:59 +01:00
										 |  |  |         if [ "$1" != "ALL" ] ; then | 
					
						
							|  |  |  |             for cpu in ${qemu_target_list} ; do | 
					
						
							|  |  |  |                 if [ "$cpu" = "$1" ] ; then | 
					
						
							|  |  |  |                     break | 
					
						
							|  |  |  |                 fi | 
					
						
							|  |  |  |             done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-25 15:18:28 +02:00
										 |  |  |             if [ "$cpu" = "$1" ] ; then | 
					
						
							| 
									
										
										
										
											2018-03-08 11:48:59 +01:00
										 |  |  |                 qemu_target_list="$1" | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 echo "ERROR: unknown CPU \"$1\"" 1>&2 | 
					
						
							|  |  |  |                 usage | 
					
						
							|  |  |  |                 exit 1 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |             fi | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     -Q|--qemu-path) | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |         QEMU_PATH="$1" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:17 +02:00
										 |  |  |     -F|--qemu-suffix) | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |         QEMU_SUFFIX="$1" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |     -e|--exportdir) | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |         EXPORTDIR="$1" | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     -h|--help) | 
					
						
							|  |  |  |         usage | 
					
						
							|  |  |  |         exit 1 | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     -c|--credential) | 
					
						
							|  |  |  |         shift | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:15 +02:00
										 |  |  |         CREDENTIAL="$1" | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2018-06-27 22:53:16 +02:00
										 |  |  |     -p|--persistent) | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |         PERSISTENT="$1" | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2021-02-22 11:50:04 +01:00
										 |  |  |     -g|--preserve-argv0) | 
					
						
							|  |  |  |         shift | 
					
						
							|  |  |  |         PRESERVE_ARG0="$1" | 
					
						
							|  |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2016-01-29 17:07:31 +01:00
										 |  |  |     *) | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  |     shift | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $CHECK | 
					
						
							|  |  |  | qemu_set_binfmts |