Patchwork [fsl-community-bsp-platform] setup-environment: add options for the script

login
register
mail settings
Submitter Mahesh Mahadevan
Date May 18, 2013, 1:02 a.m.
Message ID <1368838974-13355-1-git-send-email-Mahesh.Mahadevan@freescale.com>
Download mbox | patch
Permalink /patch/50063/
State Changes Requested
Delegated to: Otavio Salvador
Headers show

Comments

Mahesh Mahadevan - May 18, 2013, 1:02 a.m.
From: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>

Add options to help specify the machine, below are the options added:
Usage: source ./setup-environment <-m machine>
    Optional parameters: [-j jobs] [-t tasks] [-h]

 Supported machines: imx23evk imx28evk imx31pdk imx35pdk imx51evk imx53ard imx53qsb imx6dlsabresd imx6qsabreauto imx6qsabresd imx6slevk
    * [-j jobs]: number of jobs for make to spawn during compile; default=4
    * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=4
    * [-b path]: non-default build dir location; default location is /home/r9aadq/yocto/build
    * [-h]: help

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
---
 setup-environment |   91 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 81 insertions(+), 10 deletions(-)
John Weber - May 18, 2013, 1:33 a.m.
Is it possible to also include machines in the other layers?   For example
meta-fsl-arm-extra?


On Friday, May 17, 2013, Mahesh Mahadevan wrote:

