gn_silabs_example.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2020 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Build script for GN EFR32 examples GitHub workflow.
  18. set -e
  19. if [[ -z "${MATTER_ROOT}" ]]; then
  20. echo "Using default path for Matter root"
  21. CHIP_ROOT="$(dirname "$0")/../.."
  22. else
  23. echo "Using ENV path for Matter root"
  24. CHIP_ROOT="$MATTER_ROOT"
  25. fi
  26. set -x
  27. env
  28. USE_WIFI=false
  29. USE_DOCKER=false
  30. USE_GIT_SHA_FOR_VERSION=true
  31. USE_SLC=false
  32. GN_PATH=gn
  33. GN_PATH_PROVIDED=false
  34. DOTFILE=".gn"
  35. SILABS_THREAD_TARGET=\""../silabs:ot-efr32-cert"\"
  36. USAGE="./scripts/examples/gn_silabs_example.sh <AppRootFolder> <outputFolder> <silabs_board_name> [<Build options>]"
  37. if [ "$#" == "0" ]; then
  38. echo "Build script for EFR32 Matter apps
  39. Format:
  40. $USAGE
  41. <AppRootFolder>
  42. Root Location of the app e.g: examples/lighting-app/efr32/
  43. <outputFolder>
  44. Desired location for the output files
  45. <silabs_board_name>
  46. Identifier of the board for which this app is built
  47. Currently Supported :
  48. BRD4161A
  49. BRD4163A
  50. BRD4164A
  51. BRD4166A
  52. BRD4170A
  53. BRD4186A
  54. BRD4187A
  55. BRD4304A
  56. <Build options> - optional noteworthy build options for EFR32
  57. chip_build_libshell
  58. Enable libshell support. (Default false)
  59. chip_logging
  60. Current value (Default true)
  61. chip_openthread_ftd
  62. Use openthread Full Thread Device, else, use Minimal Thread Device. (Default true)
  63. efr32_sdk_root
  64. Location for an alternate or modified efr32 SDK
  65. enable_heap_monitoring
  66. Monitor & log memory usage at runtime. (Default false)
  67. enable_openthread_cli
  68. Enables openthread cli without matter shell. (Default true)
  69. kvs_max_entries
  70. Set the maxium Kvs entries that can be store in NVM (Default 75)
  71. Thresholds: 30 <= kvs_max_entries <= 255
  72. show_qr_code
  73. Enables QR code on LCD for devices with an LCD
  74. chip_enable_icd_server
  75. Configure has a Intermitently connected device. (Default false)
  76. Must also set chip_openthread_ftd=false
  77. use_rs9116
  78. Build wifi example with extension board rs9116. (Default false)
  79. use_SiWx917
  80. Build wifi example with extension board SiWx917. (Default false)
  81. use_wf200
  82. Build wifi example with extension board wf200. (Default false)
  83. 'import("//with_pw_rpc.gni")'
  84. Use to build the example with pigweed RPC
  85. ota_periodic_query_timeout_sec
  86. Periodic query timeout variable for OTA in seconds
  87. rs91x_wpa3_transition
  88. Support for WPA3 transition mode on RS91x
  89. slc_gen_path
  90. Allow users to define a path where slc generates board files. (requires --slc_generate or --slc_reuse_files)
  91. (default: /third_party/silabs/slc_gen/<board>/)
  92. sl_pre_gen_path
  93. Allow users to define a path to pre-generated board files
  94. (default: /third_party/silabs/matter_support/matter/<family>/<board>/)
  95. sl_matter_version
  96. Use provided software version at build time
  97. sl_matter_version_str
  98. Set a Matter sotfware version string for the Silabs examples
  99. Used and formatted by default in this script.
  100. sl_hardware_version
  101. Use provided hardware version at build time
  102. siwx917_commissionable_data
  103. Build with the commissionable data given in DeviceConfig.h (only for SiWx917)
  104. Presets
  105. --icd
  106. enable ICD features, set thread mtd
  107. For minimum consumption, add --low-power
  108. --low-power
  109. disables all power consuming features for the most power efficient build
  110. This flag is to be used with --icd
  111. --wifi <wf200 | rs9116>
  112. build wifi example variant for given exansion board
  113. --additional_data_advertising
  114. enable Addition data advertissing and rotating device ID
  115. --use_ot_lib
  116. use the silabs openthread library
  117. --use_chip_lwip_lib
  118. use the chip lwip library
  119. --release
  120. Remove all logs and debugs features (including the LCD). Yield the smallest image size possible
  121. --docker
  122. Change GSDK root for docker builds
  123. --uart_log
  124. Forward Logs to Uart instead of RTT
  125. --slc_generate
  126. Generate files with SLC for current board and options Requires an SLC-CLI installation or running in Docker.
  127. --slc_reuse_files
  128. Use generated files without running slc again.
  129. "
  130. elif [ "$#" -lt "2" ]; then
  131. echo "Invalid number of arguments
  132. Format:
  133. $USAGE"
  134. else
  135. ROOT=$1
  136. OUTDIR=$2
  137. if [ "$#" -gt "2" ]; then
  138. SILABS_BOARD=$3
  139. shift
  140. fi
  141. shift
  142. shift
  143. while [ $# -gt 0 ]; do
  144. case $1 in
  145. --clean)
  146. DIR_CLEAN=true
  147. shift
  148. ;;
  149. --wifi)
  150. if [ -z "$2" ]; then
  151. echo "--wifi requires rs9116 or SiWx917 or wf200"
  152. exit 1
  153. fi
  154. if [ "$2" = "rs9116" ]; then
  155. optArgs+="use_rs9116=true "
  156. elif [ "$2" = "SiWx917" ]; then
  157. optArgs+="use_SiWx917=true "
  158. elif [ "$2" = "wf200" ]; then
  159. optArgs+="use_wf200=true "
  160. else
  161. echo "Wifi usage: --wifi rs9116|SiWx917|wf200"
  162. exit 1
  163. fi
  164. USE_WIFI=true
  165. optArgs+="chip_device_platform =\"efr32\" "
  166. shift
  167. shift
  168. ;;
  169. --icd)
  170. optArgs+="chip_enable_icd_server=true chip_openthread_ftd=false "
  171. shift
  172. ;;
  173. --low-power)
  174. optArgs+="chip_build_libshell=false enable_openthread_cli=false show_qr_code=false disable_lcd=true "
  175. shift
  176. ;;
  177. --chip_enable_wifi_ipv4)
  178. optArgs="chip_enable_wifi_ipv4=true chip_inet_config_enable_ipv4=true "
  179. shift
  180. ;;
  181. --additional_data_advertising)
  182. optArgs+="chip_enable_additional_data_advertising=true chip_enable_rotating_device_id=true "
  183. shift
  184. ;;
  185. --use_ot_lib)
  186. optArgs+="use_silabs_thread_lib=true chip_openthread_target=$SILABS_THREAD_TARGET openthread_external_platform=\"""\" "
  187. shift
  188. ;;
  189. --use_ot_coap_lib)
  190. optArgs+="use_silabs_thread_lib=true chip_openthread_target=$SILABS_THREAD_TARGET openthread_external_platform=\"""\" use_thread_coap_lib=true "
  191. shift
  192. ;;
  193. --use_chip_lwip_lib)
  194. optArgs+="lwip_root=\""//third_party/connectedhomeip/third_party/lwip"\" "
  195. shift
  196. ;;
  197. # Option not to be used until ot-efr32 github is updated
  198. # --use_ot_github_sources)
  199. # optArgs+="openthread_root=\"//third_party/connectedhomeip/third_party/openthread/ot-efr32/openthread\" openthread_efr32_root=\"//third_party/connectedhomeip/third_party/openthread/ot-efr32/src/src\""
  200. # shift
  201. # ;;
  202. --release)
  203. optArgs+="is_debug=false disable_lcd=true chip_build_libshell=false enable_openthread_cli=false use_external_flash=false chip_logging=false silabs_log_enabled=false "
  204. shift
  205. ;;
  206. --docker)
  207. optArgs+="efr32_sdk_root=\"$GSDK_ROOT\" "
  208. USE_DOCKER=true
  209. shift
  210. ;;
  211. --uart_log)
  212. optArgs+="sl_uart_log_output=true "
  213. shift
  214. ;;
  215. --slc_generate)
  216. optArgs+="slc_generate=true "
  217. USE_SLC=true
  218. shift
  219. ;;
  220. --slc_reuse_files)
  221. optArgs+="slc_reuse_files=true "
  222. USE_SLC=true
  223. shift
  224. ;;
  225. --gn_path)
  226. if [ -z "$2" ]; then
  227. echo "--gn_path requires a path to GN"
  228. exit 1
  229. else
  230. GN_PATH="$2"
  231. fi
  232. GN_PATH_PROVIDED=true
  233. shift
  234. shift
  235. ;;
  236. *"sl_matter_version_str="*)
  237. optArgs+="$1 "
  238. USE_GIT_SHA_FOR_VERSION=false
  239. shift
  240. ;;
  241. *)
  242. if [ "$1" =~ *"use_rs9116=true"* ] || [ "$1" =~ *"use_SiWx917=true"* ] || [ "$1" =~ *"use_wf200=true"* ]; then
  243. USE_WIFI=true
  244. # NCP Mode so base MCU is an EFR32
  245. optArgs+="chip_device_platform =\"efr32\" "
  246. fi
  247. optArgs+=$1" "
  248. shift
  249. ;;
  250. esac
  251. done
  252. if [ -z "$SILABS_BOARD" ]; then
  253. echo "SILABS_BOARD not defined"
  254. exit 1
  255. fi
  256. # 917 exception. TODO find a more generic way
  257. if [ "$SILABS_BOARD" == "BRD4325B" ] || [ "$SILABS_BOARD" == "BRD4325C" ] || [ "$SILABS_BOARD" == "BRD4338A" ]; then
  258. echo "Compiling for 917 WiFi SOC"
  259. USE_WIFI=true
  260. optArgs+="chip_device_platform =\"SiWx917\" "
  261. fi
  262. if [ "$USE_GIT_SHA_FOR_VERSION" == true ]; then
  263. {
  264. ShortCommitSha=$(git describe --always --dirty --exclude '*')
  265. branchName=$(git rev-parse --abbrev-ref HEAD)
  266. optArgs+="sl_matter_version_str=\"v1.1-$branchName-$ShortCommitSha\" "
  267. } &>/dev/null
  268. fi
  269. if [ "$USE_SLC" == true ]; then
  270. if [ "$GN_PATH_PROVIDED" == false ]; then
  271. GN_PATH=./.environment/cipd/packages/pigweed/gn
  272. fi
  273. elif [ "$USE_SLC" == false ]; then
  274. # Activation needs to be after SLC generation which is done in gn gen.
  275. # Zap generation requires activation and is done in the build phase
  276. source "$CHIP_ROOT/scripts/activate.sh"
  277. fi
  278. PYTHON_PATH="$(which python3)"
  279. BUILD_DIR=$OUTDIR/$SILABS_BOARD
  280. echo BUILD_DIR="$BUILD_DIR"
  281. if [ "$DIR_CLEAN" == true ]; then
  282. rm -rf "$BUILD_DIR"
  283. fi
  284. if [ "$USE_WIFI" == true ]; then
  285. DOTFILE="$ROOT/build_for_wifi_gnfile.gn"
  286. else
  287. DOTFILE="$ROOT/openthread.gn"
  288. fi
  289. if [ "$USE_DOCKER" == true ] && [ "$USE_WIFI" == false ]; then
  290. echo "Switching OpenThread ROOT"
  291. optArgs+="openthread_root=\"$GSDK_ROOT/util/third_party/openthread\" "
  292. fi
  293. "$GN_PATH" gen --check --script-executable="$PYTHON_PATH" --fail-on-unused-args --export-compile-commands --root="$ROOT" --dotfile="$DOTFILE" --args="silabs_board=\"$SILABS_BOARD\" $optArgs" "$BUILD_DIR"
  294. if [ "$USE_SLC" == true ]; then
  295. # Activation needs to be after SLC generation which is done in gn gen.
  296. # Zap generation requires activation and is done in the build phase
  297. source "$CHIP_ROOT/scripts/activate.sh"
  298. fi
  299. ninja -v -C "$BUILD_DIR"/
  300. #print stats
  301. arm-none-eabi-size -A "$BUILD_DIR"/*.out
  302. fi