歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 10.04搭建Scratchbox交叉編譯環境

Ubuntu 10.04搭建Scratchbox交叉編譯環境

日期:2017/2/28 16:23:25   编辑:Linux教程
橄榄色:命令 紅色:修改或新增內容 紫色:選擇的選項
一、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.
二、安裝Scratchbox 1.添加軟件源 lingd@Ubuntu:~$ sudo vi /etc/apt/sources.list /etc/apt/sources.list最後面增加下面內容: deb http://scratchbox.org/debian/ stable main
2.更新軟件源 lingd@ubuntu:~$ sudo apt-get update
3.安裝軟件包 lingd@ubuntu:~$ sudo apt-get install scratchbox-core scratchbox-libs scratchbox-devkit-qemu lingd@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: 文檔生成工具. 這個包很大,我沒有安裝

三、禁止VDSO VDSOs (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 = 0 vm.mmap_min_addr = 4096
使結果生效,運行 lingd@ubuntu:~$ sudo sysctl -p vm.vdso_enabled = 0 vm.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 added 2.查看用戶lingd是否已在sbox組中 lingd@ubuntu:~$ groups lingd adm dialout cdrom plugdev lpadmin admin sambashare sbox 如果沒有看到sbox組,那就退出後重新登錄;否則,/scratchbox/login會出現 lingd@ubuntu:~$ /scratchbox/login bash: /scratchbox/login: 權限不夠

五、配置scratchbox 1.進入scratchbox環境 lingd@ubuntu:~$ /scratchbox/login 或 scratchbox
You dont have active target in scratchbox chroot. Please create one by running "sb-menu" before continuing

Welcome 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 出現交互式配置菜單,選擇建立一個target Setup Setup a target 選擇創建一個新target <NEW> Create a new target --> 輸入target名字: arm 選擇compiler(編譯器) cs2007q3-glibc2.5-arm7 cross 選擇devkits(開發輔助工具),一定要選擇qemu,其他根據自身需要 qemu 選擇好devkits後,選擇 DONE Done selecting 選擇模擬器,arm模擬器為qemu-arm qemu-arm-sb Emulation Do you wish extract a rootstrap on the target ? --> no Do you wish install files to the target ? --> yes 直接按照默認選擇(或也可以通過按空格來選擇自己想要安裝的文件)--> OK Do 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: ~] > ls hello hello.c 測試文件類型: [sbox-arm: ~] > file hello hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, dynamically linked (uses shared libs), not stripped 可以看到可執行文件hello的運行平台為 ARM
2.PC上運行HelloWorld(在scratchbox環境下) [sbox-arm: ~] > ./hello hello world 上面顯示的結果,實際上,是在qemu模擬器上運行該程序的結果 在 Selected devkits(輔助開發工具)中要選擇qemu配置模擬器時,一定要選為qemu-arm-XX(我選的是qemu-arm-sb);否則運行./hello會出現: [sbox-arm: ~] > ./hello Error -8 while loading ./hello
3.arm開發板上運行HelloWorld hello 文件下載到開發板當前目錄,運行: 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:~$ scratchbox ERROR: 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:~$ scratchbox
Welcome 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-qemu scratchbox又恢復正常了!
Copyright © Linux教程網 All Rights Reserved