橄榄色:命令红色:修改或新增内容紫色:选择的选项一、Scratchbox简介ScratchboxisaconfigurationandcompilationenvironmentforbuildingLinuxsoftwareandentireLinuxdistributions.ThebasicideaofScratchboxis 橄榄色:命令红
橄榄色:命令红色:修改或新增内容紫色:选择的选项一、Scratchbox简介ScratchboxisaconfigurationandcompilationenvironmentforbuildingLinuxsoftwareandentireLinuxdistributions.ThebasicideaofScratchboxis 橄榄色:命令红色:修改或新增内容紫色:选择的选项一、Scratchbox简介Scratchbox is a configuration and compilation environment for building Linux software and entire Linux distributions. The basic idea of Scratchbox is to offer developers an environment that works and looks like the target environment before the target environment is available.二、安装Scratchbox1.添加软件源lingd@Ubuntu:~$ sudo vi /etc/apt/sources.list/etc/apt/sources.list最后面增加下面内容:deb http://scratchbox.org/debian/ stable main2.更新软件源lingd@ubuntu:~$ sudo apt-get update3.安装软件包lingd@ubuntu:~$ sudo apt-get install scratchbox-core scratchbox-libs scratchbox-devkit-qemulingd@ubuntu:~$ sudo apt-get install scratchbox-devkit-debian scratchbox-devkit-perl scratchbox-toolchain-cs2007q3-glibc2.5-arm7注:以下是必须安装的scratchbox-core: scratchbox环境, 常用工具及本地编译器.scratchbox-libs: scratchbox-core, devkits和toolchains所需的库.scratchbox-devkit-qemu: scratchbox的ARM指令集仿真器. scratchbox中提供了qemu和sbrsh两种仿真手段. 要使用qemu仿真, 需安装scratchbox-devkit-cputransp包,不过现在scratchbox-devkit-cputransp包已被scratchbox-devkit-qemu取代了以下是可选的scratchbox-devkit-debian: 用于Debian包开发的环境和工具.scratchbox-devkit-perl: 额外的perl模块.scratchbox-toolchain-cs2007q3-glibc2.5-arm7: 交叉编译工具包,也可以选择其他交叉编译工具包scratchbox-devkit-doctools: 文档生成工具. 这个包很大,我没有安装三、禁止VDSOVDSOs (Virtual Dynamically-linked Shared Objects 虚拟动态共享对象) are a way to export kernel space routines to user space applications, using standard mechanisms for linking and loading (i.e. standard ELF format).禁止Ubuntu 10.04的VDSO功能lingd@ubuntu:~$ sudo vi /etc/sysctl.conf编辑/etc/sysctl.conf, 最后面增加下面两行:vm.vdso_enabled = 0vm.mmap_min_addr = 4096使结果生效,运行lingd@ubuntu:~$ sudo sysctl -pvm.vdso_enabled = 0vm.mmap_min_addr = 4096为了长期生效,编辑/etc/rc.local,在最后一行(exit 0)前面, 增加:sysctl -p四、添加scratchbox用户1.增加用户到scratchbox中lingd@ubuntu:~$ sudo /scratchbox/sbin/sbox_adduser lingd[sudo] password for lingd:Add user lingd to group 'sbox'? [yes/no] (yes): yes正在添加用户"lingd"到"sbox"组...Adding user lingd to group sbox完成。Scratchbox user account for user lingd added2.查看用户lingd是否已在sbox组中lingd@ubuntu:~$ groupslingd adm dialout cdrom plugdev lpadmin admin sambashare sbox如果没有看到sbox组,那就退出后重新登录;否则,/scratchbox/login会出现lingd@ubuntu:~$ /scratchbox/loginbash: /scratchbox/login: 权限不够五、配置scratchbox1.进入scratchbox环境lingd@ubuntu:~$ /scratchbox/login 或 scratchboxYou dont have active target in scratchbox chroot.Please create one by running "sb-menu" before continuingWelcome to Scratchbox, the cross-compilation toolkit!Use 'sb-menu' to change your compilation target.See /scratchbox/doc/ for documentation.[sbox-NO-TARGET: ~] >2.配置编译目标[sbox-NO-TARGET: ~] > sb-menu出现交互式配置菜单,选择建立一个targetSetup Setup a target选择创建一个新target Create a new target --> 输入target名字: arm选择compiler(编译器)cs2007q3-glibc2.5-arm7 cross选择devkits(开发辅助工具),一定要选择qemu,其他根据自身需要qemu选择好devkits后,选择DONE Done selecting 选择模拟器,arm模拟器为qemu-armqemu-arm-sb Emulation Do you wish extract a rootstrap on the target ? --> noDo you wish install files to the target ? --> yes直接按照默认选择(或也可以通过按空格来选择自己想要安装的文件)--> OKDo you wish to select the target --> yes此时sb-menu会退出。参考文献4有图解scratchbox的配置过程六、编译测试1.HelloWorld在/scratchbox/packages有一些例子代码,HelloWorld就是其中一个。因为在/scratchbox/packages没有足够权限,所以只能拷贝hello.c到用户主目录再编译[sbox-arm: ~] > cp /scratchbox/packages/hello.c hello.c[sbox-arm: ~] > gcc hello.c -o hello [sbox-arm: ~] > lshello hello.c测试文件类型:[sbox-arm: ~] > file hellohello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, dynamically linked (uses shared libs), not stripped可以看到可执行文件hello的运行平台为 ARM2.PC上运行HelloWorld(在scratchbox环境下)[sbox-arm: ~] > ./hellohello world上面显示的结果,实际上,是在qemu模拟器上运行该程序的结果在 Selected devkits(辅助开发工具)中要选择qemu配置模拟器时,一定要选为qemu-arm-XX(我选的是qemu-arm-sb);否则运行./hello会出现:[sbox-arm: ~] > ./helloError -8 while loading ./hello3.arm开发板上运行HelloWorldhello 文件下载到开发板当前目录,运行:chmod a+x hello./hello可以在开发板上看到程序的运行结果。七、关于登陆scratchbox出现Scratchbox is not properly set up的解决方法官网的解释:If Scratchbox was installed from Debian or RPM packages, the /etc/init.d/scratchbox-core init script was installed and Scratchbox should start automatically when the system is rebooted. However, if you installed Scratchbox from tarballs then rebooting your machine will clear away all the mounts and binfmt_misc registrations that Scratchbox requires to work. To get your Scratchbox working again after reboot, you have to run the following command as root:# /scratchbox/sbin/sbox_ctl start简单意思就是:以tar方式安装scratchbox,重启pc后,scratchbox正常工作所需要的mounts和binfmt_misc信息都会被清除。所以每次开机第一次运行scratchbox或/scratchbox/login前,必须先运行“/scratchbox/sbin/sbox_ctl start”命令lingd@ubuntu:~$ scratchboxERROR: Scratchbox is not properly set up!lingd@ubuntu:~$ sudo /scratchbox/sbin/sbox_ctl start[sudo] password for lingd:Starting Scratchbox: binfmt_misc, mount.lingd@ubuntu:~$ scratchboxWelcome to Scratchbox, the cross-compilation toolkit!Use 'sb-menu' to change your compilation target.See /scratchbox/doc/ for documentation.[sbox-arm: ~] >不过,我是通过deb包安装的,/scratchbox/sbin/sbox_ctl start解决不了我的问题。我估计是虚拟机Vmware不正常关闭导致的。重新安装一下scratchbox:lingd@ubuntu:~$ sudo apt-get --no-download --reinstall install scratchbox-core scratchbox-libs scratchbox-devkit-qemuscratchbox又恢复正常了!