Cubieboard2 debian

来源:互联网 发布:南京大学浙江大学知乎 编辑:程序博客网 时间:2024/05/21 09:51

环境准备

本文所使用的主机环境为kubuntu 12.10,然而一般情况下,下面涉及到的命令对基于Debian的(X)ubuntu系列都应该适用。

为不引起混淆,我们作如下约定:

  • 工作目录为 $WORK_DIR,目标系统 rootfs 目录为 $WORK_DIR/$ROOTFS_DIR
  • 命令均以root用户执行

笔者的设定如下:

WORK_DIR=/home/itviewer/srcROOTFS_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-configapt-get install gcc-arm-linux-gnueabihf

下载源码

从 github 下载 SPL,U-BOOT,Linux 内核源码。注意 linux-sunxi 超过 3.8G ,耗时最长。如果您曾经下载过这些代码,记得分别用 git pull 更新后再进行后续操作,因为代码仓库每天都有变化。

cd $WORK_DIRgit clone git://github.com/linux-sunxi/u-boot-sunxi.gitgit clone git://github.com/cubieboard2/linux-sunxigit clone git://github.com/linux-sunxi/sunxi-tools.gitgit clone git://github.com/linux-sunxi/sunxi-boards.git

下载并配置 Debian 基础系统

mkdir $ROOTFS_DIRcd $ROOTFS_DIRdebootstrap --foreign --arch armhf wheezy .cp /usr/bin/qemu-arm-static usr/bin/LC_ALL=C LANGUAGE=C LANG=C chroot . /debootstrap/debootstrap --second-stageLC_ALL=C LANGUAGE=C LANG=C chroot . dpkg --configure -a

该过程需要一些时间,到此为止,Debian 基础系统已经配置好了;现在可以把 $ROOTFS_DIR 保存为一个压缩包,以备日后之用。

cd $WORK_DIRtar zcvf debian-rootfs-armhf-clean.tar.gz ./debian

编译uboot

 cd $WORK_DIR/u-boot-sunxi make distclean CROSS_COMPILE=arm-linux-gnueabihf- make Cubieboard2 CROSS_COMPILE=arm-linux-gnueabihf-

得到 u-boot-sunxi-with-spl.bin(同时生成的还有其它几个文件,这里我们只用该文件)

编译kernel

 cd $WORK_DIR/linux-sunxi make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- cubieboard2_defconfig make 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/hostnameecho "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.listecho deb http://security.debian.org/ wheezy/updates main contrib non-free >> etc/apt/sources.listchroot . apt-get updatechroot . apt-get upgrade

设置网络

编辑 etc/network/interfaces,根据需要添加以下内容:

下面的配置是动态获取 IP 的设置

# set Debian to configure the interface automatically on bootauto eth0allow-hotplug eth0# use IP autoconfigurationiface eth0 inet dhcp## set the mac address#pre-up ifconfig eth0 hw ether "0011aabbccdd"

下面的配置则是固定 IP 的设置(修改成自己对应的ip、子网掩码、网关)

auto loiface lo inet loopbackauto eth0allow-hotplug eth0iface eth0 inet staticaddress 10.0.0.10netmask 255.255.255.0network 10.0.0.0broadcast 10.0.0.255gateway 10.0.0.1pre-up ifconfig eth0 hw ether "ca28f0493e7d"

如果需要设定无线网卡,可以再追加如下配置(前提是内核已经支持无线网卡驱动,假定无线网卡的设备名为 wlan0)

auto wlan0iface wlan0 inet dhcppre-up ip link set wlan0 uppre-up iwconfig wlan0 essid 路由器ssidwpa-ssid 路由器ssidwpa-psk 无线密码

可选步骤:

安装 Open SSH Server

chroot . apt-get install openssh-server

安装Vim

chroot . apt-get install vim

安装 locales

chroot . apt-get install localesecho "en_US.UTF-8 UTF-8" > etc/locale.genecho "zh_CN.UTF-8 UTF-8" >> etc/locale.genchroot . 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.binfatload mmc 0 0x48000000 boot/uImagebootm 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-toolsmake

得到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/sdXdd if=/dev/zero of=${card} bs=1M count=1      # 把SD卡前1M的区域填充为0,预留给 u-bootsfdisk -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 disklabelBuilding 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   extendedSelect (default p):                                       #直接回车Using default response pPartition number (1-4, default 1):                        #直接回车Using default value 1First sector (2048-15278079, default 2048):               #直接回车Using default value 2048Last 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   extendedSelect (default p):                                       #直接回车Using default response pPartition number (1-4, default 2):                        #直接回车 Using default value 2First sector (133120-15278079, default 133120):           #直接回车Using default value 133120Last 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然后回车,即指定第一个分区为vfatChanged 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}1mkfs.ext4 ${card}2                                        #需要稍等片刻

然后写入bootloader:

cd $WORK_DIR/u-boot-sunxidd if=u-boot-sunxi-with-spl.bin of=$card bs=1024 seek=8

之后安装内核 uImage,设置启动参数:

mount ${card}1 /mntmkdir /mnt/bootcp $WORK_DIR/linux-sunxi/arch/arm/boot/uImage /mnt/bootcp $WORK_DIR/sunxi-boards/sys_config/a20/script.bin /mnt/bootcp $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_DIRmount ${card}2 /mnttar --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/localtimeapt-get install ntpdate

执行以下命令,打开ntpdate配置文件(如果已经安装vim,可以使用vi代替nano命令):

nano -w /etc/default/ntpdate

在后面添加以下内容:

NTPDATE_USE_NTP_CONF=noNTPSERVERS="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_DIRdd if=/dev/zero of=disk.img count=4000000 #此处为 2G 大小;您可以自行修改losetup /dev/loop0 disk.imgdd if=/dev/zero of=/dev/loop0 bs=1k count=1024cd $WORK_DIR/u-boot-sunxidd if=u-boot-sunxi-with-spl.bin of=/dev/loop0 bs=1024 seek=8

分区:

fdisk /dev/loop0

这里分两个区, 第一个分区 64MB, 第二个分区占据所有剩余空间,具体步骤请参考上面内容:建立第一个分区————指定分区类型(无须格式化)

分区挂载,拷贝系统:

cd $WORK_DIRlosetup -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/loop1mkfs.ext4 /dev/loop2mount /dev/loop1 /mntcp $WORK_DIR/boot.scr /mnt/mkdir /mnt/bootcp $WORK_DIR/linux-sunxi/arch/arm/boot/uImage /mnt/bootcp $WORK_DIR/sunxi-boards/sys_config/a20/script.bin /mnt/bootumount /mntcd $ROOTFS_DIRmount /dev/loop2 /mnttar --exclude=qemu-arm-static -cf - . | tar -C /mnt -xvf -sync && umount /mntlosetup -d /dev/loop2losetup -d /dev/loop1losetup -d /dev/loop0

好了,disk.img 已经完成,您可以把它发布到网上了:→ 如果要安装到 TF 卡,执行:

cd $WORK_DIRdd if=disk.img of=$card bs=4k
0 0
原创粉丝点击