Cubieboard2 debian
環境準備
本文所使用的主機環境為kubuntu 12.10,然而一般情況下,下面涉及到的命令對基于Debian的(X)ubuntu系列都應該適用。
為不引起混淆,我們作如下約定:
- 工作目錄為 $WORK_DIR,目標系統 rootfs 目錄為 $WORK_DIR/$ROOTFS_DIR
- 命令均以root用戶執行
筆者的設定如下:
WORK_DIR=/home/itviewer/src ROOTFS_DIR=$WORK_DIR/debian下載必須的工具軟件
apt-get install build-essential libncurses5-dev u-boot-tools qemu-user-static debootstrap git binfmt-support libusb-1.0-0-dev pkg-config apt-get install gcc-arm-linux-gnueabihf下載源碼
從 github 下載 SPL,U-BOOT,Linux 內核源碼。注意 linux-sunxi 超過 3.8G ,耗時最長。如果您曾經下載過這些代碼,記得分別用 git pull 更新后再進行后續操作,因為代碼倉庫每天都有變化。
cd $WORK_DIR git clone git://github.com/linux-sunxi/u-boot-sunxi.git git clone git://github.com/cubieboard2/linux-sunxi git clone git://github.com/linux-sunxi/sunxi-tools.git git clone git://github.com/linux-sunxi/sunxi-boards.git下載并配置 Debian 基礎系統
mkdir $ROOTFS_DIR cd $ROOTFS_DIR debootstrap --foreign --arch armhf wheezy . cp /usr/bin/qemu-arm-static usr/bin/ LC_ALL=C LANGUAGE=C LANG=C chroot . /debootstrap/debootstrap --second-stage LC_ALL=C LANGUAGE=C LANG=C chroot . dpkg --configure -a該過程需要一些時間,到此為止,Debian 基礎系統已經配置好了;現在可以把 $ROOTFS_DIR 保存為一個壓縮包,以備日后之用。
cd $WORK_DIR tar zcvf debian-rootfs-armhf-clean.tar.gz ./debian編譯uboot
cd $WORK_DIR/u-boot-sunximake distclean CROSS_COMPILE=arm-linux-gnueabihf-make Cubieboard2 CROSS_COMPILE=arm-linux-gnueabihf-得到 u-boot-sunxi-with-spl.bin(同時生成的還有其它幾個文件,這里我們只用該文件)
編譯kernel
cd $WORK_DIR/linux-sunximake ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- cubieboard2_defconfigmake ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 uImage modules得到內核文件 arch/arm/boot/uImage 及其它內核模塊。
注意:這里僅使用官方的默認配置,如需要自行配置內核模塊、安裝其它驅動程序,可以在上述第一條命令后執行下述命令進行配置:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig建立 ROOTFS
除非特別說明,本節的所有操作都在 $ROOTFS DIR 下面進行,所以我們進入該目錄先:
cd $ROOTFS_DIR設置管理員密碼和主機名稱
chroot . passwd #回車后輸入root用戶密碼 echo "CubieBoard2" > etc/hostname echo "127.0.0.1 CubieBoard2" >> etc/hosts內核模塊安裝
make -C $WORK_DIR/linux-sunxi INSTALL_MOD_PATH=`pwd` ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules_install設置串口調試終端參數
echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> etc/inittab配置并更新軟件源:
echo deb http://http.debian.net/debian/ wheezy main contrib non-free > etc/apt/sources.list echo deb http://security.debian.org/ wheezy/updates main contrib non-free >> etc/apt/sources.list chroot . apt-get update chroot . apt-get upgrade設置網絡
編輯 etc/network/interfaces,根據需要添加以下內容:
下面的配置是動態獲取 IP 的設置
# set Debian to configure the interface automatically on boot auto eth0 allow-hotplug eth0 # use IP autoconfiguration iface eth0 inet dhcp ## set the mac address #pre-up ifconfig eth0 hw ether "0011aabbccdd"下面的配置則是固定 IP 的設置(修改成自己對應的ip、子網掩碼、網關)
auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet static address 10.0.0.10 netmask 255.255.255.0 network 10.0.0.0 broadcast 10.0.0.255 gateway 10.0.0.1 pre-up ifconfig eth0 hw ether "ca28f0493e7d"如果需要設定無線網卡,可以再追加如下配置(前提是內核已經支持無線網卡驅動,假定無線網卡的設備名為 wlan0)
auto wlan0 iface wlan0 inet dhcp pre-up ip link set wlan0 up pre-up iwconfig wlan0 essid 路由器ssid wpa-ssid 路由器ssid wpa-psk 無線密碼可選步驟:
安裝 Open SSH Server
chroot . apt-get install openssh-server安裝Vim
chroot . apt-get install vim安裝 locales
chroot . apt-get install locales echo "en_US.UTF-8 UTF-8" > etc/locale.gen echo "zh_CN.UTF-8 UTF-8" >> etc/locale.gen chroot . locale-gen生成 boot.scr和script.bin
生成 boot.scr
在$WORK_DIR目錄下新建 boot.cmd 文件,添加以下內容:
setenv bootargs console=ttyS0,115200 noinitrd disp.screen0_output_mode=EDID:1280x1024p60 init=/init root=/dev/mmcblk0p2 rootfstype=ext4 rootwait panic=10 ${extra} fatload mmc 0 0x43000000 boot/script.bin fatload mmc 0 0x48000000 boot/uImage bootm 0x48000000注意:上述disp.screen0_output_mode參數需要根據自己顯示器的情況進行設置
然后執行以下命令生成boot.scr:
mkimage -C none -A arm -T script -d boot.cmd boot.scr生成 script.bin
首先需要編譯sunxi-tools:
cd $WORK_DIR/sunxi-tools make得到fex2bin、bin2fex等文件,其中fex2bin能把 *.fex 文件生成 *.bin文件。反之bin2fex可以將得到的*.bin文件生成可讀的*.fex文件。
然后編譯生成script.bin:
cd $WORK_DIR/sunxi-boards/sys_config/a20 $WORK_DIR/sunxi-tools/fex2bin cubieboard2.fex script.bin安裝到 TF 卡
本文采用兩個分區方案,其中第一個分區為啟動分區,主要包含內核文件uImage和內核參數文件script.bin;第二個分區用于安裝rootfs。
將TF卡插到電腦上查看并確認設備名,為不至于混淆,我們使用sdX代替,您需要根據自己的情況修改,如sdb(這步要小心額,看錯了也許會導致硬盤被格!):
card=/dev/sdX dd if=/dev/zero of=${card} bs=1M count=1 # 把SD卡前1M的區域填充為0,預留給 u-boot sfdisk -R ${card} # 重新讀取${card} fdisk ${card} #使用fdisk進行分區具體分區步驟如下:
建立第一個分區
root@kubuntu:~/src/u-boot-sunxi# fdisk ${card} Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x911332e8. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help): n #鍵入n然后回車 Partition type:p primary (0 primary, 0 extended, 4 free)e extended Select (default p): #直接回車 Using default response p Partition number (1-4, default 1): #直接回車 Using default value 1 First sector (2048-15278079, default 2048): #直接回車 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-15278079, default 15278079): +64M #鍵入+64M后回車,即分區大小為64M建立第二個分區
Command (m for help): n #鍵入n然后回車 Partition type:p primary (1 primary, 0 extended, 3 free)e extended Select (default p): #直接回車 Using default response p Partition number (1-4, default 2): #直接回車 Using default value 2 First sector (133120-15278079, default 133120): #直接回車 Using default value 133120 Last sector, +sectors or +size{K,M,G} (133120-15278079, default 15278079): #直接回車,即第二個分區使用全部剩余空間 Using default value 15278079接下來指定分區類型:
Command (m for help): t #鍵入t然后回車 Partition number (1-4): 1 #鍵入1然后回車,即指定第一個分區 Hex code (type L to list codes): c #鍵入c然后回車,即指定第一個分區為vfat Changed system type of partition 1 to c (W95 FAT32 (LBA))Command (m for help): w #鍵入w然后回車,保存分區表 The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks.格式化分區:
mkfs.vfat ${card}1 mkfs.ext4 ${card}2 #需要稍等片刻然后寫入bootloader:
cd $WORK_DIR/u-boot-sunxi dd if=u-boot-sunxi-with-spl.bin of=$card bs=1024 seek=8之后安裝內核 uImage,設置啟動參數:
mount ${card}1 /mnt mkdir /mnt/boot cp $WORK_DIR/linux-sunxi/arch/arm/boot/uImage /mnt/boot cp $WORK_DIR/sunxi-boards/sys_config/a20/script.bin /mnt/boot cp $WORK_DIR/boot.scr /mnt/ sync && umount /mnt拷貝整個 ROOTFS 到 TF 卡
首先編輯 $ROOTFS_DIR/etc/fstab,添加以下內容:
/dev/mmcblk0p1 /boot vfat defaults 0 2 /dev/mmcblk0p2 / ext4 defaults,noatime 0 1然后拷貝整個 ROOTFS 到 TF 卡:
cd $ROOTFS_DIR mount ${card}2 /mnt tar --exclude=qemu-arm-static -cf - . | tar -C /mnt -xvf - sync && umount /mnt該操作需要稍等片刻
如果沒有意外的話——您自己動手豐衣足食得到的 Debian Linux TF 卡版本或許已經可以運行了,只是還沒把 TF 卡插到 CubieBoard 上測試而已!
系統配置
成功啟動進入shell后需要我們做些簡單的配置:
設置時區和日期
rm /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime apt-get install ntpdate執行以下命令,打開ntpdate配置文件(如果已經安裝vim,可以使用vi代替nano命令):
nano -w /etc/default/ntpdate在后面添加以下內容:
NTPDATE_USE_NTP_CONF=no NTPSERVERS="0.asia.pool.ntp.org 1.asia.pool.ntp.org 2.asia.pool.ntp.org 3.asia.pool.ntp.org" NTPOPTIONS=""先ctrl+O保存,然后需要回車確認,最后ctrl+x退出
然后執行
ntpdate-debian設置開機啟動 ntpdate, 在/etc/rc.local 文件的 exit 0 這一行之前加入:
ntpdate-debian創建系統鏡像[可選]
如果您想把自己制作的系統分享給朋友們,可以參考本節。
創建空鏡像文件并寫入uboot:
cd $WORK_DIR dd if=/dev/zero of=disk.img count=4000000 #此處為 2G 大小;您可以自行修改 losetup /dev/loop0 disk.img dd if=/dev/zero of=/dev/loop0 bs=1k count=1024 cd $WORK_DIR/u-boot-sunxi dd if=u-boot-sunxi-with-spl.bin of=/dev/loop0 bs=1024 seek=8分區:
fdisk /dev/loop0這里分兩個區, 第一個分區 64MB, 第二個分區占據所有剩余空間,具體步驟請參考上面內容:建立第一個分區————指定分區類型(無須格式化)
分區掛載,拷貝系統:
cd $WORK_DIR losetup -d /dev/loop0 && losetup /dev/loop0 disk.img #(重新關聯一次) losetup -o 1048576 /dev/loop1 /dev/loop0 #(關聯第一分區,1048576=512*2048) losetup -o 68157440 /dev/loop2 /dev/loop0 #(關聯第二分區,68157440=512*133120) mkfs.vfat /dev/loop1 mkfs.ext4 /dev/loop2 mount /dev/loop1 /mnt cp $WORK_DIR/boot.scr /mnt/ mkdir /mnt/boot cp $WORK_DIR/linux-sunxi/arch/arm/boot/uImage /mnt/boot cp $WORK_DIR/sunxi-boards/sys_config/a20/script.bin /mnt/boot umount /mnt cd $ROOTFS_DIR mount /dev/loop2 /mnt tar --exclude=qemu-arm-static -cf - . | tar -C /mnt -xvf - sync && umount /mnt losetup -d /dev/loop2 losetup -d /dev/loop1 losetup -d /dev/loop0好了,disk.img 已經完成,您可以把它發布到網上了:→ 如果要安裝到 TF 卡,執行:
cd $WORK_DIR dd if=disk.img of=$card bs=4k總結
以上是生活随笔為你收集整理的Cubieboard2 debian的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cs8900a网卡驱动--寄存器
- 下一篇: Asterisk文件目录