Skip to contentSkip to conversation

qemu: add host/target Linux version check

PATCH New Frank Hunleth 3 participants 4 messages Feb 8, 2014 – Feb 11, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu: add host/target Linux version check

Raise an error if the host is using an older kernel than the target. Since qemu-user passes emulated system calls to the host kernel, this prevents usage of qemu-user in situations where those system calls will fail.

---
 package/qemu/qemu.mk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
package/qemu/qemu.mk +18 -0
index 093ae64..bd6f555 100644
@@ -74,6 +74,24 @@ define HOST_QEMU_CONFIGURE_CMDS
 	)
 endef
 
+define HOST_QEMU_LINUX_VERSION_CHECK
+	host_version_parts=`uname -r | sed 's/\-.*//g' | sed 's/\./ /g'` ;\
+	host_version_code=0 ;\
+	multiplier=65536 ;\
+	for host_version_part in $$host_version_parts; do \
+		host_version_code=`echo "$$host_version_code + $$host_version_part * $$multiplier" | bc` ;\
+		multiplier=`echo "$$multiplier / 256" | bc` ;\
+	done ;\
+	target_version_code=`grep LINUX_VERSION_CODE $(STAGING_DIR)/usr/include/linux/version.h | awk '{print $$3}'` ;\
+	if test $$host_version_code -lt $$target_version_code ; then \
+		echo "Refusing to install qemu-user since the target Linux version is newer" ;\
+		echo "than the host's. Missing system calls will fail." ;\
+		exit 1 ;\
+	fi
+endef
+
+HOST_QEMU_POST_BUILD_HOOKS += HOST_QEMU_LINUX_VERSION_CHECK
+
 $(eval $(host-autotools-package))
 
 # variable used by other packages
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/1 qemu: add host/target Linux version check

Quoted 6 lines · Frank Hunleth

Raise an error if the host is using an older kernel than the target. Since qemu-user passes emulated system calls to the host kernel, this prevents usage of qemu-user in situations where those system calls will fail.

Thanks Frank!

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 77

Quoted 13 lines
---
 package/qemu/qemu.mk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
package/qemu/qemu.mk +1 -0
index 093ae64..bd6f555 100644
@@ -74,6 +74,24 @@ define HOST_QEMU_CONFIGURE_CMDS
 	)
 endef
 
+define HOST_QEMU_LINUX_VERSION_CHECK

Just to be sure, I'd start with a

test uname -s = Linux

(some people try to run buildroot on *BSDs, with varying degrees of success).

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 83

Quoted 6 lines
package/qemu/qemu.mk +6 -0
+	host_version_parts=`uname -r | sed 's/\-.*//g' | sed 's/\./ /g'` ;\
+	host_version_code=0 ;\
+	multiplier=65536 ;\
+	for host_version_part in $$host_version_parts; do \
+		host_version_code=`echo "$$host_version_code + $$host_version_part * $$multiplier" | bc` ;\
+		multiplier=`echo "$$multiplier / 256" | bc` ;\

Even though we do put bc in our dependencies, I'd prefer to avoid
relying on it - not many people know it. Instead, I'd use either bash's let builtin, or POSIX-compliant expr.

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 85

Quoted 2 lines
package/qemu/qemu.mk +2 -0
+	done ;\
+	target_version_code=`grep LINUX_VERSION_CODE $(STAGING_DIR)/usr/include/linux/version.h | awk '{print $$3}'` ;\

You can do the grep inside the awk:

awk '/LINUX_VERSION_CODE/ {print $$3}' .../version.h

Since it is possible to build host-qemu without building anything for
the target, you can't rely on version.h being present already. To make sure it is there, add toolchain to the HOST_QEMU_DEPENDENCIES.

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 93

Quoted 8 lines
package/qemu/qemu.mk +8 -0
+	if test $$host_version_code -lt $$target_version_code ; then \
+		echo "Refusing to install qemu-user since the target Linux version is newer" ;\
+		echo "than the host's. Missing system calls will fail." ;\
+		exit 1 ;\
+	fi
+endef
+
+HOST_QEMU_POST_BUILD_HOOKS += HOST_QEMU_LINUX_VERSION_CHECK

