diff options
Diffstat (limited to 'recipes-support/32b-env/files/set_32b_env_qemu.sh')
-rwxr-xr-x | recipes-support/32b-env/files/set_32b_env_qemu.sh | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/recipes-support/32b-env/files/set_32b_env_qemu.sh b/recipes-support/32b-env/files/set_32b_env_qemu.sh new file mode 100755 index 0000000..e8c174d --- /dev/null +++ b/recipes-support/32b-env/files/set_32b_env_qemu.sh | |||
@@ -0,0 +1,113 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | help() | ||
4 | { | ||
5 | echo " The scope of this script is to setup an environment for 32b legacy applications." | ||
6 | echo " This is a replacement for MULTILIB mechanism which is not available yet for aarch64." | ||
7 | echo " qemu-arm(user mode) is used to set access to 32b libraries instead of the host's libs" | ||
8 | echo " " | ||
9 | echo " Prerequisites:" | ||
10 | echo " - user must build a 32b amrv7 rootfs (e.q. build a image for qemuarm)" | ||
11 | echo " - user must copy 32b armv7 rootfs under 64b rootfs (e.q. /mnt/rootfs32)" | ||
12 | echo " - user must copy 32b application under 32b rootfs (e.q. /mnt/rootfs32/myapp)" | ||
13 | echo " - user must configure properly the smart package manager in order to access" | ||
14 | echo " <qemu-arm> and <kernel-module-binfmt-misc> packages otherwise it is" | ||
15 | echo " expected that those packages are already installed" | ||
16 | echo "" | ||
17 | echo " Run setup script to prepare the environment for 32b applications( -l param is optional )" | ||
18 | echo " > set_32b_env_qemu -r /mnt/rootfs32 -l /usr/local/extlib:/usr/local/mylib" | ||
19 | echo "" | ||
20 | echo " After that user should be able to run any 32b application as usual!" | ||
21 | echo " >./myapp" | ||
22 | break | ||
23 | } | ||
24 | |||
25 | usage() | ||
26 | { | ||
27 | echo "Setup environment to run 32b dynamically linked applications using qemu." | ||
28 | echo "Prerequisites:" | ||
29 | echo " It is expected that qemu and kernel-module-binfmt-misc packages are installed" | ||
30 | echo " It is expected that 32bit rootfs is already installed!" | ||
31 | echo "" | ||
32 | echo "set_32b_env_qemu -r <path to 32b rootfs> -l <ext_libs1:ext_libs2:...>" | ||
33 | echo " -r : [mandatory] path to 32b rootfs" | ||
34 | echo " -l : [optional] list of paths for nonstandard lib folders, paths must be relative to 32b rootfs" | ||
35 | echo " -h : [optional] display help" | ||
36 | echo "" | ||
37 | echo "Example: set_32b_env_qemu -r ./rootfs32b -l /usr/local/mylib:/usr/local/mylib2" | ||
38 | break | ||
39 | } | ||
40 | |||
41 | if [[ $# -eq 0 ]] ; then | ||
42 | echo "[ERR]: Missing script parameters!" | ||
43 | echo "" | ||
44 | usage | ||
45 | fi | ||
46 | |||
47 | while getopts "hr:l:" OPTION; | ||
48 | do | ||
49 | case $OPTION in | ||
50 | |||
51 | r) | ||
52 | ROOTFS32b_PATH="$OPTARG" | ||
53 | ;; | ||
54 | |||
55 | l) | ||
56 | LIBS_PATH="$OPTARG" | ||
57 | ;; | ||
58 | |||
59 | h) | ||
60 | usage | ||
61 | ;; | ||
62 | |||
63 | ?) | ||
64 | help | ||
65 | ;; | ||
66 | |||
67 | esac | ||
68 | done | ||
69 | |||
70 | ABS_PATH=`cd "${ROOTFS32b_PATH}"; pwd` | ||
71 | ROOTFS32b_PATH=${ABS_PATH} | ||
72 | |||
73 | if [[ ! -d ${ROOTFS32b_PATH} ]] ; then | ||
74 | usage | ||
75 | fi | ||
76 | |||
77 | echo "Please wait..." | ||
78 | echo "" | ||
79 | QEMU_EXISTS=`which qemu-arm` | ||
80 | if [[ "${QEMU_EXISTS}" == "" ]] ; then | ||
81 | echo "Please make sure smart package manager is configured !" | ||
82 | echo "Otherwise make sure <qemu> and <kernel-module-binfmt-misc> are installed!" | ||
83 | smart --quiet update | ||
84 | smart --quiet install qemu | ||
85 | smart --quiet install kernel-module-binfmt-misc | ||
86 | fi | ||
87 | |||
88 | echo "." | ||
89 | mount -t binfmt_misc none /proc/sys/fs/binfmt_misc | ||
90 | if [[ "$?" != "0" ]] ; then | ||
91 | echo "Failed to install binfmt_misc or the setup was already prepared for 32b" | ||
92 | echo "" | ||
93 | echo "Please, make sure the module is available into system" | ||
94 | echo "How to install the binfmt_misc package:" | ||
95 | echo " smart install binfmt_misc" | ||
96 | break | ||
97 | fi | ||
98 | |||
99 | BINFMT_INSTALLED=`cat /proc/sys/fs/binfmt_misc/status` | ||
100 | if [[ "${BINFMT_INSTALLED}" != "enabled" ]] ; then | ||
101 | echo "binfmt_misc not enabled!!" | ||
102 | break | ||
103 | fi | ||
104 | |||
105 | echo ".." | ||
106 | # configure qemu to run 32b armv7 applications | ||
107 | 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 | ||
108 | |||
109 | export QEMU_LD_PREFIX=${ROOTFS32b_PATH} | ||
110 | export QEMU_SET_ENV="LD_LIBRARY_PATH=${LIBS_PATH}" | ||
111 | |||
112 | echo "Done!" | ||
113 | echo "Environment was set to run 32b applications!" | ||