> From: Mahesh Mahadevan <mahesh.mahadevan@freescale.com <javascript:;>>
>
> Add options to help specify the machine, below are the options added:
> Usage: source ./setup-environment <-m machine>
>     Optional parameters: [-j jobs] [-t tasks] [-h]
>
>  Supported machines: imx23evk imx28evk imx31pdk imx35pdk imx51evk imx53ard
> imx53qsb imx6dlsabresd imx6qsabreauto imx6qsabresd imx6slevk
>     * [-j jobs]: number of jobs for make to spawn during compile; default=4
>     * [-t tasks]: number of bitbake tasks that can be issued in parallel;
> default=4
>     * [-b path]: non-default build dir location; default location is
> /home/r9aadq/yocto/build
>     * [-h]: help
>
> Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@freescale.com<javascript:;>
> >
> ---
>  setup-environment |   91
> +++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 81 insertions(+), 10 deletions(-)
>
> diff --git a/setup-environment b/setup-environment
> index 6aadbb4..96b1e26 100644
> --- a/setup-environment
> +++ b/setup-environment
> @@ -17,13 +17,88 @@
>  # with this program; if not, write to the Free Software Foundation, Inc.,
>  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>  #
> +# Add options for the script
> +# Copyright (C) 2013 Freescale Semiconductor, Inc.
> +
> +NCPU=`grep -c processor /proc/cpuinfo`
> +CWD=`pwd`
> +
> +usage()
> +{
> +    echo -e "\nUsage: source ${BASH_SOURCE[0]} <-m machine>
> +    Optional parameters: [-j jobs] [-t tasks] [-h]"
> +    echo -e -n "\n Supported machines: `ls
> $CWD/sources/meta-fsl-arm/conf/machine \
> +    | grep -v "^include" | sed s/\.conf//g | xargs echo`"
> +echo "
> +    * [-j jobs]: number of jobs for make to spawn during compile;
> default=$NCPU
> +    * [-t tasks]: number of bitbake tasks that can be issued in parallel;
> default=$NCPU
> +    * [-b path]: non-default build dir location; default location is
> $CWD/build
> +    * [-h]: help
> +"
> +}
> +
> +clean_up()
> +{
> +   unset EULA MACHINE JOBS THREADS LIST_MACHINES VALID_MACHINE BUILD_DIR
> +   unset NCPU CWD TEMPLATES
> +   unset imx_poky_setup_j imx_poky_setup_t imx_poky_setup_help
> imx_poky_setup_error
> +}
> +
> +# get command line options
> +OLD_OPTIND=$OPTIND
> +while getopts "m:r:t:b:h" imx_poky_setup_flag
> +do
> +    case $imx_poky_setup_flag in
> +        m) MACHINE="$OPTARG";
> +           ;;
> +        j) imx_poky_setup_j="$OPTARG";
> +           ;;
> +        t) imx_poky_setup_t="$OPTARG";
> +           ;;
> +        b) BUILD_DIR="$CWD/$OPTARG";
> +           ;;
> +        h) imx_poky_setup_help='true';
> +           ;;
> +        ?) imx_poky_setup_error='true';
> +           ;;
> +    esac
> +done
> +OPTIND=$OLD_OPTIND
>
>  if [ "$(whoami)" = "root" ]; then
>      echo "ERROR: do not use the BSP as root. Exiting..."
>  fi
>
> -if [ -z "$MACHINE" ]; then
> -    MACHINE='imx6qsabresd'
> +# check the "-h" and other not supported options
> +if test $imx_poky_setup_error || test $imx_poky_setup_help; then
> +    usage && clean_up && return 1
> +fi
> +
> +# Check the machine type specified
> +LIST_MACHINES=`ls $CWD/sources/meta-fsl-arm/conf/machine`
> +VALID_MACHINE=`echo -e "$LIST_MACHINES" | grep ${MACHINE}.conf$ | wc -l`
> +if [ "x$MACHINE" = "x" ] || [ "$VALID_MACHINE" = "0" ]; then
> +    echo "Invalid machine type!"
> +    usage && clean_up
> +    return 1
> +else
> +    echo "Configuring for ${MACHINE}"
> +fi
> +
> +if [ -n "$imx_poky_setup_j" ] && [[ "$imx_poky_setup_j" =~ ^[0-9]+$ ]];
> then
> +    JOBS=$imx_poky_setup_j
> +else
> +    JOBS=$NCPU
> +fi
> +
> +if [ -n "$fsl_poky_setup_t" ] && [[ "$fsl_poky_setup_t" =~ ^[0-9]+$ ]];
> then
> +    THREADS=$imx_poky_setup_t
> +else
> +    THREADS=$NCPU
> +fi
> +
> +if [ -z "$BUILD_DIR" ]; then
> +    BUILD_DIR=$CWD/build
>  fi
>
>  if [ -z "$SDKMACHINE" ]; then
> @@ -39,8 +114,6 @@ if [ -e sources/oe-core ]; then
>      OEROOT=sources/oe-core
>  fi
>
> -CWD=`pwd`
> -
>  # Ensure all files in sources/base are kept in sync with project root
>  updated=
>  for f in $CWD/sources/base/*; do
> @@ -62,7 +135,7 @@ fi
>
>  cd $OEROOT
>
> -. ./oe-init-build-env $CWD/$1 > /dev/null
> +. ./oe-init-build-env $BUILD_DIR > /dev/null
>
>  # Clean up PATH, because if it includes tokens to current directories
> somehow,
>  # wrong binaries can be used instead of the expected ones during task
> execution
> @@ -74,12 +147,11 @@ if [ ! -e conf/local.conf.sample ]; then
>
>      # Generate the local.conf based on the Yocto defaults
>      TEMPLATES=$CWD/sources/base/conf
> -    NCPU=`grep -c processor /proc/cpuinfo`
>      grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
>      cat >> conf/local.conf <<EOF
>
> -BB_NUMBER_THREADS = '$NCPU'
> -PARALLEL_MAKE = '-j $NCPU'
> +BB_NUMBER_THREADS = '$THREADS'
> +PARALLEL_MAKE = '-j $JOBS'
>  EOF
>      # Change settings according environment
>      sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \
> @@ -167,5 +239,4 @@ else
>      echo "Your configuration files at $1 has not been touched."
>  fi
>
> -# Force the question if setting a new build directory
> -unset EULA
> +clean_up
> --
> 1.7.10.4
>
>
> _______________________________________________
> meta-freescale mailing list
> meta-freescale@yoctoproject.org <javascript:;>
> https://lists.yoctoproject.org/listinfo/meta-freescale
>
Otavio Salvador - May 18, 2013, 2:15 p.m.
On Fri, May 17, 2013 at 10:02 PM, Mahesh Mahadevan
<Mahesh.Mahadevan@freescale.com> wrote:
> From: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
>
> Add options to help specify the machine, below are the options added:
> Usage: source ./setup-environment <-m machine>
>     Optional parameters: [-j jobs] [-t tasks] [-h]
>
>  Supported machines: imx23evk imx28evk imx31pdk imx35pdk imx51evk imx53ard imx53qsb imx6dlsabresd imx6qsabreauto imx6qsabresd imx6slevk

The meta-fsl-arm-extra machines are missing.

>     * [-j jobs]: number of jobs for make to spawn during compile; default=4
>     * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=4

I understand the need for it but I am a little concerned about using
command line options. bitbake use environment to override things, so
you can:

MACHINE=wandboard-dual bitbake core-image-base

and with the default local.conf, it will respect the environment
variable. So we could support same thing, as:

BB_NUMBER_THREADS=8 PARALLEL_MAKE='-j 12' source ./setup-environment <builddir>

>     * [-b path]: non-default build dir location; default location is /home/r9aadq/yocto/build

This one I disagree; I think we always should pass build dir so user
know where he is going.

>     * [-h]: help

ok; please support --help here as well.

> Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
> ---
>  setup-environment |   91 +++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 81 insertions(+), 10 deletions(-)
>
> diff --git a/setup-environment b/setup-environment
> index 6aadbb4..96b1e26 100644
> --- a/setup-environment
> +++ b/setup-environment
> @@ -17,13 +17,88 @@
>  # with this program; if not, write to the Free Software Foundation, Inc.,
>  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>  #
> +# Add options for the script
> +# Copyright (C) 2013 Freescale Semiconductor, Inc.
> +
> +NCPU=`grep -c processor /proc/cpuinfo`
> +CWD=`pwd`
> +
> +usage()
> +{
> +    echo -e "\nUsage: source ${BASH_SOURCE[0]} <-m machine>
> +    Optional parameters: [-j jobs] [-t tasks] [-h]"
> +    echo -e -n "\n Supported machines: `ls $CWD/sources/meta-fsl-arm/conf/machine \
> +    | grep -v "^include" | sed s/\.conf//g | xargs echo`"
> +echo "

Check other layers; you could:

ls $CWD/sources/*/conf/machine/*.conf

> +    * [-j jobs]: number of jobs for make to spawn during compile; default=$NCPU
> +    * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=$NCPU
> +    * [-b path]: non-default build dir location; default location is $CWD/build
> +    * [-h]: help

Was commented above.

> +}
> +
> +clean_up()
> +{
> +   unset EULA MACHINE JOBS THREADS LIST_MACHINES VALID_MACHINE BUILD_DIR
> +   unset NCPU CWD TEMPLATES
> +   unset imx_poky_setup_j imx_poky_setup_t imx_poky_setup_help imx_poky_setup_error

Please drop imx prefix here; use fslc so it does not restrict to imx.

...

I didn't review the other change as many are dependent from the above
ones. What you think?

--
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://projetos.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
Mahadevan Mahesh-R9AADQ - May 19, 2013, 2:04 a.m.
Hi Otavio, 
Replies interspersed below.

Best regards,
-Mahesh

-----Original Message-----
From: otavio.salvador@gmail.com [mailto:otavio.salvador@gmail.com] On Behalf Of Otavio Salvador
Sent: Saturday, May 18, 2013 9:15 AM
To: Mahadevan Mahesh-R9AADQ
Cc: meta-freescale@yoctoproject.org
Subject: Re: [meta-freescale] [fsl-community-bsp-platform][PATCH] setup-environment: add options for the script

On Fri, May 17, 2013 at 10:02 PM, Mahesh Mahadevan
<Mahesh.Mahadevan@freescale.com> wrote:
> From: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
>
> Add options to help specify the machine, below are the options added:
> Usage: source ./setup-environment <-m machine>
>     Optional parameters: [-j jobs] [-t tasks] [-h]
>
>  Supported machines: imx23evk imx28evk imx31pdk imx35pdk imx51evk imx53ard imx53qsb imx6dlsabresd imx6qsabreauto imx6qsabresd imx6slevk

The meta-fsl-arm-extra machines are missing.

[Mahadevan Mahesh-R9AADQ] Sure, will look into adding.

>     * [-j jobs]: number of jobs for make to spawn during compile; default=4
>     * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=4

I understand the need for it but I am a little concerned about using
command line options. bitbake use environment to override things, so
you can:

MACHINE=wandboard-dual bitbake core-image-base

and with the default local.conf, it will respect the environment
variable. So we could support same thing, as:

BB_NUMBER_THREADS=8 PARALLEL_MAKE='-j 12' source ./setup-environment <builddir>

[Mahadevan Mahesh-R9AADQ] That's correct, but the idea behind doing this is to make it simpler for the user with some check for valid machine type.

>     * [-b path]: non-default build dir location; default location is /home/r9aadq/yocto/build

This one I disagree; I think we always should pass build dir so user
know where he is going.

[Mahadevan Mahesh-R9AADQ] I can make the -b option mandatory

>     * [-h]: help

ok; please support --help here as well.

[Mahadevan Mahesh-R9AADQ] Sure will do.

> Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
> ---
>  setup-environment |   91 +++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 81 insertions(+), 10 deletions(-)
>
> diff --git a/setup-environment b/setup-environment
> index 6aadbb4..96b1e26 100644
> --- a/setup-environment
> +++ b/setup-environment
> @@ -17,13 +17,88 @@
>  # with this program; if not, write to the Free Software Foundation, Inc.,
>  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>  #
> +# Add options for the script
> +# Copyright (C) 2013 Freescale Semiconductor, Inc.
> +
> +NCPU=`grep -c processor /proc/cpuinfo`
> +CWD=`pwd`
> +
> +usage()
> +{
> +    echo -e "\nUsage: source ${BASH_SOURCE[0]} <-m machine>
> +    Optional parameters: [-j jobs] [-t tasks] [-h]"
> +    echo -e -n "\n Supported machines: `ls $CWD/sources/meta-fsl-arm/conf/machine \
> +    | grep -v "^include" | sed s/\.conf//g | xargs echo`"
> +echo "

Check other layers; you could:

ls $CWD/sources/*/conf/machine/*.conf

[Mahadevan Mahesh-R9AADQ] Thanks, will look into using this

> +    * [-j jobs]: number of jobs for make to spawn during compile; default=$NCPU
> +    * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=$NCPU
> +    * [-b path]: non-default build dir location; default location is $CWD/build
> +    * [-h]: help

Was commented above.

> +}
> +
> +clean_up()
> +{
> +   unset EULA MACHINE JOBS THREADS LIST_MACHINES VALID_MACHINE BUILD_DIR
> +   unset NCPU CWD TEMPLATES
> +   unset imx_poky_setup_j imx_poky_setup_t imx_poky_setup_help imx_poky_setup_error

Please drop imx prefix here; use fslc so it does not restrict to imx.

[Mahadevan Mahesh-R9AADQ] Isn't this script intended for imx targets, or would you prefer I use fsl instead?

...

I didn't review the other change as many are dependent from the above
ones. What you think?

--
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://projetos.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
Otavio Salvador - May 19, 2013, 7:43 p.m.
On Sat, May 18, 2013 at 11:04 PM, Mahadevan Mahesh-R9AADQ
<r9aadq@freescale.com> wrote:
> On Fri, May 17, 2013 at 10:02 PM, Mahesh Mahadevan
> <Mahesh.Mahadevan@freescale.com> wrote:
>> From: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
>>
>> Add options to help specify the machine, below are the options added:
>> Usage: source ./setup-environment <-m machine>
>>     Optional parameters: [-j jobs] [-t tasks] [-h]
>>
>>  Supported machines: imx23evk imx28evk imx31pdk imx35pdk imx51evk imx53ard imx53qsb imx6dlsabresd imx6qsabreauto imx6qsabresd imx6slevk
>
> The meta-fsl-arm-extra machines are missing.
>
> [Mahadevan Mahesh-R9AADQ] Sure, will look into adding.

Good.

>>     * [-j jobs]: number of jobs for make to spawn during compile; default=4
>>     * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=4
>
> I understand the need for it but I am a little concerned about using
> command line options. bitbake use environment to override things, so
> you can:
>
> MACHINE=wandboard-dual bitbake core-image-base
>
> and with the default local.conf, it will respect the environment
> variable. So we could support same thing, as:
>
> BB_NUMBER_THREADS=8 PARALLEL_MAKE='-j 12' source ./setup-environment <builddir>
>
> [Mahadevan Mahesh-R9AADQ] That's correct, but the idea behind doing this is to make it simpler for the user with some check for valid machine type.

The problem I see is not the machine validation (which can be done)
but the different way of work. If people use:

MACHINE=<machine> source ./setup-environment build

It will be natural for them to use:

MACHINE=<another machine> bitbake ...

So we're consistent on how to use things. You can validate the used
machine for setup-environment but using two ways for same thing is
confusing.

>>     * [-b path]: non-default build dir location; default location is /home/r9aadq/yocto/build
>
> This one I disagree; I think we always should pass build dir so user
> know where he is going.
>
> [Mahadevan Mahesh-R9AADQ] I can make the -b option mandatory
>
>>     * [-h]: help
>
> ok; please support --help here as well.
>
> [Mahadevan Mahesh-R9AADQ] Sure will do.

Ok

>> Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
>> ---
>>  setup-environment |   91 +++++++++++++++++++++++++++++++++++++++++++++++------
>>  1 file changed, 81 insertions(+), 10 deletions(-)
>>
>> diff --git a/setup-environment b/setup-environment
>> index 6aadbb4..96b1e26 100644
>> --- a/setup-environment
>> +++ b/setup-environment
>> @@ -17,13 +17,88 @@
>>  # with this program; if not, write to the Free Software Foundation, Inc.,
>>  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>>  #
>> +# Add options for the script
>> +# Copyright (C) 2013 Freescale Semiconductor, Inc.
>> +
>> +NCPU=`grep -c processor /proc/cpuinfo`
>> +CWD=`pwd`
>> +
>> +usage()
>> +{
>> +    echo -e "\nUsage: source ${BASH_SOURCE[0]} <-m machine>
>> +    Optional parameters: [-j jobs] [-t tasks] [-h]"
>> +    echo -e -n "\n Supported machines: `ls $CWD/sources/meta-fsl-arm/conf/machine \
>> +    | grep -v "^include" | sed s/\.conf//g | xargs echo`"
>> +echo "
>
> Check other layers; you could:
>
> ls $CWD/sources/*/conf/machine/*.conf
>
> [Mahadevan Mahesh-R9AADQ] Thanks, will look into using this

Ok

>> +    * [-j jobs]: number of jobs for make to spawn during compile; default=$NCPU
>> +    * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=$NCPU
>> +    * [-b path]: non-default build dir location; default location is $CWD/build
>> +    * [-h]: help
>
> Was commented above.
>
>> +}
>> +
>> +clean_up()
>> +{
>> +   unset EULA MACHINE JOBS THREADS LIST_MACHINES VALID_MACHINE BUILD_DIR
>> +   unset NCPU CWD TEMPLATES
>> +   unset imx_poky_setup_j imx_poky_setup_t imx_poky_setup_help imx_poky_setup_error
>
> Please drop imx prefix here; use fslc so it does not restrict to imx.
>
> [Mahadevan Mahesh-R9AADQ] Isn't this script intended for imx targets, or would you prefer I use fsl instead?

No; it is intended for use with fsl-community-bsp and we can have more
than i.MX here. Better to avoid 'imx' when something is not really
specific and this script has nothing specific.

--
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://projetos.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750

Patch

diff --git a/setup-environment b/setup-environment
index 6aadbb4..96b1e26 100644
--- a/setup-environment
+++ b/setup-environment
@@ -17,13 +17,88 @@ 
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
+# Add options for the script
+# Copyright (C) 2013 Freescale Semiconductor, Inc.
+
+NCPU=`grep -c processor /proc/cpuinfo`
+CWD=`pwd`
+
+usage()
+{
+    echo -e "\nUsage: source ${BASH_SOURCE[0]} <-m machine>
+    Optional parameters: [-j jobs] [-t tasks] [-h]"
+    echo -e -n "\n Supported machines: `ls $CWD/sources/meta-fsl-arm/conf/machine \
+    | grep -v "^include" | sed s/\.conf//g | xargs echo`"
+echo "
+    * [-j jobs]: number of jobs for make to spawn during compile; default=$NCPU
+    * [-t tasks]: number of bitbake tasks that can be issued in parallel; default=$NCPU
+    * [-b path]: non-default build dir location; default location is $CWD/build
+    * [-h]: help
+"
+}
+
+clean_up()
+{
+   unset EULA MACHINE JOBS THREADS LIST_MACHINES VALID_MACHINE BUILD_DIR
+   unset NCPU CWD TEMPLATES
+   unset imx_poky_setup_j imx_poky_setup_t imx_poky_setup_help imx_poky_setup_error
+}
+
+# get command line options
+OLD_OPTIND=$OPTIND
+while getopts "m:r:t:b:h" imx_poky_setup_flag
+do
+    case $imx_poky_setup_flag in
+        m) MACHINE="$OPTARG";
+           ;;
+        j) imx_poky_setup_j="$OPTARG";
+           ;;
+        t) imx_poky_setup_t="$OPTARG";
+           ;;
+        b) BUILD_DIR="$CWD/$OPTARG";
+           ;;
+        h) imx_poky_setup_help='true';
+           ;;
+        ?) imx_poky_setup_error='true';
+           ;;
+    esac
+done
+OPTIND=$OLD_OPTIND
 
 if [ "$(whoami)" = "root" ]; then
     echo "ERROR: do not use the BSP as root. Exiting..."
 fi
 
-if [ -z "$MACHINE" ]; then
-    MACHINE='imx6qsabresd'
+# check the "-h" and other not supported options
+if test $imx_poky_setup_error || test $imx_poky_setup_help; then
+    usage && clean_up && return 1
+fi
+
+# Check the machine type specified
+LIST_MACHINES=`ls $CWD/sources/meta-fsl-arm/conf/machine`
+VALID_MACHINE=`echo -e "$LIST_MACHINES" | grep ${MACHINE}.conf$ | wc -l`
+if [ "x$MACHINE" = "x" ] || [ "$VALID_MACHINE" = "0" ]; then
+    echo "Invalid machine type!"
+    usage && clean_up
+    return 1
+else
+    echo "Configuring for ${MACHINE}"
+fi
+
+if [ -n "$imx_poky_setup_j" ] && [[ "$imx_poky_setup_j" =~ ^[0-9]+$ ]]; then
+    JOBS=$imx_poky_setup_j
+else
+    JOBS=$NCPU
+fi
+
+if [ -n "$fsl_poky_setup_t" ] && [[ "$fsl_poky_setup_t" =~ ^[0-9]+$ ]]; then
+    THREADS=$imx_poky_setup_t
+else
+    THREADS=$NCPU
+fi
+
+if [ -z "$BUILD_DIR" ]; then
+    BUILD_DIR=$CWD/build
 fi
 
 if [ -z "$SDKMACHINE" ]; then
@@ -39,8 +114,6 @@  if [ -e sources/oe-core ]; then
     OEROOT=sources/oe-core
 fi
 
-CWD=`pwd`
-
 # Ensure all files in sources/base are kept in sync with project root
 updated=
 for f in $CWD/sources/base/*; do
@@ -62,7 +135,7 @@  fi
 
 cd $OEROOT
 
-. ./oe-init-build-env $CWD/$1 > /dev/null
+. ./oe-init-build-env $BUILD_DIR > /dev/null
 
 # Clean up PATH, because if it includes tokens to current directories somehow,
 # wrong binaries can be used instead of the expected ones during task execution
@@ -74,12 +147,11 @@  if [ ! -e conf/local.conf.sample ]; then
 
     # Generate the local.conf based on the Yocto defaults
     TEMPLATES=$CWD/sources/base/conf 
-    NCPU=`grep -c processor /proc/cpuinfo`
     grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
     cat >> conf/local.conf <<EOF
 
-BB_NUMBER_THREADS = '$NCPU'
-PARALLEL_MAKE = '-j $NCPU'
+BB_NUMBER_THREADS = '$THREADS'
+PARALLEL_MAKE = '-j $JOBS'
 EOF
     # Change settings according environment
     sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \
@@ -167,5 +239,4 @@  else
     echo "Your configuration files at $1 has not been touched."
 fi
 
-# Force the question if setting a new build directory
-unset EULA
+clean_up