gn_silabs_example.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. enable_sleepy_device
  75. Enable Sleepy end 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_only
  88. Support for WPA3 only mode on RS91x
  89. sl_matter_version
  90. Use provided software version at build time
  91. sl_matter_version_str
  92. Set a Matter sotfware version string for the Silabs examples
  93. Used and formatted by default in this script.
  94. sl_hardware_version
  95. Use provided hardware version at build time
  96. siwx917_commissionable_data
  97. Build with the commissionable data given in DeviceConfig.h (only for SiWx917)
  98. Presets
  99. --sed
  100. enable sleepy end device, set thread mtd
  101. For minimum consumption, add --low-power
  102. --low-power
  103. disables all power consuming features for the most power efficient build
  104. This flag is to be used with --sed
  105. --wifi <wf200 | rs9116>
  106. build wifi example variant for given exansion board
  107. --additional_data_advertising
  108. enable Addition data advertissing and rotating device ID
  109. --use_ot_lib
  110. use the silabs openthread library
  111. --use_chip_lwip_lib
  112. use the chip lwip library
  113. --release
  114. Remove all logs and debugs features (including the LCD). Yield the smallest image size possible
  115. --docker
  116. Change GSDK root for docker builds
  117. --uart_log
  118. Forward Logs to Uart instead of RTT
  119. --slc_generate
  120. Generate files with SLC for current board and options Requires an SLC-CLI installation or running in Docker.
  121. --slc_reuse_files
  122. Use generated files without running slc again.
  123. "
  124. elif [ "$#" -lt "2" ]; then
  125. echo "Invalid number of arguments
  126. Format:
  127. $USAGE"
  128. else
  129. ROOT=$1
  130. OUTDIR=$2
  131. if [ "$#" -gt "2" ]; then
  132. SILABS_BOARD=$3
  133. shift
  134. fi
  135. shift
  136. shift
  137. while [ $# -gt 0 ]; do
  138. case $1 in
  139. --clean)
  140. DIR_CLEAN=true
  141. shift
  142. ;;
  143. --wifi)
  144. if [ -z "$2" ]; then
  145. echo "--wifi requires rs9116 or SiWx917 or wf200"
  146. exit 1
  147. fi
  148. if [ "$2" = "rs9116" ]; then
  149. optArgs+="use_rs9116=true "
  150. elif [ "$2" = "SiWx917" ]; then
  151. optArgs+="use_SiWx917=true "
  152. elif [ "$2" = "wf200" ]; then
  153. optArgs+="use_wf200=true "
  154. else
  155. echo "Wifi usage: --wifi rs9116|SiWx917|wf200"
  156. exit 1
  157. fi
  158. USE_WIFI=true
  159. optArgs+="chip_device_platform =\"efr32\" "
  160. shift
  161. shift
  162. ;;
  163. --sed)
  164. optArgs+="enable_sleepy_device=true chip_openthread_ftd=false "
  165. shift
  166. ;;
  167. --low-power)
  168. optArgs+="chip_build_libshell=false enable_openthread_cli=false show_qr_code=false disable_lcd=true "
  169. shift
  170. ;;
  171. --chip_enable_wifi_ipv4)
  172. optArgs="chip_enable_wifi_ipv4=true chip_inet_config_enable_ipv4=true "
  173. shift
  174. ;;
  175. --additional_data_advertising)
  176. optArgs+="chip_enable_additional_data_advertising=true chip_enable_rotating_device_id=true "
  177. shift
  178. ;;
  179. --use_ot_lib)
  180. optArgs+="use_silabs_thread_lib=true chip_openthread_target=$SILABS_THREAD_TARGET openthread_external_platform=\"""\" "
  181. shift
  182. ;;
  183. --use_ot_coap_lib)
  184. optArgs+="use_silabs_thread_lib=true chip_openthread_target=$SILABS_THREAD_TARGET openthread_external_platform=\"""\" use_thread_coap_lib=true "
  185. shift
  186. ;;
  187. --use_chip_lwip_lib)
  188. optArgs+="lwip_root=\""//third_party/connectedhomeip/third_party/lwip"\" "
  189. shift
  190. ;;
  191. # Option not to be used until ot-efr32 github is updated
  192. # --use_ot_github_sources)
  193. # 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\""
  194. # shift
  195. # ;;
  196. --release)
  197. 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 "
  198. shift
  199. ;;
  200. --docker)
  201. optArgs+="efr32_sdk_root=\"$GSDK_ROOT\" "
  202. USE_DOCKER=true
  203. shift
  204. ;;
  205. --uart_log)
  206. optArgs+="sl_uart_log_output=true "
  207. shift
  208. ;;
  209. --slc_generate)
  210. optArgs+="slc_generate=true "
  211. USE_SLC=true
  212. shift
  213. ;;
  214. --slc_reuse_files)
  215. optArgs+="slc_reuse_files=true "
  216. USE_SLC=true
  217. shift
  218. ;;
  219. --gn_path)
  220. if [ -z "$2" ]; then
  221. echo "--gn_path requires a path to GN"
  222. exit 1
  223. else
  224. GN_PATH="$2"
  225. fi
  226. GN_PATH_PROVIDED=true
  227. shift
  228. shift
  229. ;;
  230. *"sl_matter_version_str="*)
  231. optArgs+="$1 "
  232. USE_GIT_SHA_FOR_VERSION=false
  233. shift
  234. ;;
  235. *)
  236. if [ "$1" =~ *"use_rs9116=true"* ] || [ "$1" =~ *"use_SiWx917=true"* ] || [ "$1" =~ *"use_wf200=true"* ]; then
  237. USE_WIFI=true
  238. # NCP Mode so base MCU is an EFR32
  239. optArgs+="chip_device_platform =\"efr32\" "
  240. fi
  241. optArgs+=$1" "
  242. shift
  243. ;;
  244. esac
  245. done
  246. if [ -z "$SILABS_BOARD" ]; then
  247. echo "SILABS_BOARD not defined"
  248. exit 1
  249. fi
  250. # 917 exception. TODO find a more generic way
  251. if [ "$SILABS_BOARD" == "BRD4325B" ]; then
  252. echo "Compiling for 917 WiFi SOC"
  253. USE_WIFI=true
  254. optArgs+="chip_device_platform =\"SiWx917\" "
  255. fi
  256. if [ "$USE_GIT_SHA_FOR_VERSION" == true ]; then
  257. {
  258. ShortCommitSha=$(git describe --always --dirty --exclude '*')
  259. branchName=$(git rev-parse --abbrev-ref HEAD)
  260. optArgs+="sl_matter_version_str=\"v1.1-$branchName-$ShortCommitSha\" "
  261. } &>/dev/null
  262. fi
  263. if [ "$USE_SLC" == true ]; then
  264. PYTHON_PATH="/usr/bin/python3"
  265. if [ "$GN_PATH_PROVIDED" == false ]; then
  266. GN_PATH=./.environment/cipd/packages/pigweed/gn
  267. fi
  268. elif [ "$USE_SLC" == false ]; then
  269. # Activation needs to be after SLC generation which is done in gn gen.
  270. # Zap generation requires activation and is done in the build phase
  271. source "$CHIP_ROOT/scripts/activate.sh"
  272. PYTHON_PATH=$VIRTUAL_ENV"/bin/python3"
  273. fi
  274. BUILD_DIR=$OUTDIR/$SILABS_BOARD
  275. echo BUILD_DIR="$BUILD_DIR"
  276. if [ "$DIR_CLEAN" == true ]; then
  277. rm -rf "$BUILD_DIR"
  278. fi
  279. if [ "$USE_WIFI" == true ]; then
  280. DOTFILE="$ROOT/build_for_wifi_gnfile.gn"
  281. else
  282. DOTFILE="$ROOT/openthread.gn"
  283. fi
  284. if [ "$USE_DOCKER" == true ] && [ "$USE_WIFI" == false ]; then
  285. echo "Switching OpenThread ROOT"
  286. optArgs+="openthread_root=\"$GSDK_ROOT/util/third_party/openthread\" "
  287. fi
  288. "$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"
  289. if [ "$USE_SLC" == true ]; then
  290. # Activation needs to be after SLC generation which is done in gn gen.
  291. # Zap generation requires activation and is done in the build phase
  292. source "$CHIP_ROOT/scripts/activate.sh"
  293. fi
  294. ninja -v -C "$BUILD_DIR"/
  295. #print stats
  296. arm-none-eabi-size -A "$BUILD_DIR"/*.out
  297. fi