Patchwork [1/4] qemuwrapper: use fallback in case the ELF binary is wrong

login
register
mail settings
Submitter Laurentiu Palcu
Date April 25, 2013, 12:23 p.m.
Message ID <dccffc726b66602d91dbd264542fda8b863b06d6.1366892003.git.laurentiu.palcu@intel.com>
Download mbox | patch
Permalink /patch/48883/
State Accepted
Commit fe240006fb79a704a27d9a5fbb7a41da9968476d
Headers show

Comments

Laurentiu Palcu - April 25, 2013, 12:23 p.m.
This wrapper script is called mainly from intercept hooks and allarch
packages postinstalls. When multilib is used, the qemuwrapper script
points to the binary that matches the MACHINE architecture.

For example: if MACHINE=qemux86_64 and we activate multilib, then the
postinstalls for lib32 packages would call qemu-x86_64 with 32 bit
binaries and they would certainly fail.

This patch adds just a fallback method if the exit code of the previous
qemu call corresponds to "Invalid ELF image for this architecture"
error. This will allow us to have all postinstalls run on host.

Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
---
 .../recipes-devtools/qemu/qemuwrapper-cross_1.0.bb |   28 +++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

Patch

diff --git a/meta/recipes-devtools/qemu/qemuwrapper-cross_1.0.bb b/meta/recipes-devtools/qemu/qemuwrapper-cross_1.0.bb
index 41617a6..18f1892 100644
--- a/meta/recipes-devtools/qemu/qemuwrapper-cross_1.0.bb
+++ b/meta/recipes-devtools/qemu/qemuwrapper-cross_1.0.bb
@@ -9,7 +9,33 @@  do_install () {
 	install -d ${D}${bindir_crossscripts}/
 
 	echo "#!/bin/sh" > ${D}${bindir_crossscripts}/qemuwrapper
-	echo exec env ${@qemu_target_binary(d)} \"\$@\" >> ${D}${bindir_crossscripts}/qemuwrapper
+	qemu_binary=${@qemu_target_binary(d)}
+	echo "$qemu_binary \"\$@\"" >> ${D}${bindir_crossscripts}/qemuwrapper
+	fallback_qemu_bin=
+	case $qemu_binary in
+		"qemu-i386")
+			fallback_qemu_bin=qemu-x86_64
+			;;
+		"qemu-x86_64")
+			fallback_qemu_bin=qemu-i386
+			;;
+		*)
+			;;
+	esac
+
+	if [ -n "$fallback_qemu_bin" ]; then
+
+		cat >> ${D}${bindir_crossscripts}/qemuwrapper << EOF
+rc=\$?
+if [ \$rc = 255 ]; then
+	$fallback_qemu_bin "\$@"
+	rc=\$?
+fi
+exit \$rc
+EOF
+
+	fi
+
 	chmod +x ${D}${bindir_crossscripts}/qemuwrapper
 }