123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- #!/bin/sh
- readonly LIBTOOLS="cp echo cat printf which mountpoint mount umount modprobe"
- readonly HOSTARCH=$(xbps-uhelper arch)
- info_msg() {
-
-
-
- printf "\033[1m%s\n\033[m" "$@"
- }
- die() {
-
-
-
- printf "FATAL: %s\n" "$@"
- umount_pseudofs
- [ -d "$ROOTFS" ] && rm -rf "$ROOTFS"
- exit 1
- }
- check_tools() {
-
-
-
-
-
- for tool in $LIBTOOLS $REQTOOLS ; do
- if ! which "$tool" > /dev/null ; then
- die "Required tool $f is not available on this system!"
- fi
- done
- info_msg "The following tools will be used:"
- for tool in $LIBTOOLS $REQTOOLS ; do
- which "$tool"
- done
- }
- mount_pseudofs() {
-
-
-
-
- for f in dev proc sys; do
-
-
- [ ! -d "$ROOTFS/$f" ] && mkdir -p "$ROOTFS/$f"
- if ! mountpoint -q "$ROOTFS/$f" ; then
-
-
-
-
- mount -r --bind /$f "$ROOTFS/$f"
- fi
- done
- }
- umount_pseudofs() {
-
-
-
-
-
- if [ -d "${ROOTFS}" ]; then
- for f in dev proc sys; do
- umount -f "$ROOTFS/$f" >/dev/null 2>&1
- done
- fi
- }
- run_cmd_target() {
- info_msg "Running $* for target $XBPS_TARGET_ARCH ..."
- if [ "$XBPS_TARGET_ARCH" = "${HOSTARCH}" ] ||
- [ -z "${XBPS_TARGET_ARCH##*86*}" ] &&
- [ -z "${HOSTARCH##*86*}" ] ; then
-
-
- if ! eval XBPS_ARCH="$XBPS_TARGET_ARCH" "$@" ; then
- die "Could not run command $*"
- fi
- else
-
-
-
- if ! eval XBPS_TARGET_ARCH="$XBPS_TARGET_ARCH" "$@" ; then
- die "Could not run command $*"
- fi
- fi
- }
- run_cmd() {
-
-
-
-
- info_msg "Running $*"
- eval "$@"
- }
- run_cmd_chroot() {
-
-
-
-
-
-
- register_binfmt
-
-
-
- mount_pseudofs
-
-
- chroot "$1" sh -c "$2"
- }
- cleanup_chroot() {
-
-
-
-
- umount_pseudofs
-
- if [ -x "$ROOTFS/usr/bin/$QEMU_BIN" ] ; then
- rm "$ROOTFS/usr/bin/$QEMU_BIN"
- fi
- }
- register_binfmt() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if [ -z "$XBPS_TARGET_ARCH" ] && [ ! -z "$PLATFORM" ] ; then
- set_target_arch_from_platform
- fi
- case "${XBPS_TARGET_ARCH}" in
- armv*)
- _cpu=arm
- _magic="\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00"
- _mask="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
- QEMU_BIN=qemu-arm-static
- ;;
- aarch64*)
- _cpu=aarch64
- _magic="\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7"
- _mask="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
- QEMU_BIN=qemu-aarch64-static
- ;;
- ppc*)
- _cpu=ppc
- _magic="\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14"
- _mask="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff"
- QEMU_BIN=qemu-ppc-static
- ;;
- mipsel*)
- _cpu=mipsel
- _magic="\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00"
- _mask="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
- QEMU_BIN=qemu-mipsel-static
- ;;
- *86*)
- info_msg "FIXME: Assuming that x86 instructions are native"
- QEMU_BIN=NATIVE
- ;;
- *)
- die "Unknown target architecture!"
- ;;
- esac
-
-
- if [ "$QEMU_BIN" = "NATIVE" ] ; then
- return
- fi
-
-
- if ! $QEMU_BIN -version >/dev/null 2>&1; then
- die "$QEMU_BIN binary is missing in your system, exiting."
- fi
-
-
- if ! mountpoint -q /proc/sys/fs/binfmt_misc ; then
- modprobe -q binfmt_misc
- mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc 2>/dev/null
- fi
-
- if [ ! -f /proc/sys/fs/binfmt_misc/qemu-$_cpu ] ; then
- echo ":qemu-$_cpu:M::$_magic:$_mask:/usr/bin/$QEMU_BIN:" > /proc/sys/fs/binfmt_misc/register 2>/dev/null
- fi
-
-
-
-
-
-
- if [ ! -x "$ROOTFS/usr/bin/$QEMU_BIN" ] ; then
- cp -f "$(which "$QEMU_BIN")" "$ROOTFS/usr/bin" ||
- die "Could not install $QEMU_BIN to $ROOTFS/usr/bin/"
- fi
- }
- set_target_arch_from_platform() {
-
-
-
-
- case "$PLATFORM" in
- bananapi*) XBPS_TARGET_ARCH="armv7l";;
- beaglebone*) XBPS_TARGET_ARCH="armv7l";;
- cubieboard2*|cubietruck*) XBPS_TARGET_ARCH="armv7l";;
- dockstar*) XBPS_TARGET_ARCH="armv5tel";;
- pogoplugv4*) XBPS_TARGET_ARCH="armv5tel" ;;
- odroid-u2*) XBPS_TARGET_ARCH="armv7l";;
- odroid-c2*) XBPS_TARGET_ARCH="aarch64";;
- rpi3*) XBPS_TARGET_ARCH="aarch64";;
- rpi2*) XBPS_TARGET_ARCH="armv7l";;
- rpi*) XBPS_TARGET_ARCH="armv6l";;
- usbarmory*) XBPS_TARGET_ARCH="armv7l";;
- ci20*) XBPS_TARGET_ARCH="mipsel";;
- i686*) XBPS_TARGET_ARCH="i686";;
- x86_64*) XBPS_TARGET_ARCH="x86_64";;
- GCP*) XBPS_TARGET_ARCH="x86_64";;
- *) die "$PROGNAME: Unable to compute target architecture from platform";;
- esac
- if [ -z "${PLATFORM##*-musl}" ] ; then
- XBPS_TARGET_ARCH="${XBPS_TARGET_ARCH}-musl"
- fi
- }
- set_dracut_args_from_platform() {
-
-
- case "$PLATFORM" in
- pogoplugv4*) dracut_args="-o 'btrfs drm i18n resume terminfo'" ;;
- *) ;;
- esac
- }
- set_cachedir() {
-
-
- : "${XBPS_CACHEDIR:=--cachedir=$PWD/xbps-cache/${XBPS_TARGET_ARCH}}"
- }
- : "${XBPS_REPOSITORY:=--repository=http://alpha.de.repo.voidlinux.org/current \
- --repository=http://alpha.de.repo.voidlinux.org/current/musl \
- --repository=http://alpha.de.repo.voidlinux.org/current/aarch64}"
- case $1 in
- platform2arch)
- PLATFORM=$2
- set_target_arch_from_platform
- echo "$XBPS_TARGET_ARCH"
- ;;
- esac
|