123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- #!/bin/sh
- readonly LIBTOOLS="cp echo cat printf which mountpoint mount umount modprobe"
- readonly HOSTARCH=$(xbps-uhelper arch)
- is_target_native() {
-
-
- local target_arch
- target_arch="$1"
-
- if [ "${target_arch%-musl}" = "${HOSTARCH%-musl}" ]; then
- return 0
- fi
- case "$HOSTARCH" in
-
- ppc64le*) return 1 ;;
-
- x86_64*) test -z "${target_arch##*86*}" ;;
-
- aarch64*) test -z "${target_arch##armv*}" ;;
-
- ppc64*) test "${target_arch%-musl}" = "ppc" ;;
-
- *) return 1 ;;
- esac
- return $?
- }
- version() (
- set +u
- [ -n "$PROGNAME" ] && printf "%s " "$PROGNAME"
- echo "$(cat ./version) ${MKLIVE_REV:-"$(git -c safe.directory="$(pwd)" rev-parse --short HEAD 2> /dev/null)"}"
- )
- 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 $tool 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 --rbind /$f "$ROOTFS/$f" --make-rslave
- fi
- done
- if ! mountpoint -q "$ROOTFS/tmp" ; then
- mkdir -p "$ROOTFS/tmp"
- mount -o mode=0755,nosuid,nodev -t tmpfs tmpfs "$ROOTFS/tmp"
- fi
- }
- umount_pseudofs() {
-
-
-
-
-
- if [ -d "${ROOTFS}" ]; then
- for f in dev proc sys; do
- umount -R -f "$ROOTFS/$f" >/dev/null 2>&1
- done
- fi
- umount -f "$ROOTFS/tmp" >/dev/null 2>&1
- }
- run_cmd_target() {
- info_msg "Running $* for target $XBPS_TARGET_ARCH ..."
- if is_target_native "$XBPS_TARGET_ARCH"; 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
- }
- register_binfmt() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if [ -z "$XBPS_TARGET_ARCH" ] && [ ! -z "$PLATFORM" ] ; then
- set_target_arch_from_platform
- fi
-
-
-
-
- _hostarch="${HOSTARCH%-musl}"
- _targetarch="${XBPS_TARGET_ARCH%-musl}"
- if [ "$_hostarch" = "$_targetarch" ] ; then
- return
- fi
- case "${_targetarch}" in
- armv*)
-
- if ( [ "${_targetarch}" = "armv6l" ] && [ "${_hostarch}" = "armv7l" ] ) ; then
- return
- fi
- if [ "${_targetarch}" = "armv5tel" -a \
- \( "${_hostarch}" = "armv6l" -o "${_hostarch}" = "armv7l" \) ] ; then
- return
- fi
- _cpu=arm
- ;;
- aarch64)
- _cpu=aarch64
- ;;
- ppc64le)
- _cpu=ppc64le
- ;;
- ppc64)
- _cpu=ppc64
- ;;
- ppc)
- if [ "$_hostarch" = "ppc64" ] ; then
- return
- fi
- _cpu=ppc
- ;;
- mipsel)
- if [ "$_hostarch" = "mips64el" ] ; then
- return
- fi
- _cpu=mipsel
- ;;
- x86_64)
- _cpu=x86_64
- ;;
- i686)
- if [ "$_hostarch" = "x86_64" ] ; then
- return
- fi
- _cpu=i386
- ;;
- riscv64)
- _cpu=riscv64
- ;;
- *)
- die "Unknown target architecture!"
- ;;
- esac
-
-
- QEMU_BIN="qemu-${_cpu}"
- 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
- if ! command -v update-binfmts >/dev/null 2>&1; then
- die "could not add binfmt: update-binfmts binary is missing in your system"
- fi
- update-binfmts --import "qemu-$_cpu"
- fi
- }
- set_target_arch_from_platform() {
-
-
-
-
- case "$PLATFORM" in
- rpi-aarch64*) XBPS_TARGET_ARCH="aarch64";;
- rpi-armv7l*) XBPS_TARGET_ARCH="armv7l";;
- rpi-armv6l*) XBPS_TARGET_ARCH="armv6l";;
- i686*) XBPS_TARGET_ARCH="i686";;
- x86_64*) XBPS_TARGET_ARCH="x86_64";;
- GCP*) XBPS_TARGET_ARCH="x86_64";;
- pinebookpro*) XBPS_TARGET_ARCH="aarch64";;
- pinephone*) XBPS_TARGET_ARCH="aarch64";;
- rock64*) XBPS_TARGET_ARCH="aarch64";;
- rockpro64*) XBPS_TARGET_ARCH="aarch64";;
- asahi*) XBPS_TARGET_ARCH="aarch64";;
- *) 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
- *) ;;
- esac
- }
- set_cachedir() {
-
-
- : "${XBPS_CACHEDIR:=--cachedir=$PWD/xbps-cache/${XBPS_TARGET_ARCH}}"
- }
- rk33xx_flash_uboot() {
- local dir="$1"
- local dev="$2"
- dd if="${dir}/idbloader.img" of="${dev}" seek=64 conv=notrunc,fsync >/dev/null 2>&1
- dd if="${dir}/u-boot.itb" of="${dev}" seek=16384 conv=notrunc,fsync >/dev/null 2>&1
- }
- : "${XBPS_REPOSITORY:=--repository=https://repo-default.voidlinux.org/current \
- --repository=https://repo-default.voidlinux.org/current/musl \
- --repository=https://repo-default.voidlinux.org/current/aarch64}"
- case "${1:-}" in
- platform2arch)
- PLATFORM=$2
- set_target_arch_from_platform
- echo "$XBPS_TARGET_ARCH"
- ;;
- esac
|