[meta-amd] [meta-seattle][PATCHv4 2/4] support to run 32b applications

Adrian Calianu adrian.calianu at enea.com
Wed Feb 17 06:47:50 PST 2016


Since MULTILIB is not yet available for aarch64
add two solutions to run 32b application on aarch64.

One solution is using chroot while other requires qemu-arm.

Signed-off-by: Adrian Calianu <adrian.calianu at enea.com>
---
 meta-seattle/README                                |  56 ++++++++++
 .../recipes-support/32b-env/32b-env_1.0.bb         |  25 +++++
 .../32b-env/files/set_32b_env_chroot.sh            | 120 +++++++++++++++++++++
 .../32b-env/files/set_32b_env_qemu.sh              | 113 +++++++++++++++++++
 4 files changed, 314 insertions(+)
 create mode 100644 meta-seattle/recipes-support/32b-env/32b-env_1.0.bb
 create mode 100755 meta-seattle/recipes-support/32b-env/files/set_32b_env_chroot.sh
 create mode 100755 meta-seattle/recipes-support/32b-env/files/set_32b_env_qemu.sh

diff --git a/meta-seattle/README b/meta-seattle/README
index 0454cd5..0792570 100644
--- a/meta-seattle/README
+++ b/meta-seattle/README
@@ -112,3 +112,59 @@ Shell> FS0:\Image root=/dev/sda<X> rw console=ttyAMA0,115200n8
 References:
 1) https://www.kernel.org/doc/Documentation/efi-stub.txt
 2) http://www.uefi.org/specifications
