Skip to content

Commit f30bfb7

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 3a521d4 commit f30bfb7

File tree

1 file changed

+63
-12
lines changed

1 file changed

+63
-12
lines changed

scripts/examples/imxlinux_example.sh

+63-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,66 @@
1818

1919
set -e
2020
set -x
21-
if [ "$#" != 2 && "$#" != 3 ]; then
22-
exit -1
21+
helpFunction() {
22+
cat <<EOF
23+
Usage: $0 -s|--src <src folder> -o|--out <out folder> [-d|--debug] [-n|--no-init] [-t|--trusty]
24+
-s, --src Source folder
25+
-o, --out Output folder
26+
-d, --debug Debug build (optional)
27+
-n, --no-init No init mode (optional)
28+
-t, --trusty Build with Trusty OS backed security enhancement (optional)
29+
EOF
30+
exit 1
31+
}
32+
33+
trusty=0
34+
release_build=true
35+
PARSED_OPTIONS="$(getopt -o s:o:tdn --long src:,out:,trusty,debug,no-init -- "$@")"
36+
if [ $? -ne 0 ]; then
37+
helpFunction
2338
fi
39+
eval set -- "$PARSED_OPTIONS"
40+
while true; do
41+
case "$1" in
42+
-s | --src)
43+
src="$2"
44+
shift 2
45+
;;
46+
-o | --out)
47+
out="$2"
48+
shift 2
49+
;;
50+
-t | --trusty)
51+
trusty=1
52+
shift
53+
;;
54+
-d | --debug)
55+
release_build=false
56+
shift
57+
;;
58+
-n | --no-init)
59+
no_init=1
60+
shift
61+
;;
62+
--)
63+
shift
64+
break
65+
;;
66+
*)
67+
echo "Invalid option: $1" >&2
68+
exit 1
69+
;;
70+
esac
71+
done
2472

25-
source "$(dirname "$0")/../../scripts/activate.sh"
73+
if [ -z "$src" ] || [ -z "$out" ]; then
74+
echo "Some or all of the required -s|--src and -o|--out parameters are empty."
75+
helpFunction
76+
fi
77+
78+
if [ "$no_init" != 1 ]; then
79+
source "$(dirname "$0")/../../scripts/activate.sh"
80+
fi
2681

2782
if [ "$IMX_SDK_ROOT" = "" -o ! -d "$IMX_SDK_ROOT" ]; then
2883
echo "the Yocto SDK path is not specified with the shell env IMX_SDK_ROOT or an invalid path is specified"
@@ -100,13 +155,9 @@ if [ -z "$target_cpu" -o -z "$cross_compile" ]; then
100155
exit 1
101156
fi
102157

103-
release_build=true
104-
if [ "$3" = "debug" ]; then
105-
release_build=false
106-
fi
107-
108158
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\"
159+
gn gen --check --fail-on-unused-args --root="$src" "$out" --args="target_os=\"linux\" target_cpu=\"$target_cpu\" arm_arch=\"$arm_arch\"
160+
chip_with_trusty_os=$trusty
110161
treat_warnings_as_errors=false
111162
import(\"//build_overrides/build.gni\")
112163
sysroot=\"$sdk_target_sysroot\"
@@ -117,4 +168,4 @@ target_cxx=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/
117168
target_ar=\"$IMX_SDK_ROOT/sysroots/x86_64-pokysdk-linux/usr/bin/$cross_compile/$cross_compile-ar\"
118169
$(if [ "$release_build" = "true" ]; then echo "is_debug=false"; else echo "optimize_debug=true"; fi)"
119170

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

0 commit comments

Comments
 (0)