diff --git a/scripts/build/builders/imx.py b/scripts/build/builders/imx.py index 9118066f5d0d05..6275bd41da748e 100644 --- a/scripts/build/builders/imx.py +++ b/scripts/build/builders/imx.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import re from enum import Enum, auto from .gn import GnBuilder @@ -74,30 +75,58 @@ def __init__(self, self.release = release self.app = app - def GnBuildEnv(self): - return { - 'PKG_CONFIG_PATH': self.SysRootPath('IMX_SDK_ROOT') + '/sysroots/cortexa53-crypto-poky-linux/lib/aarch64-linux-gnu/pkgconfig', - } - def GnBuildArgs(self): + entries = os.listdir(self.SysRootPath('IMX_SDK_ROOT')) + for entry in entries: + if re.match(r'^environment-setup-', entry): + env_setup_script = entry + break + + with open(os.path.join(self.SysRootPath('IMX_SDK_ROOT'), env_setup_script), 'r') as env_setup_script_fd: + lines = env_setup_script_fd.readlines() + for line in lines: + line = line.strip('\n') + if re.match(r'export SDKTARGETSYSROOT=', line): + sdk_target_sysroot = line[len(r'export SDKTARGETSYSROOT='):] + if re.match(r'export CC=', line): + # remove the quotation marks, replace a shell env + cc = line[len(r'export CC=')+1: -1] + cc = cc.replace('$SDKTARGETSYSROOT', sdk_target_sysroot) + if re.match(r'export CXX=', line): + # remove the quotation marks, replace a shell env + cxx = line[len(r'export CXX=')+1: -1] + cxx = cxx.replace('$SDKTARGETSYSROOT', sdk_target_sysroot) + if re.match(r'export ARCH=', line): + target_cpu = line[len(r'export ARCH='):] + if target_cpu == 'arm64': + arm_arch = 'armv8-a' + elif target_cpu == 'arm': + arm_arch = 'armv7ve' + if re.match(r'export CROSS_COMPILE=', line): + cross_compile = line[len(r'export CROSS_COMPILE='):-1] + print(cross_compile) + args = [ + 'treat_warnings_as_errors=false', 'target_os="linux"', - 'target_cpu="arm64"', - 'arm_arch="armv8-a"', + 'target_cpu="%s"' % target_cpu, + 'arm_arch="%s"' % arm_arch, 'import(\"//build_overrides/build.gni\")', 'custom_toolchain=\"${build_root}/toolchain/custom\"', - 'sysroot="%s/sysroots/cortexa53-crypto-poky-linux"' % self.SysRootPath('IMX_SDK_ROOT'), + 'sysroot="%s"' % sdk_target_sysroot, 'target_cflags=[ "-DCHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME=\\"mlan0\\"", "-DCHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD=\\"udhcpc -b -i %s \\"" ]', - 'target_cc="%s/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc"' % self.SysRootPath( - 'IMX_SDK_ROOT'), - 'target_cxx="%s/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++"' % self.SysRootPath( - 'IMX_SDK_ROOT'), - 'target_ar="%s/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar"' % self.SysRootPath( - 'IMX_SDK_ROOT'), + 'target_cc="%s/sysroots/x86_64-pokysdk-linux/usr/bin/%s/%s"' % (self.SysRootPath('IMX_SDK_ROOT'), cross_compile, + cc), + 'target_cxx="%s/sysroots/x86_64-pokysdk-linux/usr/bin/%s/%s"' % (self.SysRootPath('IMX_SDK_ROOT'), cross_compile, + cxx), + 'target_ar="%s/sysroots/x86_64-pokysdk-linux/usr/bin/%s/%s-ar"' % (self.SysRootPath('IMX_SDK_ROOT'), cross_compile, + cross_compile), ] if self.release: args.append('is_debug=false') + else: + args.append('optimize_debug=true') return args diff --git a/scripts/examples/imxlinux_example.sh b/scripts/examples/imxlinux_example.sh index e0ac39bd13c289..98b2da70904ec0 100755 --- a/scripts/examples/imxlinux_example.sh +++ b/scripts/examples/imxlinux_example.sh @@ -18,7 +18,7 @@ set -e set -x -if [ "$#" != 2 ]; then +if [ "$#" != 2 && "$#" != 3 ]; then exit -1 fi @@ -30,15 +30,64 @@ if [ "$IMX_SDK_ROOT" = "" ]; then fi env +entries=$(ls "$IMX_SDK_ROOT") +for entry in "$entries"; do + if [ "$(echo "$entry" | grep -E "^environment-setup-")" != "" ]; then + env_setup_script=$entry + break + fi +done + +while read line; do + if [ "$(echo "$line" | grep -E "^export SDKTARGETSYSROOT=")" != "" ]; then + sdk_target_sysroot=${line#"export SDKTARGETSYSROOT="} + fi + + if [ "$(echo "$line" | grep -E "^export CC=")" != "" ]; then + cc=${line#"export CC="} + cc=${cc#"\""} + cc=${cc%"\""} + cc=${cc/"\$SDKTARGETSYSROOT"/$sdk_target_sysroot} + fi + + if [ "$(echo "$line" | grep -E "^export CXX=")" != "" ]; then + cxx=${line#"export CXX="} + cxx=${cxx#"\""} + cxx=${cxx%"\""} + cxx=${cxx/"\$SDKTARGETSYSROOT"/$sdk_target_sysroot} + fi + + if [ "$(echo "$line" | grep -E "^export ARCH=")" != "" ]; then + target_cpu=${line#"export ARCH="} + + if [ "$target_cpu" = "arm64" ]; then + arm_arch="armv8-a" + elif [ "$target_cpu" = "arm" ]; then + arm_arch="armv7ve" + fi + fi + + if [ "$(echo "$line" | grep -E "^export CROSS_COMPILE=")" != "" ]; then + cross_compile=${line#"export CROSS_COMPILE="} + cross_compile=${cross_compile%"-"} + fi +done <"$IMX_SDK_ROOT/$env_setup_script" + +release_build=true +if [ "$3" = "debug" ]; then + release_build=false +fi + PLATFORM_CFLAGS='-DCHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME=\"mlan0\"", "-DCHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD=\"udhcpc -b -i %s \"' -PKG_CONFIG_PATH=$IMX_SDK_ROOT/sysroots/cortexa53-crypto-poky-linux/lib/aarch64-linux-gnu/pkgconfig \ - gn gen --check --fail-on-unused-args --root="$1" "$2" --args="target_os=\"linux\" target_cpu=\"arm64\" arm_arch=\"armv8-a\" +gn gen --check --fail-on-unused-args --root="$1" "$2" --args="target_os=\"linux\" target_cpu=\"$target_cpu\" arm_arch=\"$arm_arch\" +treat_warnings_as_errors=false import(\"//build_overrides/build.gni\") -sysroot=\"$IMX_SDK_ROOT/sysroots/cortexa53-crypto-poky-linux\" +sysroot=\"$sdk_target_sysroot\" target_cflags=[ \"$PLATFORM_CFLAGS\" ] custom_toolchain=\"\${build_root}/toolchain/custom\" -target_cc=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc\" -target_cxx=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++\" -target_ar=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar\"" +target_cc=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/$cc\" +target_cxx=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/$cxx\" +target_ar=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/$cross_compile-ar\" +$(if [ "$release_build" = "true" ]; then echo "is_debug=false"; else echo "optimize_debug=true"; fi)" ninja -C "$2"