aboutsummaryrefslogtreecommitdiffstats
path: root/meta-seattle/recipes-support/32b-env/files/set_32b_env_qemu.sh
blob: 3a165025a4554b661eb2b0764bfd3d58875aa190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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!"