I think a pre-configure hook is more appropriate.

Regards,
Arnout

Quoted 5 lines
package/qemu/qemu.mk +1 -0
+
 $(eval $(host-autotools-package))
 
 # variable used by other packages
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#2 lore raw

PATCH 1/1 qemu: add host/target Linux version check

Arnout, Frank, All,

On 2014-02-10 18:06 +0100, Arnout Vandecappelle spake thusly:

Quoted 1 line · Frank Hunleth

[--SNIP--]

Quoted 10 lines

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 83

Quoted 6 lines
package/qemu/qemu.mk +6 -0
+	host_version_parts=`uname -r | sed 's/\-.*//g' | sed 's/\./ /g'` ;\
+	host_version_code=0 ;\
+	multiplier=65536 ;\
+	for host_version_part in $$host_version_parts; do \
+		host_version_code=`echo "$$host_version_code + $$host_version_part * $$multiplier" | bc` ;\
+		multiplier=`echo "$$multiplier / 256" | bc` ;\

Even though we do put bc in our dependencies, I'd prefer to avoid
relying on it - not many people know it. Instead, I'd use either bash's let builtin, or POSIX-compliant expr.

POSIX defines (basic) mathematical expressions, eg:
multiplier=$((multiplier/256))

See: The Open Group Base Specifications Issue 7, Shell Command Language:

    http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04
Quoted 10 lines

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 93

Quoted 8 lines
package/qemu/qemu.mk +8 -0
+	if test $$host_version_code -lt $$target_version_code ; then \
+		echo "Refusing to install qemu-user since the target Linux version is newer" ;\
+		echo "than the host's. Missing system calls will fail." ;\
+		exit 1 ;\
+	fi
+endef
+
+HOST_QEMU_POST_BUILD_HOOKS += HOST_QEMU_LINUX_VERSION_CHECK

I think a pre-configure hook is more appropriate.

Indeed.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH 1/1 qemu: add host/target Linux version check

Quoted 16 lines · Yann E. MORIN

Arnout, Frank, All,

On 2014-02-10 18:06 +0100, Arnout Vandecappelle spake thusly:

Quoted 1 line · Frank Hunleth

[--SNIP--]

Quoted 10 lines

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 83

Quoted 6 lines
package/qemu/qemu.mk +6 -0
+   host_version_parts=`uname -r | sed 's/\-.*//g' | sed 's/\./ /g'` ;\
+   host_version_code=0 ;\
+   multiplier=65536 ;\
+   for host_version_part in $$host_version_parts; do \
+           host_version_code=`echo "$$host_version_code + $$host_version_part * $$multiplier" | bc` ;\
+           multiplier=`echo "$$multiplier / 256" | bc` ;\

Even though we do put bc in our dependencies, I'd prefer to avoid
relying on it - not many people know it. Instead, I'd use either bash's let builtin, or POSIX-compliant expr.

Quoted 5 lines

POSIX defines (basic) mathematical expressions, eg:
multiplier=$((multiplier/256))

See: The Open Group Base Specifications Issue 7, Shell Command Language:

    http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04

Thanks Arnout and Yann - I always learn something when I submit a patch to this project.

Revised patch coming shortly...

Quoted 24 lines
Quoted 11 lines

package/qemu/qemu.mk define HOST_QEMU_CONFIGURE_CMDS · line 93

Quoted 9 lines
package/qemu/qemu.mk +8 -0
+   if test $$host_version_code -lt $$target_version_code ; then \
+           echo "Refusing to install qemu-user since the target Linux version is newer" ;\
+           echo "than the host's. Missing system calls will fail." ;\
+           exit 1 ;\
+   fi
+endef
+
+HOST_QEMU_POST_BUILD_HOOKS += HOST_QEMU_LINUX_VERSION_CHECK

I think a pre-configure hook is more appropriate.

Indeed.

Regards,
Yann E. MORIN.

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'

Signature · 4 lines
Frank Hunleth
Troodon Software LLC
Embedded Software Development
http://troodon-software.com/