成功的在ubuntu12.04上建立RTT交叉编译环境

74 views
Skip to first unread message

xp...@sina.com

unread,
Jul 26, 2012, 3:12:19 PM7/26/12
to rt-thread-cnusers
 今天尝试了一下在linux下建立RTT的交叉编译环境,下面分享一下我的建立步骤。

第一步:安装scons.命令:(sudo apt-get install scons
第二步:安装工具链,arm交叉编译器(Sourcery_CodeBench_Lite_for_ARM_EABI 的arm-2012.03-56-arm-none-eabi.bin版本),这个编译找不到的话就自己google吧。安装这个工具有几个地方需要注意一下——(安装目录要记住,然后配置PATH),我安装在/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI下,所以我的PATH添加了/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin
第三布:获取源代码,我是从SVN上取下来的。所以我安装了SVN,命令(sudo apt-get install subversion
第四步:将bsp里面的rtconfig.py文件的编译工具设为gcc,路径设为刚才安装Sourcery_CodeBench_Lite_for_ARM_EABI时的路径也即/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin,和添加到PATH中的路径一样。
第五步:直接在bsp的对于目录下scons吧!
最后你就等着笑吧 !

arm-none-eabi-objcopy -O binary rtthread-stm32.axf rtthread.bin
arm-none-eabi-size rtthread-stm32.axf
   text       data        bss        dec        hex    filename
 157888        248      18200     176336      2b0d0    rtthread-stm32.axf
scons: done building targets.

魏伟

unread,
Jul 26, 2012, 7:59:25 PM7/26/12
to rt-threa...@googlegroups.com
调试方便吗?

Grissiom

unread,
Jul 26, 2012, 8:09:44 PM7/26/12
to rt-threa...@googlegroups.com
恭喜楼主。

不过按说是可以不修改系统 PATH 的,楼主可以试试不修改系统 PATH,把 rtconfig.py 里的 EXEC_PATH 改好。

2012/7/27 <xp...@sina.com>



--
Cheers,
Grissiom

老新手

unread,
Jul 26, 2012, 8:13:15 PM7/26/12
to rt-threa...@googlegroups.com
第二步:比较奇怪的是,codesourcery 安装后,在.bash_profile中有这么一句:
# Do NOT modify these lines; they are used to uninstall.
PATH="/home/USER/CodeSourcery/Sourcery_G++_Lite/bin:${PATH}"
这一句不是将路径加入环境变量中吗?为什么是uninstall时使用。
实际结果确实是PATH中没有这个路径,需要手动添加。
 
第四步:里面的gcc应为arm-none-linux-gnueabi-gcc吧?

Grissiom

unread,
Jul 26, 2012, 8:42:23 PM7/26/12
to rt-threa...@googlegroups.com
2012/7/27 老新手 <oldxi...@sina.com>
第二步:比较奇怪的是,codesourcery 安装后,在.bash_profile中有这么一句:
# Do NOT modify these lines; they are used to uninstall.
PATH="/home/USER/CodeSourcery/Sourcery_G++_Lite/bin:${PATH}"
这一句不是将路径加入环境变量中吗?为什么是uninstall时使用。
实际结果确实是PATH中没有这个路径,需要手动添加。

codesourcery 竟然会修改 .bash_profile ,不厚道啊……

嗯,大概明白为什么必须要在 PATH 里添加路径了。咱们可以修改下 building.py 让用户可以不修改 PATH 的~
 
 
第四步:里面的gcc应为arm-none-linux-gnueabi-gcc吧?
----- Original Message -----
Sent: Friday, July 27, 2012 3:12 AM
Subject: 成功的在ubuntu12.04上建立RTT交叉编译环境

 今天尝试了一下在linux下建立RTT的交叉编译环境,下面分享一下我的建立步骤。

第一步:安装scons.命令:(sudo apt-get install scons
第二步:安装工具链,arm交叉编译器(Sourcery_CodeBench_Lite_for_ARM_EABI 的arm-2012.03-56-arm-none-eabi.bin版本),这个编译找不到的话就自己google吧。安装这个工具有几个地方需要注意一下——(安装目录要记住,然后配置PATH),我安装在/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI下,所以我的PATH添加了/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin
第三布:获取源代码,我是从SVN上取下来的。所以我安装了SVN,命令(sudo apt-get install subversion
第四步:将bsp里面的rtconfig.py文件的编译工具设为gcc,路径设为刚才安装Sourcery_CodeBench_Lite_for_ARM_EABI时的路径也即/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin,和添加到PATH中的路径一样。
第五步:直接在bsp的对于目录下scons吧!
最后你就等着笑吧 !

arm-none-eabi-objcopy -O binary rtthread-stm32.axf rtthread.bin
arm-none-eabi-size rtthread-stm32.axf
   text       data        bss        dec        hex    filename
 157888        248      18200     176336      2b0d0    rtthread-stm32.axf
scons: done building targets.




--
Cheers,
Grissiom

bernard

unread,
Jul 26, 2012, 8:57:29 PM7/26/12
to rt-threa...@googlegroups.com

确实可以做一个先从PATH环境变量中先取得的操作,如果没有则用指定的。或者是反过来

~~from android phone

prife

unread,
Jul 26, 2012, 9:32:03 PM7/26/12
to rt-threa...@googlegroups.com
在 2012年7月27日 上午8:42,Grissiom <chaos....@gmail.com>写道:
2012/7/27 老新手 <oldxi...@sina.com>
第二步:比较奇怪的是,codesourcery 安装后,在.bash_profile中有这么一句:
# Do NOT modify these lines; they are used to uninstall.
PATH="/home/USER/CodeSourcery/Sourcery_G++_Lite/bin:${PATH}"
这一句不是将路径加入环境变量中吗?为什么是uninstall时使用。
实际结果确实是PATH中没有这个路径,需要手动添加。

codesourcery 竟然会修改 .bash_profile ,不厚道啊……


To Grissiom:
1.这个 bash_profile不就是让人改的么。
2. 安装 Sourcery_G++_Lite的时候,有选项决定是否修改PATH。
不把arm-gcc加入到path中也是可以的,只要修改 bsp下的rtconfig.py即可。

to 魏伟 

3. 调试很方便

ps:把编译器安装到系统路径不是好选择啊,看情况楼主是root权限安装的,一般来说,/home占一个分区,这样我们就可以无缝升级系统,或者更换linux系统。所以程序还是安装到 /home下比较好。

嗯,大概明白为什么必须要在 PATH 里添加路径了。咱们可以修改下 building.py 让用户可以不修改 PATH 的~
 
 
第四步:里面的gcc应为arm-none-linux-gnueabi-gcc吧?
----- Original Message -----
Sent: Friday, July 27, 2012 3:12 AM
Subject: 成功的在ubuntu12.04上建立RTT交叉编译环境

 今天尝试了一下在linux下建立RTT的交叉编译环境,下面分享一下我的建立步骤。

第一步:安装scons.命令:(sudo apt-get install scons
第二步:安装工具链,arm交叉编译器(Sourcery_CodeBench_Lite_for_ARM_EABI 的arm-2012.03-56-arm-none-eabi.bin版本),这个编译找不到的话就自己google吧。安装这个工具有几个地方需要注意一下——(安装目录要记住,然后配置PATH),我安装在/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI下,所以我的PATH添加了/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin
第三布:获取源代码,我是从SVN上取下来的。所以我安装了SVN,命令(sudo apt-get install subversion
第四步:将bsp里面的rtconfig.py文件的编译工具设为gcc,路径设为刚才安装Sourcery_CodeBench_Lite_for_ARM_EABI时的路径也即/usr/share/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin,和添加到PATH中的路径一样。
第五步:直接在bsp的对于目录下scons吧!
最后你就等着笑吧 !

arm-none-eabi-objcopy -O binary rtthread-stm32.axf rtthread.bin
arm-none-eabi-size rtthread-stm32.axf
   text       data        bss        dec        hex    filename
 157888        248      18200     176336      2b0d0    rtthread-stm32.axf
scons: done building targets.




--
Cheers,
Grissiom



--
把有限的时间投入到无限的学习中去

Ming Bai

unread,
Jul 26, 2012, 9:47:50 PM7/26/12
to rt-threa...@googlegroups.com

ps:把编译器安装到系统路径不是好选择啊,看情况楼主是root权限安装的,一般来说,/home占一个分区,这样我们就可以无缝升级系统,或者更换linux系统。所以程序还是安装到 /home下比较好。

按照FHS一般这种软件放到/opt比较好,我一般放在 ~/opt/ 

老新手

unread,
Jul 26, 2012, 9:58:45 PM7/26/12
to rt-threa...@googlegroups.com
自动修改.bash_profile 是我期望它这样做的。
但不理解的是为什么它已经添加了路径,但使用export却看不到,还要手动再修改一下.bashrc文件
 
我在网上查到的资料是:
  bash在用户起始目录下按顺序查找三个特殊文件中的一个:

    /.bash_profile、(不一定存在)
    /.bash_login、 (不一定存在)
    /.profile,(最好用这一个)
   但只执行最先找到的一个

谁能给分析一下。

Ming Bai

unread,
Jul 26, 2012, 10:05:54 PM7/26/12
to rt-threa...@googlegroups.com


2012/7/27 老新手 <oldxi...@sina.com>

自动修改.bash_profile 是我期望它这样做的。
但不理解的是为什么它已经添加了路径,但使用export却看不到,还要手动再修改一下.bashrc文件
因为不是login shell 

prife

unread,
Jul 26, 2012, 10:06:49 PM7/26/12
to rt-threa...@googlegroups.com
在 2012年7月27日 上午9:58,老新手 <oldxi...@sina.com>写道:
自动修改.bash_profile 是我期望它这样做的。
但不理解的是为什么它已经添加了路径,但使用export却看不到,还要手动再修改一下.bashrc文件
 
我在网上查到的资料是:
  bash在用户起始目录下按顺序查找三个特殊文件中的一个:

    /.bash_profile、(不一定存在)
    /.bash_login、 (不一定存在)
    /.profile,(最好用这一个)
   但只执行最先找到的一个

谁能给分析一下。

其实很简单: 请打开一下 .bashrc文件,搜索一下 .bash_profile下,在笔者的 .bashrc中,没有 bash_profile语句,所以笔者自行添加如下语句。

108 
109 if [ -f ~/.bash_profile ]; then 
110     . ~/.bash_profile 
111 fi 

这样,在bash_profile中的语句就有效了。



--
把有限的时间投入到无限的学习中去

Ming Bai

unread,
Jul 26, 2012, 10:09:11 PM7/26/12
to rt-threa...@googlegroups.com


2012/7/27 prife <gop...@gmail.com>

在 2012年7月27日 上午9:58,老新手 <oldxi...@sina.com>写道:
自动修改.bash_profile 是我期望它这样做的。
但不理解的是为什么它已经添加了路径,但使用export却看不到,还要手动再修改一下.bashrc文件
 
我在网上查到的资料是:
  bash在用户起始目录下按顺序查找三个特殊文件中的一个:

    /.bash_profile、(不一定存在)
    /.bash_login、 (不一定存在)
    /.profile,(最好用这一个)
   但只执行最先找到的一个

谁能给分析一下。

其实很简单: 请打开一下 .bashrc文件,搜索一下 .bash_profile下,在笔者的 .bashrc中,没有 bash_profile语句,所以笔者自行添加如下语句。

108 
109 if [ -f ~/.bash_profile ]; then 
110     . ~/.bash_profile 
111 fi 

这样,在bash_profile中的语句就有效了。
$bash -l 

老新手

unread,
Jul 26, 2012, 10:30:21 PM7/26/12
to rt-threa...@googlegroups.com
谢谢两位的回答。
好似明白了,.bashrc是根,.bash_profile的调用是从这里来的。
.profile 应该不是从.bashrc来的。因为只用使用终端时.bashrc才起作用。它也是系统默认的一个文件。不知道对不对。
 
 
另外:ubuntu 12.04下
$ bash -l
.bashrc: command not found

Ming Bai

unread,
Jul 26, 2012, 10:49:59 PM7/26/12
to rt-threa...@googlegroups.com
$man bash
...
       When  bash  is  invoked  as  an interactive login shell, or as a non-interactive shell with the --login option, it
       first reads and executes commands from the file /etc/profile, if that file exists.  After reading  that  file,  it
       looks  for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the
       first one that exists and is readable.  The --noprofile option may be used when the shell is  started  to  inhibit
       this behavior.

       When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

       When  an  interactive  shell  that  is  not  a  login  shell  is  started,  bash  reads and executes commands from
       /etc/bash.bashrc and ~/.bashrc, if these files exist.  This may be inhibited by  using  the  --norc  option.   The
       --rcfile  file  option  will  force  bash  to  read and execute commands from file instead of /etc/bash.bashrc and
       ~/.bashrc.


2012/7/27 老新手 <oldxi...@sina.com>

老新手

unread,
Jul 26, 2012, 10:55:18 PM7/26/12
to rt-threa...@googlegroups.com
哦。正解在这里。网上说的顺序有误。应该是.profile最先。
怎么就没想到man bash呢。
谢谢。

老新手

unread,
Jul 26, 2012, 10:57:39 PM7/26/12
to rt-threa...@googlegroups.com
看错了。唉。
留着晚些时候慢慢仔细看。

prife

unread,
Jul 28, 2012, 6:48:02 AM7/28/12
to rt-threa...@googlegroups.com
为了读一个很长的shell脚本,今天又把learning bash shell翻出来读

看到这一段:

.bash_profile is read and executed only by the login shell. If you start up a new shell (a subshell) by
typing bash on the command line, it will attempt to read commands from the file .bashrc. This
scheme allows you the flexibility to separate startup commands needed at login time from those you
might need when you run a subshell. If you need to have the same commands run regardless of
whether it is a login shell or a subshell, you can just use the source command from within
.bash_profile to execute .bashrc. If .bashrc doesn't exist then no commands are executed when you
start up a subshell.
The file .bash_logout is read and executed every time a login shell exits. It is provided to round out
the capabilities for customizing your environment. If you wanted to execute some commands that
remove temporary files from your account or record how much time you have spent logged in to the
system then you would place the commands in .bash_logout. This file doesn't have to exist in your
account—if it isn't there when you log out, then no extra commands are executed.


另外:ubuntu 12.04

$bash -l 

运行正常,没有任何问题,还有,根据上面的描述, 把 source .bash_profile放到 bashrc里没有问题的(之前我是瞎蒙的,根本没想到login shell的问题)。



2012/7/27 老新手 <oldxi...@sina.com>



--
把有限的时间投入到无限的学习中去

Grissiom

unread,
Jul 28, 2012, 7:21:36 AM7/28/12
to rt-threa...@googlegroups.com
2012/7/27 prife <gop...@gmail.com>

在 2012年7月27日 上午8:42,Grissiom <chaos....@gmail.com>写道:
2012/7/27 老新手 <oldxi...@sina.com>
第二步:比较奇怪的是,codesourcery 安装后,在.bash_profile中有这么一句:
# Do NOT modify these lines; they are used to uninstall.
PATH="/home/USER/CodeSourcery/Sourcery_G++_Lite/bin:${PATH}"
这一句不是将路径加入环境变量中吗?为什么是uninstall时使用。
实际结果确实是PATH中没有这个路径,需要手动添加。

codesourcery 竟然会修改 .bash_profile ,不厚道啊……


To Grissiom:
1.这个 bash_profile不就是让人改的么。

这个东西是让人改的,但是不是让别人改的,是让我自己改的,连权限都要是 rw------- 的。虽然自己几乎所有的配置文件都用 git 管理并且托管在 github 上了,但是我怎么知道这个东西在修改的同时不会破坏别的东西,修改的方式是不是我自己的风格?更何况它有个注释:

# Do NOT modify these lines; they are used to uninstall.

这个 these 指的是 哪些 行?它改了之后我还不能改?……

况且,或许用户并不是用 bash 呢?当然没在 Linux 里用过 codesourcery ,可能它会自动判断 shell 或者提供选项之类的,那我就乌龙了,嘿嘿嘿……
 
2. 安装 Sourcery_G++_Lite的时候,有选项决定是否修改PATH。
不把arm-gcc加入到path中也是可以的,只要修改 bsp下的rtconfig.py即可。


试过?在我的 win7 上是不行的……



--
Cheers,
Grissiom

prife

unread,
Jul 28, 2012, 8:05:04 AM7/28/12
to rt-threa...@googlegroups.com
在 2012年7月28日 下午7:21,Grissiom <chaos....@gmail.com>写道:
2012/7/27 prife <gop...@gmail.com>
在 2012年7月27日 上午8:42,Grissiom <chaos....@gmail.com>写道:
2012/7/27 老新手 <oldxi...@sina.com>
第二步:比较奇怪的是,codesourcery 安装后,在.bash_profile中有这么一句:
# Do NOT modify these lines; they are used to uninstall.
PATH="/home/USER/CodeSourcery/Sourcery_G++_Lite/bin:${PATH}"
这一句不是将路径加入环境变量中吗?为什么是uninstall时使用。
实际结果确实是PATH中没有这个路径,需要手动添加。

codesourcery 竟然会修改 .bash_profile ,不厚道啊……


To Grissiom:
1.这个 bash_profile不就是让人改的么。

这个东西是让人改的,但是不是让别人改的,是让我自己改的,连权限都要是 rw------- 的。虽然自己几乎所有的配置文件都用 git 管理并且托管在 github 上了,但是我怎么知道这个东西在修改的同时不会破坏别的东西,修改的方式是不是我自己的风格?更何况它有个注释:

# Do NOT modify these lines; they are used to uninstall.

这个 these 指的是 哪些 行?它改了之后我还不能改?……

况且,或许用户并不是用 bash 呢?当然没在 Linux 里用过 codesourcery ,可能它会自动判断 shell 或者提供选项之类的,那我就乌龙了,嘿嘿嘿……

1. codesoucery安装到时候有选项让你决定是否添加到系统路径里去,如果勾选了之后,自然是授权它修改了啊。
2. 权限是 rw------- 就更没有问题了,既然安装程序是当前用户启动的,它自然对用户的配置文件具有rw权限。除非你这样 
su user2 
user2 $ ./startup.sh
然后安装路径选择到  user1下..    
:-)
 
 
2. 安装 Sourcery_G++_Lite的时候,有选项决定是否修改PATH。
不把arm-gcc加入到path中也是可以的,只要修改 bsp下的rtconfig.py即可。


 
试过?在我的 win7 上是不行的……


ubuntu上:

prife@smart:~/projects/svn/rtt/trunk/bsp/stm32f10x$ echo $PATH
/usr/src/obj/tooldir.Linux-3.2.0-26-generic-pae-i686/bin/:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

prife@smart:~/projects/svn/rtt/trunk/bsp/stm32f10x$ scons -j4
......
cc_ride7/startup_stm32f10x_hd.o
arm-none-eabi-objcopy -O binary rtthread-stm32.axf rtthread.bin
arm-none-eabi-size rtthread-stm32.axf
   text   data    bss    dec    hex filename
  62144    248   5356  67748  108a4 rtthread-stm32.axf
scons: done building targets.

prife@smart:~/projects/svn/rtt/trunk/bsp/stm32f10x$ cat rtconfig.py
.....
if  CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
#EXEC_PATH = 'D:/SourceryGCC/bin'
EXEC_PATH = '/home/prife/tools/CodeSourcery/Sourcery_G++_Lite_201103_eabi/bin'
......

win7我就不试了,还要重启,麻烦。



--
把有限的时间投入到无限的学习中去
Reply all
Reply to author
Forward
0 new messages