NuttX 安装脚本

释放双眼,带上耳机,听听看~!

(2014年4月12日修改)
(嵌入式 实时操作系统 rtos nuttx 开发环境 交叉工具链 shell脚本)

NuttX 安装脚本

nuttx_building_v12.sh
转载请注明出处: http://www.voidcn.com/article/p-fkqcqgwg-rm.html
已测试的 Linux 发行版:
linuxmint-16-cinnamon-64bit/32bit
ubuntu-13.10-amd64/i386
debian-7.4-gnome-amd64/i386
debian-7.4-xfce-amd64/i386(要使用 Qt Creator 或 Eclipse 需额外的设置)
crunchbang-11-amd64/i686


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
1#!/bin/bash
2
3#nuttx7.1在linuxmint-16-cinnamon-64bit上测试通过
4
5#设置
6BASEDIR=`pwd`
7TOPDIR=my_nuttx
8BOARD=shenzhou
9TARGETCONFIG=shenzhou/nsh
10COMMIT=nuttx-7.1
11
12gmp_name=gmp-5.1.3.tar.xz
13mpfr_name=mpfr-3.1.2.tar.xz
14mpc_name=mpc-1.0.2.tar.gz
15binutils_name=binutils-2.24.tar.bz2
16gcc_name=gcc-4.8.2.tar.bz2
17gmp_basename=`echo $gmp_name | awk -F. 'NF-=2' OFS=.`
18mpfr_basename=`echo $mpfr_name | awk -F. 'NF-=2' OFS=.`
19mpc_basename=`echo $mpc_name | awk -F. 'NF-=2' OFS=.`
20binutils_basename=`echo $binutils_name | awk -F. 'NF-=2' OFS=.`
21gcc_basename=`echo $gcc_name | awk -F. 'NF-=2' OFS=.`
22
23#“按任意键继续。。。”的处理函数
24get_char()
25{
26  SAVEDSTTY=`stty -g`
27  stty -echo
28  stty raw
29  dd if=/dev/tty bs=1 count=1 2> /dev/null
30  stty -raw
31  stty echo
32  stty $SAVEDSTTY
33}
34
35usage()
36{
37cat <<EOF
38  -d             下载安装并创建压缩包->编译nuttx
39  -e             从本地压缩包安装->编译nuttx
40  -m             编译nuttx
41
42EOF
43}
44
45if [ -z "$1" ]; then
46  usage
47  exit 1
48fi
49
50DOWNLOAD=no
51EXTRACT=no
52MAKE_NUTTX=no
53
54while getopts debcma OPT
55do
56  case "$OPT" in
57    d) DOWNLOAD=yes; MAKE_NUTTX=yes;;
58    e) EXTRACT=yes; MAKE_NUTTX=yes;;
59    m) MAKE_NUTTX=yes;;
60    *) usage; exit 1;;
61  esac
62done
63
64
65
66if [ $DOWNLOAD = 'yes' ] || [ $EXTRACT = 'yes' ]; then
67
68echo "安装依赖项"
69sudo apt-get -d update 2>&1 | tee apt-get_update.log
70if (grep -q -E '^E:|^Err|^W:' apt-get_update.log); then
71  if (grep -q '/var/lib/apt/lists/lock' apt-get_update.log); then
72    sudo rm -vf /var/lib/apt/lists/*
73    sudo apt-get update
74    if [ $? -ne 0 ]; then
75      echo "更新源出现错误,请稍候重试1"
76      exit 1
77    fi
78  else
79    echo "更新源出现错误,请稍候重试2"
80    exit 1
81  fi
82fi
83sudo apt-get install -y git build-essential bison flex gcc-multilib zlib1g-dev gperf libncurses5-dev texinfo autoconf automake libtool curl gettext libgmp-dev pkg-config
84if [ $? -ne 0 ]; then
85  echo "安装依赖项出现错误,请稍候重试1"
86  exit 1
87fi
88sudo apt-get install -y  libgmp3-dev libmpc-dev libmpfr-dev  #linuxmint、ubuntu不需要
89if [ $? -ne 0 ]; then
90  echo "安装依赖项出现错误,请稍候重试2"
91  exit 1
92fi
93#echo "按任意键继续。。。" && char=`get_char`
94
95
96
97if [ $DOWNLOAD = 'yes' ]; then
98  echo "下载安装并创建压缩包"
99  which proz > /dev/null 2>&1
100  if [ $? -ne 0 ]; then
101  echo "安装多线程下载工具"
102    wget -c http://dxdown1.onlinedown.net/down/prozilla-2.0.4.tar.zip
103    unzip prozilla-2.0.4.tar.zip prozilla-2.0.4.tar.bz2
104    tar -xf prozilla-2.0.4.tar.bz2
105    rm prozilla-2.0.4.tar.zip prozilla-2.0.4.tar.bz2
106    cd prozilla-2.0.4
107    sed -i 's/DL_Window:://' src/download_win.h
108    ./configure
109    make
110    sudo make install
111    cd ..
112  fi
113  which proz > /dev/null 2>&1
114  if [ $? -ne 0 ]; then
115    echo "安装多线程下载工具出现错误,中止运行"
116    exit 1
117  fi
118  if [ -d "$TOPDIR" ]; then
119    echo "错误:目录$TOPDIR已经存在"
120    exit 1
121  fi
122  mkdir $TOPDIR
123  cd $TOPDIR
124
125  down_cmd='proz -k=20 '
126  host1='http://mirrors.ustc.edu.cn/gnu'
127  #host2='http://mirror.bjtu.edu.cn/gnu'
128  $down_cmd$host1/gmp/$gmp_name
129  $down_cmd$host1/mpfr/$mpfr_name
130  $down_cmd$host1/mpc/$mpc_name
131  $down_cmd$host1/binutils/$binutils_name
132  $down_cmd$host1/gcc/$gcc_basename/$gcc_name
133
134  session_id=`curl http://sourceforge.net/p/nuttx/git/ci/$COMMIT/tree/  | awk -F \" '/_session_id/{for(i=1; i<=NF; i++) if($i ~ /value/) print $i+1}'`
135  for ((i=1; i<=10; i++)); do
136    echo "获取http下载地址第$i次尝试"
137    nuttx_http_url=`curl -d "path=&_session_id=$session_id" http://sourceforge.net/p/nuttx/git/ci/$COMMIT/tarball | awk -F \' '/window.location.href/{for(i=1; i<=NF; i++) if($i ~ /nuttx-git-/) print $i}'`
138    if [ -n "$nuttx_http_url" ]; then
139      break
140    fi
141    sleep 4s
142  done
143  echo "nuttx_http_url=$nuttx_http_url"
144
145  $down_cmd$nuttx_http_url
146  if [ $? -ne 0 ]; then
147    echo "http下载失败,使用git下载"
148    git clone -b $COMMIT git://git.code.sf.net/p/nuttx/git nuttx-code
149    if [ $? -ne 0 ]; then
150      echo "git下载失败,中止执行"
151      exit 1
152    fi
153    mv nuttx-code/* .
154    rm -rf nuttx-code
155  else
156    nuttx_http_pkg=`echo $nuttx_http_url | awk -F '/' '{print $NF}'`
157    nuttx_http_dir=`echo $nuttx_http_pkg | awk -F '.' '{print $1}'`
158    unzip -q $nuttx_http_pkg
159    mv $nuttx_http_dir/* .
160    rm -rf $nuttx_http_pkg $nuttx_http_dir
161  fi
162
163  cd ..
164  echo "打包..."
165  tar -zcf $TOPDIR-$(date +%Y%m%d-%H%M%S).tar.gz $TOPDIR
166                    
167else
168  echo "从本地压缩包安装"
169  nuttx_pkg=`find . -maxdepth 1 -type f -name "$TOPDIR-????????-??????.tar.gz" | sort -r | head -1`
170  if [ -z "$nuttx_pkg" ]; then
171    echo "错误:没有找到压缩包,中止执行"
172    exit 1
173  fi
174  if [ -d "$TOPDIR" ]; then
175    echo "错误:目录$TOPDIR已经存在"
176    exit 1
177  fi
178  echo "解包..."
179  tar -xf $nuttx_pkg
180fi
181#echo "按任意键继续。。。" && char=`get_char`
182
183echo "编译安装kconfig-frontends"
184cd $BASEDIR/$TOPDIR/misc/tools/kconfig-frontends
185./bootstrap
186./configure --enable-mconf
187LD_RUN_PATH=/usr/local/lib make
188if [ $? -ne 0 ]; then
189  echo "编译安装kconfig-frontends出现错误,中止执行"
190  exit 1
191fi
192#echo "按任意键继续。。。" && char=`get_char`
193sudo make install
194
195echo "编译库"
196cd $BASEDIR/$TOPDIR
197tar -xf $gmp_name
198tar -xf $mpfr_name
199tar -xf $mpc_name
200
201mkdir b-gmp
202cd b-gmp
203../$gmp_basename/configure && make && sudo make install
204cd ..
205mkdir b-mpfr
206cd b-mpfr
207../$mpfr_basename/configure && make && sudo make install
208cd ..
209mkdir b-mpc
210cd b-mpc
211../$mpc_basename/configure && make && sudo make install
212cd ..
213
214echo "nuttx配置"
215cd $BASEDIR/$TOPDIR/nuttx/tools
216./configure.sh $TARGETCONFIG
217if [ $? -ne 0 ]; then
218  echo "nuttx配置出现错误,中止执行"
219  exit 1
220fi
221
222echo "删除多余的目录"
223cd $BASEDIR/$TOPDIR/nuttx
224cp -r ../nuttx ../nuttx_backup
225
226del_dir=`find configs -maxdepth 1 -type d`
227del_dir=`echo $del_dir | sed "s,configs,,"`
228del_dir=`echo $del_dir | sed "s,configs/$BOARD,,"`
229for i in $del_dir; do
230  echo "删除$i"
231  rm -rf $i
232  sed -i "s,^source \"$i/Kconfig\",# &," configs/Kconfig
233done
234
235del_dir=`find arch -maxdepth 1 -type d`
236del_dir=`echo $del_dir | sed "s,arch,,"`
237retain_dir=`awk -F \" '/^CONFIG_ARCH=/{print $2}' .config`
238del_dir=`echo $del_dir | sed "s,arch/$retain_dir,,"`
239for i in $del_dir; do
240  echo "删除$i"
241  rm -rf $i
242  sed -i "s,^source $i/Kconfig,# &," arch/Kconfig
243done
244
245if [ $retain_dir="arm" ]; then
246  del_dir=`find arch/arm/src -maxdepth 1 -type d`
247  del_dir=`echo $del_dir | sed "s,arch/arm/src,,"`
248  del_dir=`echo $del_dir | sed "s,arch/arm/src/common,,"`
249  retain_dir=`awk -F \" '/^CONFIG_ARCH_FAMILY=/{print $2}' .config`
250  del_dir=`echo $del_dir | sed "s,arch/arm/src/$retain_dir,,"`
251  retain_dir=`awk -F \" '/^CONFIG_ARCH_CHIP=/{print $2}' .config`
252  del_dir=`echo $del_dir | sed "s,arch/arm/src/$retain_dir,,"`
253  for i in $del_dir; do
254    echo "删除$i"
255    rm -rf $i
256    sed -i "s,^source $i/Kconfig,# &," arch/arm/Kconfig
257  done
258fi
259#echo "按任意键继续。。。" && char=`get_char`
260
261echo "编译buildroot"
262cd $BASEDIR/$TOPDIR/nuttx
263sed -i 's,^CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y,# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW is not set,' .config
264sed -i 's,^# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set,CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT=y,' .config
265make context
266if [ $? -ne 0 ]; then
267  echo "编译buildroot出现错误,中止执行1"
268  exit 1
269fi
270#echo "按任意键继续。。。" && char=`get_char`
271
272cd $BASEDIR/$TOPDIR/misc/buildroot
273sed -i 's,$(WGET) -P $(DL_DIR) $(BINUTILS_SITE)/$(BINUTILS_SOURCE),mv $(TOPDIR)/../../$(BINUTILS_SOURCE) $(DL_DIR),' toolchain/binutils/binutils.mk
274sed -i 's,$(WGET) -P $(DL_DIR) $(GCC_SITE)/$(GCC_SOURCE),mv $(TOPDIR)/../../$(GCC_SOURCE) $(DL_DIR),' toolchain/gcc/gcc-nuttx-4.x.mk
275cp configs/cortexm3-eabi-defconfig-4.8.2 .config
276sed -i 's,BR2_PACKAGE_NXFLAT=y,# BR2_PACKAGE_NXFLAT is not set,' .config
277sed -i '/BR2_PACKAGE_GENROMFS/a# BR2_PACKAGE_KCONFIG_FRONTENDS is not set\n# BR2_NCONF_FRONTEND is not set\n# BR2_GCONF_FRONTEND is not set\n# BR2_QCONF_FRONTEND is not set' .config
278
279make oldconfig
280if [ $? -ne 0 ]; then
281  echo "编译buildroot出现错误,中止执行2"
282  exit 1
283fi
284#echo "按任意键继续。。。" && char=`get_char`
285make
286if [ $? -ne 0 ]; then
287  echo "编译buildroot出现错误,中止执行3"
288  exit 1
289fi
290#echo "按任意键继续。。。" && char=`get_char`
291
292fi  #end [ $DOWNLOAD = 'yes' ] || [ $EXTRACT = 'yes' ]
293
294
295
296if [ $MAKE_NUTTX = 'yes' ]; then
297
298echo "编译nuttx"
299cd $BASEDIR/$TOPDIR/nuttx
300sed -i 's,^# CONFIG_RAW_BINARY is not set,CONFIG_RAW_BINARY=y,' .config
301sed -i 's,^CONFIG_TASK_NAME_SIZE=0,CONFIG_TASK_NAME_SIZE=16,' .config
302sed -i 's,^CONFIG_NSH_IPADDR=0x0a000002,CONFIG_NSH_IPADDR=0xc0a8020a,' .config    #192.168.2.10
303sed -i 's,^CONFIG_NSH_DRIPADDR=0x0a000001,CONFIG_NSH_DRIPADDR=0xc0a80201,' .config    #192.168.2.1
304if !(grep -q '  @echo "DUMP: $(BIN).out"' Makefile.unix); then
305  sed -i '/pass2:/,/^$/{
306    /^$/i\   @echo "DUMP: $(BIN).out"
307    /^$/i\   $(Q) $(OBJDUMP) -x $(BIN) > $(HOME)/$(BIN).out
308    /^$/i\   @echo "DUMP: $(BIN).S"
309    /^$/i\   $(Q) $(OBJDUMP) -d -j .text -j .init_section -j .ARM.exidx -j .data -j .bss $(BIN) > $(HOME)/$(BIN).S
310    /^$/i\   cp -f $(BIN) $(BIN).hex $(BIN).bin $(HOME)
311  }' Makefile.unix
312fi
313
314TOOLCHAIN_BIN=$BASEDIR/$TOPDIR/misc/buildroot/build_arm_nofpu/staging_dir/bin
315TOOLS_DIR=$BASEDIR/$TOPDIR/nuttx/configs/$BOARD/tools
316if !(grep -q "PATH=\"$TOOLCHAIN_BIN:$TOOLS_DIR:\$PATH\"" $HOME/.profile); then
317  echo >> $HOME/.profile
318  echo PATH=\"$TOOLCHAIN_BIN:$TOOLS_DIR:\$PATH\" >> $HOME/.profile  #重起生效
319fi
320if !(echo $PATH | grep -q "$TOOLCHAIN_BIN:$TOOLS_DIR"); then
321  export PATH=$TOOLCHAIN_BIN:$TOOLS_DIR:$PATH
322fi
323
324make
325
326fi  #end MAKE_NUTTX
327
328time=$SECONDS
329hour=$[$time/3600]
330min=$[$[$time/60]%60]
331sec=$[$time%60]
332echo "执行时间:$hour小时$min分$sec秒"
333

使用上述脚本安装 NuttX 之后,在 Qt Creator 或 Eclipse 中以导入现有项目的方式新建项目,无需其它设置,点击构建按钮即可进行编译。

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

详解Node.js API系列C/C++ Addons(1) API文档

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索