gn_bouffalolab_example.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. set -e
  18. # Build script for GN Bouffalolab examples GitHub workflow.
  19. MATTER_ROOT=$(dirname "$(readlink -f "$0")")/../../
  20. source "$MATTER_ROOT/scripts/activate.sh"
  21. bl602_boards=("BL602-IoT-Matter-V1" "BL602-NIGHT-LIGHT")
  22. bl602_module_type="BL602"
  23. bl702_boards=("XT-ZB6-DevKit" "BL706-NIGHT-LIGHT" "BL706-ETH" "BL706-WIFI")
  24. bl702_modules=("BL702" "BL706C-22")
  25. bl702_module_type="BL706C-22"
  26. bl702l_boards=("BL704L-DVK")
  27. bl702l_modules=("BL702L")
  28. bl702l_module_type="BL704l"
  29. print_help() {
  30. bl602_boards_help=""
  31. for board in "${bl602_boards[@]}"; do
  32. bl602_boards_help=$bl602_boards_help$board"\n "
  33. done
  34. bl702_boards_help=""
  35. for board in "${bl702_boards[@]}"; do
  36. bl702_boards_help=$bl702_boards_help$board"\n "
  37. done
  38. bl702l_boards_help=""
  39. for board in "${bl702l_boards[@]}"; do
  40. bl702l_boards_help=$bl702l_boards_help$board"\n "
  41. done
  42. echo -e "Build script for Bouffalolab Matter examples
  43. Format:
  44. ./scripts/examples/gn_bouffalolab_example.sh <Example folder> <Output folder> <Bouffalolab_board_name> [<Build options>]
  45. <Example folder>
  46. Folder of example application, e.g: lighting-app
  47. <Output folder>
  48. Desired location for the output files
  49. <Bouffalolab_board_name>
  50. Identifier of the board for which this app is built
  51. Currently Supported :
  52. $bl602_boards_help
  53. $bl702_boards_help
  54. $bl702l_boards_help
  55. <Build options> - optional noteworthy build options for Bouffalolab IOT Matter examples
  56. chip_build_libshell
  57. Enable libshell support. (Default false)
  58. chip_openthread_ftd
  59. Use openthread Full Thread Device, else, use Minimal Thread Devic. (Default true)
  60. enable_heap_monitoring
  61. Monitor & log memory usage at runtime. (Default false)
  62. setupDiscriminator
  63. Discriminatoor value used for commission. (Default 3840)
  64. setupPinCode
  65. PIN code for PASE session establishment. (Default 20202021)
  66. 'import("//with_pw_rpc.gni")'
  67. Use to build the example with pigweed RPC
  68. OTA_periodic_query_timeout
  69. Periodic query timeout variable for OTA in seconds
  70. enable_psram
  71. Enable PSRAM memory. (Default true for BL702/BL706)
  72. baudrate
  73. UART baudrate for log output and UART shell command, e.g, baudrate=2000000, by default.
  74. module_type
  75. Bouffalolab chip module.
  76. "
  77. }
  78. if [ "$#" -lt "3" ]; then
  79. print_help
  80. else
  81. example_name=$1
  82. output_folder=$2
  83. board_name=$3
  84. bouffalo_chip=
  85. module_type=
  86. baudrate=2000000
  87. optArgs=""
  88. optArgs=custom_toolchain=\"$MATTER_ROOT/config/bouffalolab/toolchain:riscv_gcc\"
  89. shift
  90. shift
  91. shift
  92. while [ $# -gt 0 ]; do
  93. if [[ "$1" == "module_type"* ]]; then
  94. module_type=$(echo "$1" | awk -F'=' '{print $2}')
  95. shift
  96. continue
  97. fi
  98. if [[ "$1" == "baudrate"* ]]; then
  99. baudrate=$(echo "$1" | awk -F'=' '{print $2}')
  100. shift
  101. continue
  102. fi
  103. optArgs=$optArgs$1" "
  104. shift
  105. done
  106. if [[ "${bl602_boards[@]}" =~ "$board_name" ]]; then
  107. bouffalo_chip="bl602"
  108. optArgs=board=\"$board_name\"" "$optArgs
  109. optArgs=module_type=\"$bl602_module_type\"" "$optArgs
  110. optArgs=baudrate=\"$baudrate\"" "$optArgs
  111. optArgs=baudrate=\"$baudrate\"" "$optArgs
  112. optArgs=chip_enable_openthread=false" "$optArgs
  113. optArgs=chip_enable_wifi=true" "$optArgs
  114. elif [[ "${bl702_boards[@]}" =~ "$board_name" ]]; then
  115. bouffalo_chip="bl702"
  116. optArgs=board=\"$board_name\"" "$optArgs
  117. if [[ "$module_type" != "" ]]; then
  118. if [[ ! "${bl702_modules[@]}" =~ "$module_type" ]]; then
  119. echo "Module $module_type is not supported."
  120. exit 1
  121. fi
  122. optArgs=module_type=\"$module_type\"" "$optArgs
  123. fi
  124. optArgs=baudrate=\"$baudrate\"" "$optArgs
  125. if [[ "$board_name" == "BL706-ETH" ]]; then
  126. optArgs=chip_config_network_layer_ble=false" "$optArgs
  127. optArgs=chip_enable_openthread=false" "$optArgs
  128. optArgs=chip_enable_wifi=false" "$optArgs
  129. elif [[ "$board_name" == "BL706-WIFI" ]]; then
  130. optArgs=chip_enable_openthread=false" "$optArgs
  131. optArgs=chip_enable_wifi=true" "$optArgs
  132. else
  133. optArgs=chip_enable_openthread=true" "$optArgs
  134. optArgs=chip_enable_wifi=false" "$optArgs
  135. fi
  136. elif [[ "${bl702l_boards[@]}" =~ "$board_name" ]]; then
  137. bouffalo_chip="bl702l"
  138. optArgs=board=\"$board_name\"" "$optArgs
  139. if [[ "$module_type" != "" ]]; then
  140. if [[ ! "${bl702l_modules[@]}" =~ "$module_type" ]]; then
  141. echo "Module $module_type is not supported."
  142. exit 1
  143. fi
  144. optArgs=module_type=\"$module_type\"" "$optArgs
  145. fi
  146. optArgs=baudrate=\"$baudrate\"" "$optArgs
  147. optArgs=chip_enable_openthread=true" "$optArgs
  148. optArgs=chip_enable_wifi=false" "$optArgs
  149. else
  150. echo "Board $board_name is not supported."
  151. exit 1
  152. fi
  153. if [[ "$BOUFFALOLAB_SDK_ROOT" == "" ]]; then
  154. echo -e "\e[31mPlease make sure Bouffalo Lab SDK installs as below:\e[0m"
  155. echo -e "\e[31m\tcd third_party/bouffalolab/repo\e[0m"
  156. echo -e "\e[31m\tsudo bash scripts/setup.sh\e[0m"
  157. echo -e "\e[31mPlease make sure BOUFFALOLAB_SDK_ROOT exports before building as below:\e[0m"
  158. echo -e "\e[31m\texport BOUFFALOLAB_SDK_ROOT=/opt/bouffalolab_sdk\e[0m"
  159. exit 1
  160. fi
  161. optArgs=$optArgs' bouffalolab_sdk_root="'$BOUFFALOLAB_SDK_ROOT'"'
  162. example_dir=$MATTER_ROOT/examples/$example_name/bouffalolab/$bouffalo_chip
  163. output_dir=$MATTER_ROOT/$output_folder
  164. gn gen --check --fail-on-unused-args --export-compile-commands --root="$example_dir" "$output_dir" --args="${optArgs[*]}"
  165. ninja -C "$output_dir"
  166. fi