refresh.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #!/usr/bin/env bash
  2. # tools/refresh.sh
  3. #
  4. # Copyright (C) 2014, 2016-2017, 2019 Gregory Nutt. All rights reserved.
  5. # Author: Gregory Nutt <gnutt@nuttx.org>
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. #
  11. # 1. Redistributions of source code must retain the above copyright
  12. # notice, this list of conditions and the following disclaimer.
  13. # 2. Redistributions in binary form must reproduce the above copyright
  14. # notice, this list of conditions and the following disclaimer in
  15. # the documentation and/or other materials provided with the
  16. # distribution.
  17. # 3. Neither the name NuttX nor the names of its contributors may be
  18. # used to endorse or promote products derived from this software
  19. # without specific prior written permission.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. # POSSIBILITY OF SUCH DAMAGE.
  33. #
  34. WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
  35. USAGE="USAGE: $0 [options] <board>:<config>+"
  36. ADVICE="Try '$0 --help' for more information"
  37. unset CONFIGS
  38. diff=0
  39. debug=n
  40. defaults=n
  41. prompt=y
  42. nocopy=n
  43. while [ ! -z "$1" ]; do
  44. case $1 in
  45. --debug )
  46. debug=y
  47. ;;
  48. --silent )
  49. defaults=y
  50. prompt=n
  51. ;;
  52. --prompt )
  53. prompt=y
  54. ;;
  55. --defaults )
  56. defaults=y
  57. ;;
  58. --nocopy )
  59. nocopy=y
  60. ;;
  61. --help )
  62. echo "$0 is a tool for refreshing board configurations"
  63. echo ""
  64. echo $USAGE
  65. echo ""
  66. echo "Where [options] include:"
  67. echo " --debug"
  68. echo " Enable script debug"
  69. echo " --silent"
  70. echo " Update board configuration without interaction. Implies --defaults."
  71. echo " Assumes no prompt for save. Use --silent --prompt to prompt before saving."
  72. echo " --prompt"
  73. echo " Prompt before updating and overwriting the defconfig file. Default is to"
  74. echo " prompt unless --silent"
  75. echo " --defaults"
  76. echo " Do not prompt for new default selections; accept all recommended default values"
  77. echo " --nocopy"
  78. echo " Do not copy defconfig from nuttx/boards/<board>/configs to nuttx/.config"
  79. echo " --help"
  80. echo " Show this help message and exit"
  81. echo " <board>"
  82. echo " The board directory under nuttx/boards"
  83. echo " <config>"
  84. echo " The board configuration directory under nuttx/boards/<board>/configs"
  85. echo " Note: all configuration is refreshed if <board>:<config> equals all."
  86. exit 0
  87. ;;
  88. * )
  89. CONFIGS=$*
  90. break
  91. ;;
  92. esac
  93. shift
  94. done
  95. # Where are we
  96. MYNAME=`basename $0`
  97. cd $WD
  98. if [ -x ./${MYNAME} ] ; then
  99. cd .. || { echo "ERROR: cd .. failed" ; exit 1 ; }
  100. fi
  101. if [ ! -x tools/${MYNAME} ] ; then
  102. echo "ERROR: This file must be executed from the top-level NuttX directory: $PWD"
  103. exit 1
  104. fi
  105. # Get the board configuration
  106. if [ -z "${CONFIGS}" ]; then
  107. echo "ERROR: No configuration provided"
  108. echo $USAGE
  109. echo $ADVICE
  110. exit 1
  111. fi
  112. if [ "X${CONFIGS}" == "Xall" ]; then
  113. CONFIGS=`find boards -name defconfig | cut -d'/' -f4,6`
  114. fi
  115. for CONFIG in ${CONFIGS}; do
  116. echo " Normalize ${CONFIG}"
  117. # Set up the environment
  118. CONFIGSUBDIR=`echo ${CONFIG} | cut -s -d':' -f2`
  119. if [ -z "${CONFIGSUBDIR}" ]; then
  120. CONFIGSUBDIR=`echo ${CONFIG} | cut -s -d'/' -f2`
  121. if [ -z "${CONFIGSUBDIR}" ]; then
  122. echo "ERROR: Malformed configuration: ${CONFIG}"
  123. echo $USAGE
  124. echo $ADVICE
  125. exit 1
  126. else
  127. BOARDSUBDIR=`echo ${CONFIG} | cut -d'/' -f1`
  128. fi
  129. else
  130. BOARDSUBDIR=`echo ${CONFIG} | cut -d':' -f1`
  131. fi
  132. BOARDDIR=boards/*/*/$BOARDSUBDIR
  133. SCRIPTSDIR=$BOARDDIR/scripts
  134. MAKEDEFS1=$SCRIPTSDIR/Make.defs
  135. CONFIGDIR=$BOARDDIR/configs/$CONFIGSUBDIR
  136. DEFCONFIG=$CONFIGDIR/defconfig
  137. MAKEDEFS2=$CONFIGDIR/Make.defs
  138. # Check the board configuration directory
  139. if [ ! -d $BOARDDIR ]; then
  140. echo "No board directory found at $BOARDDIR"
  141. exit 1
  142. fi
  143. if [ ! -d $CONFIGDIR ]; then
  144. echo "No configuration directory found at $CONFIGDIR"
  145. exit 1
  146. fi
  147. if [ ! -r $DEFCONFIG ]; then
  148. echo "No readable defconfig file at $DEFCONFIG"
  149. exit 1
  150. fi
  151. if [ -r $MAKEDEFS2 ]; then
  152. MAKEDEFS=$MAKEDEFS2
  153. else
  154. if [ -r $MAKEDEFS1 ]; then
  155. MAKEDEFS=$MAKEDEFS1
  156. else
  157. echo "No readable Make.defs file at $MAKEDEFS1 or $MAKEDEFS2"
  158. exit 1
  159. fi
  160. fi
  161. # Copy the .config and Make.defs to the toplevel directory
  162. rm -f SAVEconfig
  163. rm -f SAVEMake.defs
  164. if [ "X${nocopy}" != "Xy" ]; then
  165. if [ -e .config ]; then
  166. mv .config SAVEconfig || \
  167. { echo "ERROR: Failed to move .config to SAVEconfig"; exit 1; }
  168. fi
  169. cp -a $DEFCONFIG .config || \
  170. { echo "ERROR: Failed to copy $DEFCONFIG to .config"; exit 1; }
  171. if [ -e Make.defs ]; then
  172. mv Make.defs SAVEMake.defs || \
  173. { echo "ERROR: Failed to move Make.defs to SAVEMake.defs"; exit 1; }
  174. fi
  175. cp -a $MAKEDEFS Make.defs || \
  176. { echo "ERROR: Failed to copy $MAKEDEFS to Make.defs"; exit 1; }
  177. # Then run oldconfig or oldefconfig
  178. if [ "X${defaults}" == "Xy" ]; then
  179. if [ "X${debug}" == "Xy" ]; then
  180. make olddefconfig V=1
  181. else
  182. make olddefconfig 1>/dev/null
  183. fi
  184. else
  185. if [ "X${debug}" == "Xy" ]; then
  186. make oldconfig V=1
  187. else
  188. make oldconfig
  189. fi
  190. fi
  191. fi
  192. # Run savedefconfig to create the new defconfig file
  193. if [ "X${debug}" == "Xy" ]; then
  194. make savedefconfig V=1
  195. else
  196. make savedefconfig 1>/dev/null
  197. fi
  198. # Show differences
  199. if ! diff $DEFCONFIG defconfig; then
  200. # Save the refreshed configuration
  201. if [ "X${prompt}" == "Xy" ]; then
  202. read -p "Save the new configuration (y/n)?" -n 1 -r
  203. echo
  204. if [[ $REPLY =~ ^[Yy]$ ]]; then
  205. echo "Saving the new configuration file"
  206. mv defconfig $DEFCONFIG || \
  207. { echo "ERROR: Failed to move defconfig to $DEFCONFIG"; exit 1; }
  208. chmod 644 $DEFCONFIG
  209. fi
  210. else
  211. echo "Saving the new configuration file"
  212. mv defconfig $DEFCONFIG || \
  213. { echo "ERROR: Failed to move defconfig to $DEFCONFIG"; exit 1; }
  214. chmod 644 $DEFCONFIG
  215. fi
  216. diff=1
  217. fi
  218. # Restore any previous .config and Make.defs files
  219. if [ -e SAVEMake.defs ]; then
  220. mv SAVEMake.defs Make.defs || \
  221. { echo "ERROR: Failed to move SAVEMake.defs to Make.defs"; exit 1; }
  222. fi
  223. if [ -e SAVEconfig ]; then
  224. mv SAVEconfig .config || \
  225. { echo "ERROR: Failed to move SAVEconfig to .config"; exit 1; }
  226. if [ "X${debug}" == "Xy" ]; then
  227. ./tools/sethost.sh V=1
  228. else
  229. ./tools/sethost.sh 1>/dev/null
  230. fi
  231. fi
  232. done
  233. exit $diff