Make poky-qemu and related scripts work with arbitrary SDK locations
cover Make poky-qemu and related scripts work with arbitrary SDK locations
Hi Saul,
This commit needs to precede a merge of Josh's work to add a version directory to SDK toolchain installations. It eliminates all assumptions that toolchains are installed in /opt/poky and allows for arbitrary toolchain location locations.
It also fixes a bug I ran across when paths to both the kernel and filesystem image are specified, leading to POKY_NATIVE_SYSROOT not being set, which causes poky-qemu-ifup/ifdown to fail. [BUGFIX #568]
Pull URL: git://git.pokylinux.org/poky-contrib.git
Branch: sgarman/poky-qemu-changes
Browse: http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=sgarman/poky-qemu-changes
Thanks,
Scott Garman <[email protected]>
---
Scott Garman (1):
Make poky-qemu and related scripts work with arbitrary SDK locations
scripts/poky-find-native-sysroot | 2 +- scripts/poky-qemu | 38 ++++++++++++++++++++++---------------- scripts/poky-qemu-ifdown | 9 +-------- scripts/poky-qemu-ifup | 9 +-------- scripts/poky-qemu-internal | 16 +--------------- 5 files changed, 26 insertions(+), 48 deletions(-)
PATCH 1/1 Make poky-qemu and related scripts work with arbitrary SDK locations
* No longer assume SDK toolchains are installed in /opt/poky
* [BUGFIX #568] where specifying paths to both the kernel and fs image caused an error due to POKY_NATIVE_SYSROOT never being set, triggering failure of poky-qemu-ifup/ifdown
* Cosmetic improvements to usage() functions by using basename
--- scripts/poky-find-native-sysroot | 2 +- scripts/poky-qemu | 38 ++++++++++++++++++++++---------------- scripts/poky-qemu-ifdown | 9 +-------- scripts/poky-qemu-ifup | 9 +-------- scripts/poky-qemu-internal | 16 +--------------- 5 files changed, 26 insertions(+), 48 deletions(-)
scripts/poky-find-native-sysroot +1 -1
@@ -1,7 +1,7 @@ #!/bin/bash # # Find a native sysroot to use - either from an in-tree Poky build or -# from a toolchain installation in /opt/poky. It then ensures the variable +# from a toolchain installation. It then ensures the variable # $POKY_NATIVE_SYSROOT is set to the sysroot's base directory, and sets # $PSEUDO to the path of the pseudo binary. #
scripts/poky-qemu +22 -16
@@ -31,9 +31,9 @@ usage() { echo " serial - enables a serial console on /dev/ttyS0" echo "" echo "Examples:" - echo " $0 qemuarm" - echo " $0 qemux86-64 poky-image-sato ext3" - echo " $0 path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" + echo " $MYNAME qemuarm" + echo " $MYNAME qemux86-64 poky-image-sato ext3" + echo " $MYNAME path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" exit 1 }
@@ -213,23 +213,29 @@ setup_tmpdir() { echo "before running this script" >&2; exit 1; } - # We have bitbake in PATH, get TMPDIR and BUILD_SYS - # from the environment + # We have bitbake in PATH, get TMPDIR from bitbake TMPDIR=`bitbake -e | grep TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2` - BUILD_SYS=`bitbake -e | grep BUILD_SYS=\" | cut -d '=' -f2 | cut -d '"' -f2` else - BUILD_ARCH=`uname -m` - BUILD_OS=`uname | tr '[A-Z]' '[a-z]'` - BUILD_SYS="$BUILD_ARCH-$BUILD_OS" TMPDIR=$BUILDDIR/tmp fi - if [ -z "$POKY_NATIVE_SYSROOT" ]; then - POKY_NATIVE_SYSROOT=$TMPDIR/sysroots/$BUILD_SYS - fi - CROSSPATH=$POKY_NATIVE_SYSROOT/usr/bin fi } +setup_sysroot() { + # Toolchain installs set up $POKY_NATIVE_SYSROOT in their + # environment script. If that variable isn't set, we're + # either in an in-tree poky scenario or the environment + # script wasn't source'd. + if [ -z "$POKY_NATIVE_SYSROOT" ]; then + setup_tmpdir + BUILD_ARCH=`uname -m` + BUILD_OS=`uname | tr '[A-Z]' '[a-z]'` + BUILD_SYS="$BUILD_ARCH-$BUILD_OS" + + POKY_NATIVE_SYSROOT=$TMPDIR/sysroots/$BUILD_SYS + fi +} + # Locate a rootfs image based on defaults defined above findimage() { where=$1
@@ -254,8 +260,6 @@ findimage() { } if [[ -e "$ROOTFS" && -z "$FSTYPE" ]]; then - setup_tmpdir - # Extract the filename extension EXT=`echo $ROOTFS | awk -F . '{ print \$NF }'` if [[ "x$EXT" == "xext2" || "x$EXT" == "xext3" ||
@@ -281,7 +285,6 @@ fi # KERNEL is now set for all cases if [ -z "$FSTYPE" ]; then - setup_tmpdir eval FSTYPE=\$${machine2}_DEFAULT_FSTYPE if [ -z "$FSTYPE" ]; then
@@ -318,6 +321,9 @@ echo "KERNEL: [$KERNEL]" echo "ROOTFS: [$ROOTFS]" echo "FSTYPE: [$FSTYPE]" +setup_sysroot +# POKY_NATIVE_SYSROOT is now set for all cases + # We can't run without a libGL.so libgl='no'
scripts/poky-qemu-ifdown +1 -8
@@ -27,7 +27,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. usage() { - echo "sudo $0 <tap-dev> <native-sysroot-basedir>" + echo "sudo $(basename $0) <tap-dev> <native-sysroot-basedir>" } if [ $EUID -ne 0 ]; then
@@ -46,13 +46,6 @@ NATIVE_SYSROOT_DIR=$2 TUNCTL=$NATIVE_SYSROOT_DIR/usr/bin/tunctl if [ ! -e "$TUNCTL" ]; then echo "Error: Unable to find tunctl binary in '$NATIVE_SYSROOT_DIR/usr/bin'" - - if [[ "$NATIVE_SYSROOT_DIR" =~ ^\/opt\/poky ]]; then - echo "This shouldn't happen - something is wrong with your toolchain installation" - else - echo "Have you run 'bitbake meta-ide-support'?" - fi - exit 1 fi
scripts/poky-qemu-ifup +1 -8
@@ -34,7 +34,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. usage() { - echo "sudo $0 <gid> <native-sysroot-basedir>" + echo "sudo $(basename $0) <gid> <native-sysroot-basedir>" } if [ $EUID -ne 0 ]; then
@@ -53,13 +53,6 @@ NATIVE_SYSROOT_DIR=$2 TUNCTL=$NATIVE_SYSROOT_DIR/usr/bin/tunctl if [ ! -x "$TUNCTL" ]; then echo "Error: Unable to find tunctl binary in '$NATIVE_SYSROOT_DIR/usr/bin'" - - if [[ "$NATIVE_SYSROOT_DIR" =~ ^\/opt\/poky ]]; then - echo "This shouldn't happen - something is wrong with your toolchain installation" - else - echo "Have you run 'bitbake meta-ide-support'?" - fi - exit 1 fi
scripts/poky-qemu-internal +1 -15
@@ -394,23 +394,9 @@ if [ "x$QEMUOPTIONS" = "x" ]; then return fi -SDKDIR="/opt/poky/sysroots" -if [ "$MACHINE" = "qemuarm" -o "$MACHINE" = "spitz" -o "$MACHINE" = "borzoi" -o "$MACHINE" = "akita" -o "$MACHINE" = "nokia800" ]; then - SDKPATH="$SDKDIR/arm-poky-linux-gnueabi/bin" -fi - -if [ "$MACHINE" = "qemux86" ]; then - SDKPATH="$SDKDIR/i586-poky-linux/bin" -fi - -if [ "$MACHINE" = "qemux86-64" ]; then - SDKPATH="$SDKDIR/x86_64-poky-linux/bin" -fi - -PATH=$CROSSPATH:$SDKPATH:$PATH +PATH=$CROSSPATH:$POKY_NATIVE_SYSROOT/usr/bin:$PATH QEMUBIN=`which $QEMU` - if [ ! -x "$QEMUBIN" ]; then echo "Error: No QEMU binary '$QEMU' could be found." cleanup
Signature · 1 line
1.7.1
Quoted 32 lines · Scott Garman
scripts/poky-find-native-sysroot +0
-0scripts/poky-qemu +4
-7@@ -31,9 +31,9 @@ usage() { echo " serial - enables a serial console on /dev/ttyS0" echo "" echo "Examples:" - echo " $0 qemuarm" - echo " $0 qemux86-64 poky-image-sato ext3" - echo " $0 path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" + echo " $MYNAME qemuarm" + echo " $MYNAME qemux86-64 poky-image-sato ext3" + echo " $MYNAME path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" exit 1 }@@ -213,23 +213,29 @@ setup_tmpdir() { echo "before running this script" >&2; exit 1; } - # We have bitbake in PATH, get TMPDIR and BUILD_SYS - # from the environment + # We have bitbake in PATH, get TMPDIR from bitbake TMPDIR=`bitbake -e | grep TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2` - BUILD_SYS=`bitbake -e | grep BUILD_SYS=\" | cut -d '=' -f2 | cut -d '"' -f2` else - BUILD_ARCH=`uname -m`
scripts/poky-qemu setup_tmpdir() { · line 222
Quoted 10 lines
scripts/poky-qemu +0
-6- BUILD_OS=`uname | tr '[A-Z]' '[a-z]'` - BUILD_SYS="$BUILD_ARCH-$BUILD_OS" TMPDIR=$BUILDDIR/tmp fi - if [ -z "$POKY_NATIVE_SYSROOT" ]; then - POKY_NATIVE_SYSROOT=$TMPDIR/sysroots/$BUILD_SYS - fi - CROSSPATH=$POKY_NATIVE_SYSROOT/usr/bin fi }
Hmm, you remove CROSSPATH yet still reference it later. I think the code has become confused. I'm going to merge the patch as it improves the situation compared to how it is at the moment. I'll give some background though:
There are three things we really want to reference in PATH:
a) The "native" or "nativesdk" tools
b) The "cross" tools, i.e. TARGET_PREFIX-gcc
c) The "cross" tools without the prefix, e.g. "gcc", replacing the usual gcc you'd find in PATH. This last part is to allow distcc in a image to use the compiler outside the emulation.
The distcc thing did used to work but I doubt it does at the moment as I think this has just been reduced to the native case accidentally.
The paths in the sysroot corresponding to these are:
/opt/poky/sysroots/HOST-pokysdk-linux/usr/bin /opt/poky/sysroots/HOST-pokysdk-linux/usr/bin/TARGET-poky-linux /opt/poky/sysroots/HOST-pokysdk-linux/usr/libexec/TARGET-poky-linux/gcc/TARGET-poky-linux/GCCVERSION/
and there are similar paths in a Poky build directory.
I hope that helps clear things up a bit.
Cheers,
Richard
Quoted 62 lines · Richard Purdie
Quoted 32 lines · Scott Garman
scripts/poky-find-native-sysroot +0
-0scripts/poky-qemu +4
-7@@ -31,9 +31,9 @@ usage() { echo " serial - enables a serial console on /dev/ttyS0" echo "" echo "Examples:" - echo " $0 qemuarm" - echo " $0 qemux86-64 poky-image-sato ext3" - echo " $0 path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" + echo " $MYNAME qemuarm" + echo " $MYNAME qemux86-64 poky-image-sato ext3" + echo " $MYNAME path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial" exit 1 }@@ -213,23 +213,29 @@ setup_tmpdir() { echo "before running this script">&2; exit 1; } - # We have bitbake in PATH, get TMPDIR and BUILD_SYS - # from the environment + # We have bitbake in PATH, get TMPDIR from bitbake TMPDIR=`bitbake -e | grep TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2` - BUILD_SYS=`bitbake -e | grep BUILD_SYS=\" | cut -d '=' -f2 | cut -d '"' -f2` else - BUILD_ARCH=`uname -m`scripts/poky-qemu setup_tmpdir() { · line 222
Quoted 10 lines
scripts/poky-qemu +0
-6- BUILD_OS=`uname | tr '[A-Z]' '[a-z]'` - BUILD_SYS="$BUILD_ARCH-$BUILD_OS" TMPDIR=$BUILDDIR/tmp fi - if [ -z "$POKY_NATIVE_SYSROOT" ]; then - POKY_NATIVE_SYSROOT=$TMPDIR/sysroots/$BUILD_SYS - fi - CROSSPATH=$POKY_NATIVE_SYSROOT/usr/bin fi }Hmm, you remove CROSSPATH yet still reference it later. I think the code has become confused. I'm going to merge the patch as it improves the situation compared to how it is at the moment. I'll give some background though:
There are three things we really want to reference in PATH:
a) The "native" or "nativesdk" tools
b) The "cross" tools, i.e. TARGET_PREFIX-gcc
c) The "cross" tools without the prefix, e.g. "gcc", replacing the usual gcc you'd find in PATH. This last part is to allow distcc in a image to use the compiler outside the emulation.The distcc thing did used to work but I doubt it does at the moment as I think this has just been reduced to the native case accidentally.
The paths in the sysroot corresponding to these are:
Quoted 7 lines
/opt/poky/sysroots/HOST-pokysdk-linux/usr/bin/opt/poky/sysroots/HOST-pokysdk-linux/usr/bin/TARGET-poky-linux/opt/poky/sysroots/HOST-pokysdk-linux/usr/libexec/TARGET-poky-linux/gcc/TARGET-poky-linux/GCCVERSION/and there are similar paths in a Poky build directory.
I hope that helps clear things up a bit.
Thanks Richard, that does clarify things. I will file a bug for this and address it soon.
Scott
Signature · 2 lines
Scott Garman Embedded Linux Distro Engineer - Yocto Project