2017-05-26 20:08:45 +00:00
|
|
|
"""
|
2019-01-02 08:31:20 +00:00
|
|
|
Copyright 2019 Oliver Smith
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import platform
|
|
|
|
import fnmatch
|
|
|
|
|
|
|
|
|
|
|
|
def alpine_native():
|
|
|
|
machine = platform.machine()
|
|
|
|
ret = ""
|
|
|
|
|
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",
|
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
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def from_chroot_suffix(args, suffix):
|
|
|
|
if suffix == "native":
|
|
|
|
return args.arch_native
|
|
|
|
if suffix == "rootfs_" + args.device:
|
|
|
|
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.
|
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",
|
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",
|
|
|
|
"armhf": "armv6-alpine-linux-muslgnueabihf",
|
|
|
|
"armv7": "armv7-alpine-linux-musleabihf",
|
|
|
|
"ppc": "powerpc-alpine-linux-musl",
|
|
|
|
"ppc64": "powerpc64-alpine-linux-musl",
|
|
|
|
"ppc64le": "powerpc64le-alpine-linux-musl",
|
|
|
|
"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
|
|
|
|
|
|
|
|
|
|
|
def cpu_emulation_required(args, arch):
|
|
|
|
# Obvious case: host arch is target arch
|
|
|
|
if args.arch_native == arch:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Other cases: host arch on the left, target archs on the right
|
|
|
|
not_required = {
|
|
|
|
"x86_64": ["x86"],
|
|
|
|
"aarch64": ["armel", "armhf", "armv7"],
|
|
|
|
}
|
|
|
|
if args.arch_native in not_required:
|
|
|
|
if arch in not_required[args.arch_native]:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# No match: then it's required
|
|
|
|
return True
|
2017-08-09 20:26:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
def uname_to_qemu(arch):
|
|
|
|
"""
|
|
|
|
Convert the most common architectures returned by 'uname' to those
|
|
|
|
used by the QEMU binary
|
|
|
|
"""
|
|
|
|
mapping = {
|
|
|
|
"aarch64": "aarch64",
|
|
|
|
"arm": "arm",
|
|
|
|
"armeb": "arm",
|
|
|
|
"armel": "arm",
|
|
|
|
"armhf": "arm",
|
2018-12-12 20:22:27 +00:00
|
|
|
"armv7l": "arm",
|
2017-08-09 20:26:40 +00:00
|
|
|
"x86_64": "x86_64",
|
|
|
|
"amd64": "x86_64",
|
|
|
|
}
|
|
|
|
if arch in mapping:
|
|
|
|
return mapping[arch]
|
|
|
|
|
|
|
|
raise ValueError("Can not map host architecture '" + arch + "'"
|
|
|
|
" to the right QEMU value")
|
|
|
|
|
|
|
|
|
|
|
|
def qemu_to_pmos_device(arch):
|
|
|
|
"""
|
|
|
|
Convert the architecture used in the QEMU binary to the aport name in
|
|
|
|
postmarketOS defining the device
|
|
|
|
"""
|
|
|
|
mapping = {
|
|
|
|
"arm": "qemu-vexpress",
|
|
|
|
"aarch64": "qemu-aarch64",
|
|
|
|
"x86_64": "qemu-amd64",
|
|
|
|
}
|
|
|
|
if arch in mapping:
|
|
|
|
return mapping[arch]
|
|
|
|
|
|
|
|
raise ValueError("Can not map QEMU value '" + arch + "'"
|
|
|
|
" to the right postmarketOS device")
|
2018-01-08 15:18:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def qemu_check_device(device, arch):
|
|
|
|
"""
|
|
|
|
Check whether a device has a specific architecture.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
qemu_check_device("qemu-amd64", "x86_64") is True
|
|
|
|
qemu_check_device("qemu-vexpress", "armel") is True
|
|
|
|
qemu_check_device("qemu-vexpress", "aarch64") is False
|
|
|
|
"""
|
|
|
|
arch_qemu = uname_to_qemu(arch)
|
|
|
|
return device == qemu_to_pmos_device(arch_qemu)
|