2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-05-26 20:08:45 +00:00
|
|
|
import fnmatch
|
2021-10-16 16:33:27 +00:00
|
|
|
import platform
|
|
|
|
import pmb.parse.arch
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def alpine_native():
|
|
|
|
machine = platform.machine()
|
|
|
|
|
2017-06-26 22:28:11 +00:00
|
|
|
mapping = {
|
2018-01-24 00:56:11 +00:00
|
|
|
"i686": "x86",
|
2017-06-26 22:28:11 +00:00
|
|
|
"x86_64": "x86_64",
|
2017-10-02 22:49:40 +00:00
|
|
|
"aarch64": "aarch64",
|
2022-12-02 19:25:02 +00:00
|
|
|
"arm64": "aarch64",
|
2019-02-13 09:02:43 +00:00
|
|
|
"armv6l": "armhf",
|
2018-12-12 20:22:27 +00:00
|
|
|
"armv7l": "armv7"
|
2017-06-26 22:28:11 +00:00
|
|
|
}
|
|
|
|
if machine in mapping:
|
|
|
|
return mapping[machine]
|
2017-07-29 15:16:43 +00:00
|
|
|
raise ValueError("Can not map platform.machine '" + machine + "'"
|
2017-06-26 22:28:11 +00:00
|
|
|
" to the right Alpine Linux architecture")
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def from_chroot_suffix(args, suffix):
|
|
|
|
if suffix == "native":
|
2021-10-16 16:33:27 +00:00
|
|
|
return pmb.config.arch_native
|
2020-06-06 21:38:34 +00:00
|
|
|
if suffix in [f"rootfs_{args.device}", f"installer_{args.device}"]:
|
2017-05-26 20:08:45 +00:00
|
|
|
return args.deviceinfo["arch"]
|
|
|
|
if suffix.startswith("buildroot_"):
|
2018-01-23 00:54:48 +00:00
|
|
|
return suffix.split("_", 1)[1]
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
raise ValueError("Invalid chroot suffix: " + suffix +
|
|
|
|
" (wrong device chosen in 'init' step?)")
|
|
|
|
|
|
|
|
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
def alpine_to_qemu(arch):
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
Convert the architecture to the string used in the QEMU packaging.
|
2022-10-13 22:12:37 +00:00
|
|
|
This corresponds to the package name of e.g. qemu-system-aarch64.
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
mapping = {
|
2018-01-24 00:56:11 +00:00
|
|
|
"x86": "i386",
|
|
|
|
"x86_64": "x86_64",
|
2017-05-26 20:08:45 +00:00
|
|
|
"armhf": "arm",
|
2018-12-12 20:22:27 +00:00
|
|
|
"armv7": "arm",
|
2017-06-14 17:10:21 +00:00
|
|
|
"aarch64": "aarch64",
|
2022-10-13 22:12:37 +00:00
|
|
|
"riscv64": "riscv64",
|
2017-05-26 20:08:45 +00:00
|
|
|
}
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
for pattern, arch_qemu in mapping.items():
|
2017-05-26 20:08:45 +00:00
|
|
|
if fnmatch.fnmatch(arch, pattern):
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
return arch_qemu
|
2017-07-29 15:16:43 +00:00
|
|
|
raise ValueError("Can not map Alpine architecture '" + arch + "'"
|
2017-05-26 20:08:45 +00:00
|
|
|
" to the right Debian architecture.")
|
|
|
|
|
|
|
|
|
|
|
|
def alpine_to_kernel(arch):
|
|
|
|
"""
|
|
|
|
Convert the architecture to the string used inside the kernel sources.
|
|
|
|
You can read the mapping from the linux-vanilla APKBUILD for example.
|
|
|
|
"""
|
|
|
|
mapping = {
|
|
|
|
"aarch64*": "arm64",
|
|
|
|
"arm*": "arm",
|
|
|
|
"ppc*": "powerpc",
|
|
|
|
"s390*": "s390"
|
|
|
|
}
|
|
|
|
for pattern, arch_kernel in mapping.items():
|
|
|
|
if fnmatch.fnmatch(arch, pattern):
|
|
|
|
return arch_kernel
|
|
|
|
return arch
|
|
|
|
|
|
|
|
|
|
|
|
def alpine_to_hostspec(arch):
|
|
|
|
"""
|
|
|
|
See: abuild source code/functions.sh.in: arch_to_hostspec()
|
|
|
|
"""
|
|
|
|
mapping = {
|
|
|
|
"aarch64": "aarch64-alpine-linux-musl",
|
2019-09-18 11:36:58 +00:00
|
|
|
"armel": "armv5-alpine-linux-musleabi",
|
|
|
|
"armhf": "armv6-alpine-linux-musleabihf",
|
2017-05-26 20:08:45 +00:00
|
|
|
"armv7": "armv7-alpine-linux-musleabihf",
|
2022-10-13 22:12:37 +00:00
|
|
|
"loongarch32": "loongarch32-alpine-linux-musl",
|
|
|
|
"loongarchx32": "loongarchx32-alpine-linux-musl",
|
|
|
|
"loongarch64": "loongarch64-alpine-linux-musl",
|
2019-09-18 11:36:58 +00:00
|
|
|
"mips": "mips-alpine-linux-musl",
|
|
|
|
"mips64": "mips64-alpine-linux-musl",
|
|
|
|
"mipsel": "mipsel-alpine-linux-musl",
|
|
|
|
"mips64el": "mips64el-alpine-linux-musl",
|
2017-05-26 20:08:45 +00:00
|
|
|
"ppc": "powerpc-alpine-linux-musl",
|
|
|
|
"ppc64": "powerpc64-alpine-linux-musl",
|
|
|
|
"ppc64le": "powerpc64le-alpine-linux-musl",
|
2022-10-13 22:12:37 +00:00
|
|
|
"riscv32": "riscv32-alpine-linux-musl",
|
|
|
|
"riscv64": "riscv64-alpine-linux-musl",
|
2017-05-26 20:08:45 +00:00
|
|
|
"s390x": "s390x-alpine-linux-musl",
|
|
|
|
"x86": "i586-alpine-linux-musl",
|
2017-06-26 22:28:11 +00:00
|
|
|
"x86_64": "x86_64-alpine-linux-musl",
|
2017-05-26 20:08:45 +00:00
|
|
|
}
|
|
|
|
if arch in mapping:
|
|
|
|
return mapping[arch]
|
|
|
|
|
2017-07-29 15:16:43 +00:00
|
|
|
raise ValueError("Can not map Alpine architecture '" + arch + "'"
|
2017-05-26 20:08:45 +00:00
|
|
|
" to the right hostspec value")
|
2017-07-26 19:01:44 +00:00
|
|
|
|
|
|
|
|
2021-10-16 16:33:27 +00:00
|
|
|
def cpu_emulation_required(arch):
|
2017-07-26 19:01:44 +00:00
|
|
|
# Obvious case: host arch is target arch
|
2021-10-16 16:33:27 +00:00
|
|
|
if pmb.config.arch_native == arch:
|
2017-07-26 19:01:44 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
# Other cases: host arch on the left, target archs on the right
|
|
|
|
not_required = {
|
|
|
|
"x86_64": ["x86"],
|
2020-06-22 14:56:24 +00:00
|
|
|
"armv7": ["armel", "armhf"],
|
2017-07-26 19:01:44 +00:00
|
|
|
"aarch64": ["armel", "armhf", "armv7"],
|
|
|
|
}
|
2021-10-16 16:33:27 +00:00
|
|
|
if pmb.config.arch_native in not_required:
|
|
|
|
if arch in not_required[pmb.config.arch_native]:
|
2017-07-26 19:01:44 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
# No match: then it's required
|
|
|
|
return True
|