+
+III. How to Run 32-bit Applications on aarch64
+==============================================
+
+Since multilib is not yet available for aarch64, this BSP offers some alternatives
+in order to run 32-bit legacy applications on an aarch64.
+
+Each method that helps to setup the environment to run 32-bit applications requires
+a few extra tools. Two of those metods are described in this section, one requiring
+chroot and another one qemu installation.
+
+meta-seattle BSP includes two scripts that help you to setup environment for 32bit
+applications that can be found under following path meta-seattle/recipes-support/32b-env/
+
+III.1 Using chroot tool to run 32-bit applications on aarch64
+=============================================================
+
+This solution requires the chroot tool on the target, a 32b-built rootfs, and
+a build for the seattle machine.
+
+root at seattle:~# scp <user>@<host_ip>:/homes/rootfs32b.tar.gz ./
+
+root at seattle:~# tar -zxf rootfs32.tar.gz
+
+root at seattle:~# set_32b_env_chroot.sh -r ./rootfs32
+
+# 32b environment started
+ at seattle:~# ./hello32d
+
+Starting from this point, any 32-bit application can be executed, but not 64-bit
+applications which will fail due to wrong path to 32-bit libraries. To run a 64-bit
+application, chroot mode must be quit by using the "exit" command.
+
+III.2 Using qemu to run 32-bit applications on aarch64
+======================================================
+
+This example requires an existing 32b-built rootfs and a build for the seattle machine.
+It is also expected that qemu-arm is already installed!!!
+
+root at seattle:~# scp <user>@<host_ip>:/homes/rootfs32b.tar.gz ./
+
+root at seattle:~# source /usr/bin/set_32b_env_qemu.sh -r ./rootfs32
+
+Starting from this point, any 32-bit or 64-bit application can be executed.
+
+IV. Limitations
+===============
+In order to enable 32-bit support in the aarch64 kernel, COMPAT mode is enabled
+(CONFIG_COMPAT=y), page size set to 4K, and VirtualAddress set to 48-bit.
+
+It might be possible to use 64K page sizes and 42-bit VirtualAddress if it is possible
+to rebuild the 32-bit application using binutils version 2.25.
+
+If 32-bit support is not required, COMPAT mode can be disabled (CONFIG_COMPAT=n) and
+page sizes set to 64K and VirtualAddress to 42-bit. Any change of the kernel
+confguration requires of course a kernel rebuild.
diff --git a/meta-seattle/recipes-support/32b-env/32b-env_1.0.bb b/meta-seattle/recipes-support/32b-env/32b-env_1.0.bb
new file mode 100644
index 0000000..e518b2a
--- /dev/null
+++ b/meta-seattle/recipes-support/32b-env/32b-env_1.0.bb
@@ -0,0 +1,25 @@
+SUMMARY = "A simple set of shell scripts used for enabling support for \
+dynamic linked 32b application on AMD Seattle."
+DESCRIPTION = "The 32b-env package installs the set_32b_env_chroot.sh \
+and set_32b_env_qemu.sh shell scripts which enables support for dynamic \
+linked 32b application on Seattle until the multilib support \
+will be available for armv8 architecture."
+
+SRC_URI = "file://set_32b_env_chroot.sh \
+           file://set_32b_env_qemu.sh"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690"
+
+inherit allarch
+
+do_install () {
+    install -d ${D}${bindir}/
+    install -m 755 ${WORKDIR}/set_32b_env_chroot.sh ${D}${bindir}/
+    install -m 755 ${WORKDIR}/set_32b_env_qemu.sh ${D}${bindir}/
+}
+
+do_patch[noexec] = "1"
+do_configure[noexec] = "1"
+do_compile[noexec] = "1"
+do_build[noexec] = "1"
diff --git a/meta-seattle/recipes-support/32b-env/files/set_32b_env_chroot.sh b/meta-seattle/recipes-support/32b-env/files/set_32b_env_chroot.sh
new file mode 100755
index 0000000..499b580
--- /dev/null
+++ b/meta-seattle/recipes-support/32b-env/files/set_32b_env_chroot.sh
@@ -0,0 +1,120 @@
+#!/bin/sh
+
+help()
+{
+    echo " The scope of this script is to setup an environment for 32b legacy applications."
+    echo " This is a replacement for MULTILIB mechanism which is not available yet for aarch64."
+    echo " chroot is used to setup an isolated environment for 32b applications"
+    echo "                                                                                      "
+    echo " Prerequisites:"
+    echo "    - user must build a 32b amrv7 rootfs (e.q. build a image for qemuarm)"
+    echo "    - user must copy 32b armv7 rootfs under 64b rootfs (e.q. /mnt/rootfs32)"
+    echo "    - user must copy 32b application under 32b rootfs (e.q. /mnt/rootfs32/myapp)"
+    echo ""
+    echo " Run setup script to prepare the environment for 32b applications"
+    echo "    > set_32b_env_chroot -r /mnt/rootfs32"
+    echo ""
+    echo " Run 32b applications"
+    echo "    @> ./myapp/myexec"
+    echo ""
+    echo " In order to return to default root just type <exit>"
+    echo "    @> exit"
+    exit
+}
+
+usage()
+{
+    echo "set_32b_env_chroot OPTIONS"
+    echo "OPTIONS:"
+    echo ""
+    echo "     -r <32b_rootfs> : path to a 32b rootfs."
+    echo "     -h              : display help"
+    echo ""
+    exit
+}
+
+if [[ $# -eq 0 ]] ; then
+    echo "[ERR]: Missing script parameters!"
+    echo ""
+    usage
+fi
+
+while getopts "hr:" OPTION;
+do
+        case $OPTION in
+
+                r)
+                        ROOTFS32b_PATH="$OPTARG"
+                        ;;
+
+                ?)
+                        help
+                        ;;
+
+        esac
+done
+
+ABS_PATH=`cd "${ROOTFS32b_PATH}"; pwd`
+ROOTFS32b_PATH=${ABS_PATH}
+
+if [[ ! -d ${ROOTFS32b_PATH} ]] ; then
+    usage
+fi
+
+if [[ ! -d ${ROOTFS32b_PATH}/dev ]] ; then
+    mkdir ${ROOTFS32b_PATH}/dev
+fi
+
+if [[ ! -d ${ROOTFS32b_PATH}/proc ]] ; then
+    mkdir ${ROOTFS32b_PATH}/proc
+fi
+
+if [[ ! -d ${ROOTFS32b_PATH}/sys ]] ; then
+    mkdir ${ROOTFS32b_PATH}/sys
+fi
+
+if [[ ! -d ${ROOTFS32b_PATH}/etc ]] ; then
+    mkdir ${ROOTFS32b_PATH}/etc
+fi
+
+umount ${ROOTFS32b_PATH}/dev/pts 2>/dev/null
+umount ${ROOTFS32b_PATH}/dev 2>/dev/null
+mount --bind /dev ${ROOTFS32b_PATH}/dev
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to mount /dev folder"
+    exit
+fi
+
+umount ${ROOTFS32b_PATH}/proc 2>/dev/null
+mount --bind /proc ${ROOTFS32b_PATH}/proc
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to mount /proc folder"
+    exit
+fi
+
+umount ${ROOTFS32b_PATH}/sys 2>/dev/null
+mount --bind /sys ${ROOTFS32b_PATH}/sys
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to mount /sys folder"
+    exit
+fi
+
+mount --bind /dev/pts ${ROOTFS32b_PATH}/dev/pts
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to mount /dev/pts folder"
+    exit
+fi
+
+cp /etc/resolv.conf ${ROOTFS32b_PATH}/etc/resolv.conf
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to copy resolv.conf file"
+    exit
+fi
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+
+echo "New root will be ${ROOTFS32b_PATH}/   type \"exit\" to return to /"
+chroot ${ROOTFS32b_PATH}/ /bin/sh
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to start chroot!"
+fi
diff --git a/meta-seattle/recipes-support/32b-env/files/set_32b_env_qemu.sh b/meta-seattle/recipes-support/32b-env/files/set_32b_env_qemu.sh
new file mode 100755
index 0000000..3a16502
--- /dev/null
+++ b/meta-seattle/recipes-support/32b-env/files/set_32b_env_qemu.sh
@@ -0,0 +1,113 @@
+#!/bin/sh
+
+help()
+{
+    echo " The scope of this script is to setup an environment for 32b legacy applications."
+    echo " This is a replacement for MULTILIB mechanism which is not available yet for aarch64."
+    echo " qemu-arm(user mode) is used to set access to 32b libraries instead of the host's libs"
+    echo "                                                                                      "
+    echo " Prerequisites:"
+    echo "    - user must build a 32b amrv7 rootfs (e.q. build a image for qemuarm)"
+    echo "    - user must copy 32b armv7 rootfs under 64b rootfs (e.q. /mnt/rootfs32)"
+    echo "    - user must copy 32b application under 32b rootfs (e.q. /mnt/rootfs32/myapp)"
+    echo "    - user must configure properly the smart package manager in order to access"
+    echo "                <qemu-arm> and <kernel-module-binfmt-misc> packages otherwise it is"
+    echo "                expected that those packages are already installed"
+    echo ""
+    echo " Run setup script to prepare the environment for 32b applications( -l param is optional )"
+    echo "    > set_32b_env_qemu -r /mnt/rootfs32 -l /usr/local/extlib:/usr/local/mylib"
+    echo ""
+    echo " After that user should be able to run any 32b application as usual!"
+    echo "    >./myapp"
+    break
+}
+
+usage()
+{
+    echo "Setup environment to run 32b dynamically linked applications using qemu."
+    echo "Prerequisites:"
+    echo "   It is expected that qemu and kernel-module-binfmt-misc packages are installed"
+    echo "   It is expected that 32bit rootfs is already installed!"
+    echo ""
+    echo "set_32b_env_qemu -r <path to 32b rootfs> -l <ext_libs1:ext_libs2:...>"
+    echo " -r : [mandatory] path to 32b rootfs"
+    echo " -l : [optional]  list of paths for nonstandard lib folders, paths must be relative to 32b rootfs"
+    echo " -h : [optional]  display help"
+    echo ""
+    echo "Example: set_32b_env_qemu -r ./rootfs32b -l /usr/local/mylib:/usr/local/mylib2"
+    break
+}
+
+if [[ $# -eq 0 ]] ; then
+    echo "[ERR]: Missing script parameters!"
+    echo ""
+    usage
+fi
+
+while getopts "hr:l:" OPTION;
+do
+        case $OPTION in
+
+                r)
+                        ROOTFS32b_PATH="$OPTARG"
+                        ;;
+
+                l)
+                        LIBS_PATH="$OPTARG"
+                        ;;
+
+                h)
+                        usage
+                        ;;
+
+                ?)
+                        help
+                        ;;
+
+        esac
+done
+
+ABS_PATH=`cd "${ROOTFS32b_PATH}"; pwd`
+ROOTFS32b_PATH=${ABS_PATH}
+
+if [[ ! -d ${ROOTFS32b_PATH} ]] ; then
+    usage
+fi
+
+echo "Please wait..."
+echo ""
+QEMU_EXISTS=`which qemu-arm`
+if [[ "${QEMU_EXISTS}" == "" ]] ; then
+    echo "Please make sure smart package manager is configured !"
+    echo "Otherwise make sure <qemu> and <kernel-module-binfmt-misc> are installed!"
+    smart --quiet update
+    smart --quiet install qemu
+    smart --quiet install kernel-module-binfmt-misc
+fi
+
+echo "."
+mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
+if [[ "$?" != "0" ]] ; then
+    echo "Failed to install binfmt_misc or the setup was already prepared for 32b"
+    echo ""
+    echo "Please, make sure the module is available into system"
+    echo "How to install the binfmt_misc package:"
+    echo "         smart install binfmt_misc"
+    break
+fi
+
+BINFMT_INSTALLED=`cat /proc/sys/fs/binfmt_misc/status`
+if [[ "${BINFMT_INSTALLED}" != "enabled" ]] ; then
+    echo "binfmt_misc not enabled!!"
+    break
+fi
+
+echo ".."
+# configure qemu to run 32b armv7 applications
+echo ":arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm:" > /proc/sys/fs/binfmt_misc/register
+
+export QEMU_LD_PREFIX=${ROOTFS32b_PATH}
+export QEMU_SET_ENV="LD_LIBRARY_PATH=${LIBS_PATH}"
+
+echo "Done!"
+echo "Environment was set to run 32b applications!"
-- 
1.9.1



More information about the meta-amd mailing list