在 Linux 底下玩遊戲
mame -> 大型電玩模擬器
1. 下載模擬器
apt-get install xmame-sdl
2. 下載遊戲檔
http://boneash.oldgame.tw/MAME/mame.html
3. 執行
/usr/games/xmame.SDL -rp . twincobr.zip
2012年10月7日 星期日
使用 ntpdate 來更新時間
使用 ntpdate 來更新時間
1. 安裝 ntpdate 套件
apt-get install ntpdate
2. 在 /etc/default/ntpdate 中觀察結果,可選擇要不要加入台灣的伺服器
http://www.stdtime.gov.tw/Time/ntp/NTPClockOperatingManualRelease1.21.html
3. 以 root 權限執行底下指令更新系統時間(請注意網路連線必須沒有問題才行)
ntpdate time.stdtime.gov.tw
1. 安裝 ntpdate 套件
apt-get install ntpdate
2. 在 /etc/default/ntpdate 中觀察結果,可選擇要不要加入台灣的伺服器
http://www.stdtime.gov.tw/Time/ntp/NTPClockOperatingManualRelease1.21.html
3. 以 root 權限執行底下指令更新系統時間(請注意網路連線必須沒有問題才行)
ntpdate time.stdtime.gov.tw
架設 ssh 伺服器
架設 ssh 伺服器
Linux 是多人多工的作業系統,因此可以同時容納多人在同一台主機裡進行操作,要讓使用者能遠端連線進入我們的主機,我們必須架設 ssh 伺服器。
請執行
apt-get install openssh-server
來安裝 ssh 伺服器。當我們已經在 163.26.xx.xx 裝好 ssh 伺服器,該主機即可遠端連線,連線指令如下:
ssh -l 使用者帳號 163.26.xx.xx
不管是正常連線或是錯誤連線,我們都可以在 /var/log/auth.log 看到連線結果。
例如:
May 8 17:56:44 pc-6 sshd[1639]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=118.125.243.59 user=root
May 8 17:56:44 pc-6 sshd[1639]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=118.125.243.59 user=root
May 8 17:56:46 pc-6 sshd[1639]: Failed password for root from 118.125.243.59 port 17448 ssh2
上面錯誤訊息為:
1. 有個人從 118.125.243.59 連到我的機器
2. 他用 root 的帳號,但是沒有正確密碼
3. 入侵時間為 5/8 下午 5:56:44
要避免我們的機器被玩,我們要設定自動偵測錯誤連線並加入阻擋 IP 之機制,因此要安裝以下套件:
denyhosts
openssh-blacklist
openssh-blacklist-extra
在 /etc/hosts.deny 檔案中記錄我們那些主機要擋下來,這是正面表列。我們可以使用
nslookup IP 來查 IP 之 domain name
小結:
ssh 登錄是一個相當重要的程式,它可以讓遠端使用者連至我們所架設的伺服器來進行操作,一旦我們主機的帳號/密碼外露,有可能讓惡意使用者自全世界連線至我們的電腦。使用 denyhosts 套件可以有效降低惡意試帳/密的情況出現,並將惡意連線之 IP 登錄在 /etc/hosts.deny 檔案,如此一來此 IP 將無法再進行連線。
** 聽 MP3 **
1. 安裝音效驅動程式 - alsa
2. 安裝混音程式
3. 安裝 mp3 播放程式
4. 聽 mp3
2012年10月5日 星期五
編譯 ARM Linux 核心
編譯 ARM Linux 核心
檔案位置:
~/qemu_image/ -> 所有虛擬 ARM 檔案目錄
/kernel/ -> 編譯 ARM Linux 核心目錄
/modules -> 編譯 ARM Linux 核心模組目錄
0. 判別我們所要使用之 ARM CPU
我們的模擬目標為 Beagle Board,其 CPU 為 OMAP 3530,有關 Beagle Board 的詳細規格可以參考官方網站 (http://beagleboard.org/),而 OMAP 3530 是由德洲儀洲所生產之 ARM CPU,其資料可以參考德儀網站 (http://www.ti.com/product/omap3530?247SEM)。
OMAP 3530 是一顆 Cortex A8 的 ARM CPU,目前已被 Qemu ARM 完整支援,我們可以使用
qemu-system-arm -cpu ?
來觀看 Qemu ARM 版所支援之 CPU 清單,如下所示:
Available CPUs:
arm1026
arm1136
arm1136-r2
arm1176
arm11mpcore
arm926
arm946
cortex-a15
cortex-a8
cortex-a9
cortex-m3
pxa250
pxa255
pxa260
pxa261
pxa262
pxa270
pxa270-a0
pxa270-a1
pxa270-b0
pxa270-b1
pxa270-c0
pxa270-c5
sa1100
sa1110
ti925t
any
因此我們可以使用 Qemu 來模擬 beagle board 平台,底下將介紹如何編譯 Linux 核心:
1. 下載 & 解壓縮
請切換至 ~/qemu_image/kernel 目錄,進行底下操作:
wget ftp://ftp.twaren.net/pub/Unix/Kernel/linux/kernel/v3.x/linux-3.2.30.tar.xz
tar xfva linux-3.2.30.tar.xz
此時會出現 linux-3.2.30 目錄
2. 設定編譯參數
cd linux-3.2.30
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- omap2plus_defconfig
** ARM 版之核心設定參數檔在 linux-3.2.30/arch/arm/configs 目錄 **
此時會出現以下訊息:
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
這表示我們已經完成基本參數設定,接著我們要作細部微調。請執行:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
如果出現底下錯誤的話,表示我們還沒有安裝 libncurses5-dev 這個函式庫:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
請以底下指令安裝 libncurses5-dev 函式庫:
apt-get install libncurses5-dev
然後再重新執行底下指令即可:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
請設定以下部份:
General setup ---> Kernel compression mode (Gzip) --->XZ
System Type ---> TI OMAP2/3/4 Specific Features --->
[*] OMAP3 BEAGLE board
[*] DEVKIT8000 board
File systems --->
<*> The Extended 4 (ext4) filesystem
設定完畢後請跳出 Linux 設定畫面,如此一來我們即完成 Linux 核心設定。
3. 編譯核心及核心模組
a. 編譯核心
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4
假設在編譯時有底下訊息:
make: arm-linux-gnueabi-gcc: Command not found
scripts/kconfig/conf --silentoldconfig Kconfig
make: arm-linux-gnueabi-gcc: Command not found
WRAP arch/arm/include/generated/asm/auxvec.h
WRAP arch/arm/include/generated/asm/bitsperlong.h
WRAP arch/arm/include/generated/asm/cputime.h
WRAP arch/arm/include/generated/asm/emergency-restart.h
WRAP arch/arm/include/generated/asm/errno.h
WRAP arch/arm/include/generated/asm/ioctl.h
WRAP arch/arm/include/generated/asm/irq_regs.h
WRAP arch/arm/include/generated/asm/kdebug.h
WRAP arch/arm/include/generated/asm/local.h
WRAP arch/arm/include/generated/asm/local64.h
WRAP arch/arm/include/generated/asm/percpu.h
WRAP arch/arm/include/generated/asm/poll.h
WRAP arch/arm/include/generated/asm/resource.h
WRAP arch/arm/include/generated/asm/sections.h
WRAP arch/arm/include/generated/asm/siginfo.h
WRAP arch/arm/include/generated/asm/sizes.h
CHK include/linux/version.h
UPD include/linux/version.h
HOSTCC scripts/dtc/checks.o
HOSTCC scripts/dtc/data.o
SHIPPED scripts/dtc/dtc-lexer.lex.c
SHIPPED scripts/dtc/dtc-parser.tab.h
SHIPPED scripts/dtc/dtc-parser.tab.c
HOSTCC scripts/dtc/dtc.o
HOSTCC scripts/dtc/flattree.o
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
Generating include/generated/mach-types.h
CC kernel/bounds.s
/bin/sh: 1: arm-linux-gnueabi-gcc: not found
make[1]: *** [kernel/bounds.s] Error 127
make: *** [prepare0] Error 2
make: *** Waiting for unfinished jobs....
HOSTCC scripts/dtc/fstree.o
HOSTCC scripts/dtc/livetree.o
HOSTCC scripts/genksyms/genksyms.o
HOSTCC scripts/dtc/srcpos.o
HOSTCC scripts/dtc/treesource.o
SHIPPED scripts/genksyms/lex.lex.c
SHIPPED scripts/genksyms/keywords.hash.c
SHIPPED scripts/genksyms/parse.tab.h
SHIPPED scripts/genksyms/parse.tab.c
HOSTCC scripts/genksyms/lex.lex.o
HOSTCC scripts/dtc/util.o
HOSTCC scripts/dtc/dtc-lexer.lex.o
HOSTCC scripts/dtc/dtc-parser.tab.o
HOSTCC scripts/genksyms/parse.tab.o
HOSTLD scripts/dtc/dtc
CC scripts/mod/empty.o
/bin/sh: 1: arm-linux-gnueabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Error 127
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
HOSTLD scripts/genksyms/genksyms
make: *** [scripts] Error 2
real 0m3.743s
user 0m4.576s
sys 0m0.304s
上面錯誤訊息是因為 arm-linux-gnueabi-gcc 這個指令找不到,我們可以切換至 /usr/bin 目錄來觀察 gcc cpp g++ 三個指令,如下所示:
root@debian:/usr/src# cd /usr/bin
root@debian:/usr/bin# ls -l arm-linux-gnueabi-gcc-4.7 arm-linux-gnueabi-cpp-4.7 arm-linux-gnueabi-g++-4.7
-rwxr-xr-x 1 root root 559672 10月 12 2012 arm-linux-gnueabi-cpp-4.7
-rwxr-xr-x 1 root root 562936 10月 12 2012 arm-linux-gnueabi-g++-4.7
-rwxr-xr-x 1 root root 558840 10月 12 2012 arm-linux-gnueabi-gcc-4.7
這個錯誤是因為編譯指令要的是 arm-linux-gnueabi-gcc、arm-linux-gnueabi-cpp 以及 arm-linux-gnueabi-g++ 三個檔案,而目前系統沒有,因此我們要手動建立連結:
root@debian:/usr/bin# ln -s arm-linux-gnueabi-cpp-4.7 arm-linux-gnueabi-cpp
root@debian:/usr/bin# ln -s arm-linux-gnueabi-g++-4.7 arm-linux-gnueabi-g++
root@debian:/usr/bin# ln -s arm-linux-gnueabi-gcc-4.7 arm-linux-gnueabi-gcc
接著再執行剛剛沒有成功的指令來編譯核心:
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4
若是編譯過程中出現底下錯誤:
SHIPPED arch/arm/boot/compressed/ashldi3.S
AS arch/arm/boot/compressed/lib1funcs.o
AS arch/arm/boot/compressed/ashldi3.o
AS arch/arm/boot/compressed/piggy.xzkern.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
"mkimage" command not found - U-Boot images will not be built
make[1]: *** [arch/arm/boot/uImage] Error 1
make: *** [uImage] Error 2
這表示編譯程式找不到 mkimage 這個指令,我們可以上 packages.debian.org 來查詢,得知此檔案在 u-boot-tools 套件中,因此要再安裝 u-boot-tools 套件,然後再下編譯指令。編譯完畢後會出現以下訊息,告訴我們 uImage 已經編譯完成。
Image Name: Linux-3.2.30
Created: Fri Oct 5 15:43:49 2012
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2475104 Bytes = 2417.09 kB = 2.36 MB
Load Address: 0x80008000
Entry Point: 0x80008000
Image arch/arm/boot/uImage is ready
我們可以執行底下指令來看 /arch/arm/boot/uImage 的屬性:
file arch/arm/boot/uImage
其輸出如底下所示:
file uImage
uImage: u-boot legacy uImage, Linux-3.2.30, Linux/ARM, OS Kernel Image (Not compressed), 2475104 bytes, Fri Oct 5 15:43:49 2012, Load Address: 0x80008000, Entry Point: 0x80008000, Header CRC: 0x3A120CB2, Data CRC: 0x1508ED43
b. 編譯核心模組
核心要正常工作必須要有相對應的核心模組,否則無法載入驅動程式,
# Compile Kernel Modules
time make -s ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules -j $CPU_CORE
# Install Kernel Modules
time make -s ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install INSTALL_MOD_PATH=../modules/ -j $CPU_CORE
cd ../modules
time tar cfa ../modules-$KERNEL_VERSION.tar.xz lib
編譯完成後我們會有一個名為 modules-核心編號.tar.xz 的檔案,此檔案可以用來取代原始 rootfs 中 /lib/modules 目錄中舊版的驅動核心模組。因此我們必須將舊版驅動核心模組移除,再放入我們剛剛編完之驅動核心模組。
4. 準備虛擬 SD card -> 請看講義
5. 將 /dev/loop1 掛載至 /mnt/sdcard1 目錄
mount /dev/loop1 /mnt/sdcard1
將以下檔案複製至 /mnt/sdcard1 目錄:
-rwxr-xr-x 1 root root 45444 2012-10-05 16:52 MLO
-rwxr-xr-x 1 root root 1370958 2012-10-05 16:52 u-boot
-rwxr-xr-x 1 root root 344872 2012-10-05 16:52 u-boot.bin
-rwxr-xr-x 1 root root 344936 2012-10-05 16:52 u-boot.img
-rwxr-xr-x 1 root root 2475168 2012-10-05 16:54 uImage
6.
qemu-system-arm -M beagle -m 256 -nographic -sd sdcard.img
此時即可看到 qemu 使用虛擬 sdcard 開機。
檔案位置:
~/qemu_image/ -> 所有虛擬 ARM 檔案目錄
/kernel/ -> 編譯 ARM Linux 核心目錄
/modules -> 編譯 ARM Linux 核心模組目錄
0. 判別我們所要使用之 ARM CPU
我們的模擬目標為 Beagle Board,其 CPU 為 OMAP 3530,有關 Beagle Board 的詳細規格可以參考官方網站 (http://beagleboard.org/),而 OMAP 3530 是由德洲儀洲所生產之 ARM CPU,其資料可以參考德儀網站 (http://www.ti.com/product/omap3530?247SEM)。
OMAP 3530 是一顆 Cortex A8 的 ARM CPU,目前已被 Qemu ARM 完整支援,我們可以使用
qemu-system-arm -cpu ?
來觀看 Qemu ARM 版所支援之 CPU 清單,如下所示:
Available CPUs:
arm1026
arm1136
arm1136-r2
arm1176
arm11mpcore
arm926
arm946
cortex-a15
cortex-a8
cortex-a9
cortex-m3
pxa250
pxa255
pxa260
pxa261
pxa262
pxa270
pxa270-a0
pxa270-a1
pxa270-b0
pxa270-b1
pxa270-c0
pxa270-c5
sa1100
sa1110
ti925t
any
因此我們可以使用 Qemu 來模擬 beagle board 平台,底下將介紹如何編譯 Linux 核心:
1. 下載 & 解壓縮
請切換至 ~/qemu_image/kernel 目錄,進行底下操作:
wget ftp://ftp.twaren.net/pub/Unix/Kernel/linux/kernel/v3.x/linux-3.2.30.tar.xz
tar xfva linux-3.2.30.tar.xz
此時會出現 linux-3.2.30 目錄
2. 設定編譯參數
cd linux-3.2.30
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- omap2plus_defconfig
** ARM 版之核心設定參數檔在 linux-3.2.30/arch/arm/configs 目錄 **
此時會出現以下訊息:
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
這表示我們已經完成基本參數設定,接著我們要作細部微調。請執行:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
如果出現底下錯誤的話,表示我們還沒有安裝 libncurses5-dev 這個函式庫:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
請以底下指令安裝 libncurses5-dev 函式庫:
apt-get install libncurses5-dev
然後再重新執行底下指令即可:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
請設定以下部份:
General setup ---> Kernel compression mode (Gzip) --->XZ
System Type ---> TI OMAP2/3/4 Specific Features --->
[*] OMAP3 BEAGLE board
[*] DEVKIT8000 board
File systems --->
<*> The Extended 4 (ext4) filesystem
設定完畢後請跳出 Linux 設定畫面,如此一來我們即完成 Linux 核心設定。
3. 編譯核心及核心模組
a. 編譯核心
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4
假設在編譯時有底下訊息:
make: arm-linux-gnueabi-gcc: Command not found
scripts/kconfig/conf --silentoldconfig Kconfig
make: arm-linux-gnueabi-gcc: Command not found
WRAP arch/arm/include/generated/asm/auxvec.h
WRAP arch/arm/include/generated/asm/bitsperlong.h
WRAP arch/arm/include/generated/asm/cputime.h
WRAP arch/arm/include/generated/asm/emergency-restart.h
WRAP arch/arm/include/generated/asm/errno.h
WRAP arch/arm/include/generated/asm/ioctl.h
WRAP arch/arm/include/generated/asm/irq_regs.h
WRAP arch/arm/include/generated/asm/kdebug.h
WRAP arch/arm/include/generated/asm/local.h
WRAP arch/arm/include/generated/asm/local64.h
WRAP arch/arm/include/generated/asm/percpu.h
WRAP arch/arm/include/generated/asm/poll.h
WRAP arch/arm/include/generated/asm/resource.h
WRAP arch/arm/include/generated/asm/sections.h
WRAP arch/arm/include/generated/asm/siginfo.h
WRAP arch/arm/include/generated/asm/sizes.h
CHK include/linux/version.h
UPD include/linux/version.h
HOSTCC scripts/dtc/checks.o
HOSTCC scripts/dtc/data.o
SHIPPED scripts/dtc/dtc-lexer.lex.c
SHIPPED scripts/dtc/dtc-parser.tab.h
SHIPPED scripts/dtc/dtc-parser.tab.c
HOSTCC scripts/dtc/dtc.o
HOSTCC scripts/dtc/flattree.o
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
Generating include/generated/mach-types.h
CC kernel/bounds.s
/bin/sh: 1: arm-linux-gnueabi-gcc: not found
make[1]: *** [kernel/bounds.s] Error 127
make: *** [prepare0] Error 2
make: *** Waiting for unfinished jobs....
HOSTCC scripts/dtc/fstree.o
HOSTCC scripts/dtc/livetree.o
HOSTCC scripts/genksyms/genksyms.o
HOSTCC scripts/dtc/srcpos.o
HOSTCC scripts/dtc/treesource.o
SHIPPED scripts/genksyms/lex.lex.c
SHIPPED scripts/genksyms/keywords.hash.c
SHIPPED scripts/genksyms/parse.tab.h
SHIPPED scripts/genksyms/parse.tab.c
HOSTCC scripts/genksyms/lex.lex.o
HOSTCC scripts/dtc/util.o
HOSTCC scripts/dtc/dtc-lexer.lex.o
HOSTCC scripts/dtc/dtc-parser.tab.o
HOSTCC scripts/genksyms/parse.tab.o
HOSTLD scripts/dtc/dtc
CC scripts/mod/empty.o
/bin/sh: 1: arm-linux-gnueabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Error 127
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
HOSTLD scripts/genksyms/genksyms
make: *** [scripts] Error 2
real 0m3.743s
user 0m4.576s
sys 0m0.304s
上面錯誤訊息是因為 arm-linux-gnueabi-gcc 這個指令找不到,我們可以切換至 /usr/bin 目錄來觀察 gcc cpp g++ 三個指令,如下所示:
root@debian:/usr/src# cd /usr/bin
root@debian:/usr/bin# ls -l arm-linux-gnueabi-gcc-4.7 arm-linux-gnueabi-cpp-4.7 arm-linux-gnueabi-g++-4.7
-rwxr-xr-x 1 root root 559672 10月 12 2012 arm-linux-gnueabi-cpp-4.7
-rwxr-xr-x 1 root root 562936 10月 12 2012 arm-linux-gnueabi-g++-4.7
-rwxr-xr-x 1 root root 558840 10月 12 2012 arm-linux-gnueabi-gcc-4.7
這個錯誤是因為編譯指令要的是 arm-linux-gnueabi-gcc、arm-linux-gnueabi-cpp 以及 arm-linux-gnueabi-g++ 三個檔案,而目前系統沒有,因此我們要手動建立連結:
root@debian:/usr/bin# ln -s arm-linux-gnueabi-cpp-4.7 arm-linux-gnueabi-cpp
root@debian:/usr/bin# ln -s arm-linux-gnueabi-g++-4.7 arm-linux-gnueabi-g++
root@debian:/usr/bin# ln -s arm-linux-gnueabi-gcc-4.7 arm-linux-gnueabi-gcc
接著再執行剛剛沒有成功的指令來編譯核心:
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4
若是編譯過程中出現底下錯誤:
SHIPPED arch/arm/boot/compressed/ashldi3.S
AS arch/arm/boot/compressed/lib1funcs.o
AS arch/arm/boot/compressed/ashldi3.o
AS arch/arm/boot/compressed/piggy.xzkern.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
UIMAGE arch/arm/boot/uImage
"mkimage" command not found - U-Boot images will not be built
make[1]: *** [arch/arm/boot/uImage] Error 1
make: *** [uImage] Error 2
這表示編譯程式找不到 mkimage 這個指令,我們可以上 packages.debian.org 來查詢,得知此檔案在 u-boot-tools 套件中,因此要再安裝 u-boot-tools 套件,然後再下編譯指令。編譯完畢後會出現以下訊息,告訴我們 uImage 已經編譯完成。
Image Name: Linux-3.2.30
Created: Fri Oct 5 15:43:49 2012
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2475104 Bytes = 2417.09 kB = 2.36 MB
Load Address: 0x80008000
Entry Point: 0x80008000
Image arch/arm/boot/uImage is ready
我們可以執行底下指令來看 /arch/arm/boot/uImage 的屬性:
file arch/arm/boot/uImage
其輸出如底下所示:
file uImage
uImage: u-boot legacy uImage, Linux-3.2.30, Linux/ARM, OS Kernel Image (Not compressed), 2475104 bytes, Fri Oct 5 15:43:49 2012, Load Address: 0x80008000, Entry Point: 0x80008000, Header CRC: 0x3A120CB2, Data CRC: 0x1508ED43
b. 編譯核心模組
核心要正常工作必須要有相對應的核心模組,否則無法載入驅動程式,
# Compile Kernel Modules
time make -s ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules -j $CPU_CORE
# Install Kernel Modules
time make -s ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install INSTALL_MOD_PATH=../modules/ -j $CPU_CORE
cd ../modules
time tar cfa ../modules-$KERNEL_VERSION.tar.xz lib
編譯完成後我們會有一個名為 modules-核心編號.tar.xz 的檔案,此檔案可以用來取代原始 rootfs 中 /lib/modules 目錄中舊版的驅動核心模組。因此我們必須將舊版驅動核心模組移除,再放入我們剛剛編完之驅動核心模組。
4. 準備虛擬 SD card -> 請看講義
5. 將 /dev/loop1 掛載至 /mnt/sdcard1 目錄
mount /dev/loop1 /mnt/sdcard1
將以下檔案複製至 /mnt/sdcard1 目錄:
-rwxr-xr-x 1 root root 45444 2012-10-05 16:52 MLO
-rwxr-xr-x 1 root root 1370958 2012-10-05 16:52 u-boot
-rwxr-xr-x 1 root root 344872 2012-10-05 16:52 u-boot.bin
-rwxr-xr-x 1 root root 344936 2012-10-05 16:52 u-boot.img
-rwxr-xr-x 1 root root 2475168 2012-10-05 16:54 uImage
6.
qemu-system-arm -M beagle -m 256 -nographic -sd sdcard.img
此時即可看到 qemu 使用虛擬 sdcard 開機。
2012年10月3日 星期三
u boot 下載、編譯:
u boot 下載、編譯:
0 toolchain 安裝
/etc/apt/sources.list 請加入以下設定:
deb http://www.emdebian.org/debian/ squeeze main
接著執行
apt-get update
apt-get install gcc-4.4-arm-linux-gnueabi cpp-4.4-arm-linux-gnueabi g++-4.4-arm-linux-gnueabi
即可完成 toolchain 安裝。
1. U-boot 是使用在嵌入式系統的 bootloader,所謂的 bootloader 是指開機時載入
的一個小程式,在開機階段作好系統初始化並導入系統 (Linux) 核心,最後完成開機
流程將權限交給作業系統。
U-boot 的官方網頁如下:
http://www.denx.de/wiki/U-Boot
下載網址在:
ftp://ftp.denx.de/pub/u-boot/u-boot-latest.tar.bz2
下載完畢後會出現 u-boot-latest.tar.bz2 這個檔案,之後我們就可以準備解壓縮。
tar xfva u-boot-latest.tar.bz2
解開完畢後會出現 u-boot-2013.10 (最新版) 之目錄,請切換至此目錄準備編譯。
2. 編譯 u-boot
u-boot-2013.10 目錄底下有個 boards.cfg 檔案,裡面內建「所有」支援 ARM 開發板之設定,請看該檔內容,我們會看到其中有一行如下:
omap3_beagle arm armv7 beagle ti omap3
以上資訊告訴我們 u-boot 有支援 beagle 板,請執行底下指令設定編譯參數。
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- omap3_beagle_config
此時會出現底下訊息:
Configuring for omap3_beagle board...
接著請執行底下指令編譯:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- all -j 8
編完之後會出現幾個檔案:
MLO
u-boot
u-boot.bin
u-boot.img
3. 測試
請執行底下指令將所開機必要檔案轉至 sd.img 這個檔案
cat MLO u-boot u-boot.bin u-boot.img > sd.img
接著執行:
qemu-system-arm -M beagle -nographic -sd sd.img
我們會看到 U-boot 2012.07 已經啟動,但是因為沒有核心所以無法開機並且會在此處
當掉,我們會在之後的教學中進行說明如何繼續往下作。
U-Boot SPL 2012.07 (Oct 04 2012 - 11:43:34)
Texas Instruments Revision detection unimplemented
OMAP SD/MMC: 0
mmc_init_stream: timedout waiting for cc!
spl: mmc init failed: err - -19
### ERROR ### Please RESET the board ###
請按 Ctrl+a x 跳出 Qemu
ARM Qemu 的使用:
ARM Qemu 的使用:
0. 看 Qemu 的 Help
qemu-system-arm -help
會跑出一堆 Qemu 的使用說明,請參考原廠手冊
http://wiki.qemu.org/Manual
1. 看 Qemu 的版本
qemu-system-arm -version
QEMU emulator version 0.14.1, Copyright (c) 2003-2008 Fabrice Bellard
2. 看 Qemu 所支援的 ARM 平台
qemu-system-arm -M ?
Supported machines are:
z2 Zipit Z2 (PXA27x)
xilinx-zynq-a9 Xilinx Zynq Platform Baseboard for Cortex-A9
vexpress-a9 ARM Versatile Express for Cortex-A9
vexpress-a15 ARM Versatile Express for Cortex-A15
versatilepb ARM Versatile/PB (ARM926EJ-S)
versatileab ARM Versatile/AB (ARM926EJ-S)
tosa Tosa PDA (PXA255)
lm3s811evb Stellaris LM3S811EVB
lm3s6965evb Stellaris LM3S6965EVB
akita Akita PDA (PXA270)
spitz Spitz PDA (PXA270)
borzoi Borzoi PDA (PXA270)
terrier Terrier PDA (PXA270)
realview-eb ARM RealView Emulation Baseboard (ARM926EJ-S)
realview-eb-mpcore ARM RealView Emulation Baseboard (ARM11MPCore)
realview-pb-a8 ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9 ARM RealView Platform Baseboard Explore for Cortex-A9
cheetah Palm Tungsten|E aka. Cheetah PDA (OMAP310)
overo Gumstix Overo board (OMAP3530)
sx1 Siemens SX1 (OMAP310) V2
sx1-v1 Siemens SX1 (OMAP310) V1
n800 Nokia N800 tablet aka. RX-34 (OMAP2420)
n810 Nokia N810 tablet aka. RX-44 (OMAP2420)
n900 Nokia N900 (OMAP3)
musicpal Marvell 88w8618 / MusicPal (ARM926EJ-S)
mainstone Mainstone II (PXA27x)
kzm ARM KZM Emulation Baseboard (ARM1136)
integratorcp ARM Integrator/CP (ARM926EJ-S) (default)
highbank Calxeda Highbank (ECX-1000)
connex Gumstix Connex (PXA255)
verdex Gumstix Verdex (PXA270)
nuri Samsung NURI board (Exynos4210)
smdkc210 Samsung SMDKC210 board (Exynos4210)
collie Collie PDA (SA-1110)
beagle Beagle board (OMAP3530)
beaglexm Beagle board XM (OMAP3630)
none empty machine
但是官方版 qemu 沒有支援 beagle 平台,因此我們要自行安裝 qemu linaro 版。
其網址如下:
https://launchpad.net/qemu-linaro
而下載網址如下:
https://launchpad.net/qemu-linaro/trunk/2012.09/+download/qemu-linaro-1.2.0-2012.09.tar.gz
請下載此檔案,然後依據上次編譯流程來編譯 Qemu linaro 版,並安裝在自己主機上。
安裝完畢後請執行
qemu-system-arm -M ?
看有沒有支援 beagle 平台。
2012年9月26日 星期三
qemu 下載與安裝
1. 下載:
Qemu 下載網頁 - http://wiki.qemu.org/Download
2. 解壓縮:
tar xfva qemu-2.5.0.tar.bz2
解開後會出現 qemu-2.5.0 目錄
3. 設定前安裝套件:
libtool
zlib1g-dev
pkg-config
libsdl1.2-dev
libcurl4-openssl-dev
libsasl2-dev
libaio-dev
libvde-dev
libvdeplug2-dev
uuid-dev
libcap-ng-dev
4. 設定:
在 qemu-2.5.0 目錄下執行:
./configure
請注意底下兩個參數一定要設定成功:
SDL support yes
KVM support yes
如果有類似底下訊息時:
lzo support no
bzip2 support no
我們可以編輯 configure 這個檔案,搜尋 bzip2 與 lzo 這兩個關鍵字,此時會發現有底下片段,分別是:
if test "$bzip2" = "yes"; then
feature_not_found "libbzip2" "Install libbzip2 devel"
fi
以及
if test "$lzo" = "yes"; then
feature_not_found "liblzo2" "Install liblzo2 devel"
fi
這表示我們的系統中沒有安裝 bzip2 devel 以及 lzo devel 套件,在 Debian 底下,此兩個套件的名稱為:
libbz2-dev
liblzo2-dev
將上述兩個套件安裝,再執行 ./configure 後會發現 lzo 及 bzip2 都已支援,其訊息如下:
lzo support yes
bzip2 support yes
其它找不到套件的訊息依此類推來解決,理論上可以作到的訊息如下:
./configure
Disabling libtool due to broken toolchain support
Install prefix /usr/local
BIOS directory /usr/local/share/qemu
binary directory /usr/local/bin
library directory /usr/local/lib
module directory /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory /usr/local/etc
local state directory /usr/local/var
Manual directory /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path /home/herman/tmp/qemu/qemu-2.5.0
C compiler cc
Host C compiler cc
C++ compiler c++
Objective-C compiler cc
ARFLAGS rv
CFLAGS -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g
QEMU_CFLAGS -I/usr/include/pixman-1 -fPIE -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/include/libpng12 -I/usr/local/include/spice-server -I/usr/local/include/cacard -I/usr/local/include -I/usr/local/include/spice-1 -I/usr/include/nss -I/usr/include/nspr -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/local/include/cacard -I/usr/include/nss -I/usr/include/nspr -I/usr/local/include/libusb-1.0 -I/usr/local/include
LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g
make make
install install
python python -B
smbd /usr/sbin/smbd
module support no
host CPU x86_64
host big endian no
target list aarch64-softmmu alpha-softmmu arm-softmmu cris-softmmu i386-softmmu lm32-softmmu m68k-softmmu microblaze-softmmu microblazeel-softmmu mips-softmmu mips64-softmmu mips64el-softmmu mipsel-softmmu moxie-softmmu or32-softmmu ppc-softmmu ppc64-softmmu ppcemb-softmmu s390x-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu sparc64-softmmu tricore-softmmu unicore32-softmmu x86_64-softmmu xtensa-softmmu xtensaeb-softmmu aarch64-linux-user alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user i386-linux-user m68k-linux-user microblaze-linux-user microblazeel-linux-user mips-linux-user mips64-linux-user mips64el-linux-user mipsel-linux-user mipsn32-linux-user mipsn32el-linux-user or32-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user ppc64le-linux-user s390x-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc32plus-linux-user sparc64-linux-user tilegx-linux-user unicore32-linux-user x86_64-linux-user
tcg debug enabled no
gprof enabled no
sparse enabled no
strip binaries yes
profiler no
static build no
pixman system
SDL support yes
GTK support yes
GTK GL support no
GNUTLS support no
GNUTLS hash no
libgcrypt yes
nettle no ()
libtasn1 yes
VTE support yes
curses support yes
virgl support no
curl support yes
mingw32 support no
Audio drivers oss
Block whitelist (rw)
Block whitelist (ro)
VirtFS support no
VNC support yes
VNC SASL support yes
VNC JPEG support yes
VNC PNG support yes
xen support no
brlapi support yes
bluez support yes
Documentation yes
PIE yes
vde support yes
netmap support no
Linux AIO support yes
ATTR/XATTR support yes
Install blobs yes
KVM support yes
RDMA support no
TCG interpreter no
fdt support yes
preadv support yes
fdatasync yes
madvise yes
posix_madvise yes
sigev_thread_id yes
uuid support yes
libcap-ng support yes
vhost-net support yes
vhost-scsi support yes
Trace backends nop
spice support yes (0.12.7/0.12.5)
rbd support yes
xfsctl support yes
smartcard support yes
libusb yes
usb net redir yes
OpenGL support no
libiscsi support yes
libnfs support no
build guest agent yes
QGA VSS support no
QGA w32 disk info no
QGA MSI support no
seccomp support yes
coroutine backend ucontext
coroutine pool yes
GlusterFS support no
Archipelago support no
gcov gcov
gcov enabled no
TPM support yes
libssh2 support yes
TPM passthrough yes
QOM debugging yes
vhdx yes
lzo support yes
snappy support no
bzip2 support yes
NUMA host support no
tcmalloc support no
jemalloc support no
5. 編譯 qemu
請在設定完成後執行:
make -j 8 (8 核)
6. 安裝
請以 root 權限執行底下指令:
make install
將 qemu 安裝在 /usr/local/bin 目錄下
7. 測試
X86 版本:
請執行底下指令:
$ qemu-system-x86_64 -version
qemu-system-x86_64: error while loading shared libraries: libiscsi.so.1: cannot open shared object file: No such file or directory
我們會看到 qemu-system-x86_64 抱怨找不到 libiscsi.so.1,這最主要的原因目前的 libiscsi 這個動態連結函式庫的檔名已經是 libiscsi.so.2 了,所以 qemu 找不到 libiscsi.so.1,要解決此問題,我們要手動新增這個檔案,請以 root 權限切換至 /usr/lib/x86_64-linux-gnu 目錄,執行:
/usr/lib/x86_64-linux-gnu# ls -l libiscsi.so*
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so -> libiscsi.so.2.1.12
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so.2 -> libiscsi.so.2.1.12
-rw-r--r-- 1 root root 143344 Jul 31 2014 libiscsi.so.2.1.12
可以看到目前只有 libiscsi.so.2 這個檔案,在此目錄中要再新增 libiscsi.so.1 連結檔,指令如下:
/usr/lib/x86_64-linux-gnu# ln -s libiscsi.so.2.1.12 libiscsi.so.1
之後可以再執行 ls 確認一下連結檔是否已建立成功:
/usr/lib/x86_64-linux-gnu# ls -l libiscsi*
-rw-r--r-- 1 root root 223084 Jul 31 2014 libiscsi.a
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so -> libiscsi.so.2.1.12
lrwxrwxrwx 1 root root 18 Mar 25 10:43 libiscsi.so.1 -> libiscsi.so.2.1.12
lrwxrwxrwx 1 root root 18 Jul 31 2014 libiscsi.so.2 -> libiscsi.so.2.1.12
-rw-r--r-- 1 root root 143344 Jul 31 2014 libiscsi.so.2.1.12
此時再執行 qemu 即沒有問題:
$ qemu-system-x86_64 -version
QEMU emulator version 2.5.0, Copyright (c) 2003-2008 Fabrice Bellard
qemu-system-arm -M ?
可以看到 qemu arm 模擬器的資訊
qemu-system-arm -version
可以看到 qemu 模擬器版本資訊
QEMU emulator version 1.2.0, Copyright (c) 2003-2008 Fabrice Bellard
訂閱:
文章 (Atom)