Skip to content

Commit feab596

Browse files
TE-N-ElvenWang“nxf90552”
authored and
“nxf90552”
committed
Refine imxlinux_example.sh build script
Now the build script are refined to use parameter for different option: Usage:./scripts/examples/imxlinux_example.sh -s|--src <src folder> -o|--out <out folder> [-d|--debug] [-n|--no-init] [-t|--trusty] -s, --src Source folder -o, --out Output folder -d, --debug Debug build (optional) -n, --no-init No init mode (optional) -t, --trusty Build with Trusty OS backed security enhancement (optional) example: ./scripts/examples/imxlinux_example.sh -s examples/chip-tool -o out -dnt #will build examples/chip-tool to out/ folder with debug build and skip init and use Trusty OS. Change-Id: I3ac3b60395255b3bfe45fdf21184ba0b6c7ba265 Signed-off-by: Haoran.Wang <elven.wang@nxp.com> Reviewed-on: http://androidsource.nxp.com/project/21564 Reviewed-by: Faqiang Zhu <faqiang.zhu@nxp.com> Reviewed-on: http://androidsource.nxp.com/project/23009
1 parent 760568b commit feab596

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

scripts/examples/imxlinux_example.sh

+45-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/usr/bin/env bash
2-
1+
#!/bin/bash
32
#
43
# Copyright (c) 2022 Project CHIP Authors
4+
# Copyright 2023, 2025 NXP
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -18,11 +18,48 @@
1818

1919
set -e
2020
set -x
21-
if [ "$#" != 2 && "$#" != 3 ]; then
22-
exit -1
21+
helpFunction()
22+
{
23+
cat << EOF
24+
Usage: $0 -s|--src <src folder> -o|--out <out folder> [-d|--debug] [-n|--no-init] [-t|--trusty]
25+
-s, --src Source folder
26+
-o, --out Output folder
27+
-d, --debug Debug build (optional)
28+
-n, --no-init No init mode (optional)
29+
-t, --trusty Build with Trusty OS backed security enhancement (optional)
30+
EOF
31+
exit 1
32+
}
33+
34+
trusty=0
35+
release_build=true
36+
PARSED_OPTIONS="$(getopt -o s:o:tdn --long src:,out:,trusty,debug,no-init -- "$@")"
37+
if [ $? -ne 0 ];
38+
then
39+
helpFunction
40+
fi
41+
eval set -- "$PARSED_OPTIONS"
42+
while true; do
43+
case "$1" in
44+
-s|--src) src="$2"; shift 2 ;;
45+
-o|--out) out="$2"; shift 2 ;;
46+
-t|--trusty) trusty=1; shift ;;
47+
-d|--debug) release_build=false; shift ;;
48+
-n|--no-init) no_init=1; shift ;;
49+
--) shift; break ;;
50+
*) echo "Invalid option: $1" >&2; exit 1 ;;
51+
esac
52+
done
53+
54+
if [ -z "$src" ] || [ -z "$out" ]; then
55+
echo "Some or all of the required -s|--src and -o|--out parameters are empty.";
56+
helpFunction
2357
fi
2458

25-
source "$(dirname "$0")/../../scripts/activate.sh"
59+
60+
if [ "$no_init" != 1 ]; then
61+
source "$(dirname "$0")/../../scripts/activate.sh"
62+
fi
2663

2764
if [ "$IMX_SDK_ROOT" = "" -o ! -d "$IMX_SDK_ROOT" ]; then
2865
echo "the Yocto SDK path is not specified with the shell env IMX_SDK_ROOT or an invalid path is specified"
@@ -100,13 +137,9 @@ if [ -z "$target_cpu" -o -z "$cross_compile" ]; then
100137
exit 1
101138
fi
102139

103-
release_build=true
104-
if [ "$3" = "debug" ]; then
105-
release_build=false
106-
fi
107-
108140
PLATFORM_CFLAGS='-DCHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME=\"mlan0\"", "-DCHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD=\"udhcpc -b -i %s \"'
109-
gn gen --check --fail-on-unused-args --root="$1" "$2" --args="target_os=\"linux\" target_cpu=\"$target_cpu\" arm_arch=\"$arm_arch\"
141+
gn gen --check --fail-on-unused-args --root="$src" "$out" --args="target_os=\"linux\" target_cpu=\"$target_cpu\" arm_arch=\"$arm_arch\"
142+
chip_with_trusty_os=$trusty
110143
treat_warnings_as_errors=false
111144
import(\"//build_overrides/build.gni\")
112145
sysroot=\"$sdk_target_sysroot\"
@@ -117,4 +150,4 @@ target_cxx=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/
117150
target_ar=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/$cross_compile-ar\"
118151
$(if [ "$release_build" = "true" ]; then echo "is_debug=false"; else echo "optimize_debug=true"; fi)"
119152

120-
ninja -C "$2"
153+
ninja -C "$out"

0 commit comments

Comments
 (0)