本帖最后由 wo4fisher 于 2016-11-10 00:56 编辑
1、准备工作:
硬件:开发板(全志A13主控),sd卡,读卡器,USB转串口线...
软件:系统ubuntu14.04 64位
Welcome to the wiki of the linux-sunxi community, an open source software community dedicated to providing open source operating system support for Allwinner SoC based devices.
2、1)首先安装ubuntu14.04 64位系统,ubuntu已经更新到更高的版本,选择14.04是为了与发布的镜像文件等编译工具更好的兼容,以免版本升级给宝宝带来困扰。坑太多了///
2)安装linux-sunxi开源SDK
下载这三个git文件包,分别是linux内核工程、u-boot工程和开发涉及到的一些工具。
3)sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev \ lib32ncurses5-dev gcc-multilib x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev \ g++-multilib mingw32 tofrodos python-markdown libxml2-utilssudo apt-get install gcc-arm-linux-gnueabihf
apt-get install device-tree-compiler
安装一些依赖包、设备树编译器,根据编译提示补全相关依赖还有版本的更新
4)拷贝修改过的三个文件到u-boot相应的目录
cp A13-Lichee_defconfig configs/ //修改过的配置未见
cp sun5i-a13-lichee.dts arch/arm/dts/ //修改过的设备树文件
cp Makefile arch/arm/dts/ //修改过的makefile
5)编译:
设置开发板默认配置: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- _defconfig
* _defconfig文件为u-boot的configs/目录下的配置文件,有好多,与自己板子兼容,可以直接使用,不兼容,可以做相应修改。
*相关链接:
http://linux-sunxi.org/Manual_build_howto#Build_the_kernel
使用半图形化配置菜单编辑配置:make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
做相应的更改后保存退出
编译u-boot: time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log
编译成功的话,会生成一些u-boot开头的文件,记住u-boot-sunxi-with-spl.bin备用。
6)准备sd卡,至少2G大小,分2个区,一分区16M,fat32,剩下的二分区,ext4。
Identify the cardFirst identify the device of the card and export it as ${card}. The commands
cat /proc/partitions
or
blkid -c /dev/null
can help with finding available/correct partition names.
- If the SD card is connected via USB and is sdX (replace X for a correct letter)
export card=/dev/sdX
export p=""
- If the SD card is connected via mmc and is mmcblk0
export card=/dev/mmcblk0
export p=p
CleaningTo be on safe side erase the first part of your SD Card (also clears the partition table).
dd if=/dev/zero of=${card} bs=1M count=1
If you wish to keep the partition table, run: dd if=/dev/zero of=${card} bs=1k count=1023 seek=1
PartitioningWith recent U-Boot it's fine to use ext2/ext3 as boot partition, and other filesystems in the root partition too. With separate boot partitionPartition the card with a 16MB boot partition starting at 1MB, and the rest as root partition
sfdisk -R ${card}
cat <
1,16,c
,,L
EOT
sfdisk v2.26 and newer does not provide the -R flag, blockdev can be used instead. sfdisk also deprecated the use of -u recently as all sizes are now in sectors. -L flag is also deprecated and ignored so we skip it. --in-order is gone and is the default.
Partitioning the card with this in mind:
blockdev --rereadpt ${card}
cat <
1M,16M,c
,,L
EOT
You should now be able to create the actual filesystems:
mkfs.vfat ${card}${p}1
mkfs.ext4 ${card}${p}2
cardroot=${card}${p}2
使用命令:dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8 将生成的bin文件烧写入sd卡,/dev/sdX 为sd卡挂在目录。有可能是/dev/mmcblkX,我的是/dev/mmcblk0,因为用的大sd卡卡托
7)建立boot.cmd文件,(//http://linux-sunxi.org/U-Boot#UART)内容如下
转换为boot.scr文件: mkimage -C none -A arm -T script -d boot.cmd boot.scr
建立A13外设配置文件A13-lichee.fex,并将fex文件转换为.bin文件,使用到u-boot-tools //http://linux-sunxi.org/Fex_Guide
:sunxi-tools/fex2bin .fex script.bin
将linux-sunxi工程编译得到uImage文件。
8)将步骤7的三个文件cp到sd卡第一分区。
mount ${card}${p}1 /mnt/
mkdir /mnt/boot
cp linux-sunxi/arch/arm/boot/uImage /mnt/boot //见10)
cp sunxi-boards/sys_config/a10/script.bin /mnt/boot
cp boot.scr /mnt/boot
umount /mnt/
解压到sd卡的第二个分区
mount ${card}${p}2 /mnt/
tar -C /mnt/ -xjpf my-chosen-rootfs.tar.bz2
umount /mnt
10)编译linux-sunxi内核
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun5i_defconfig
apt-get install libncurses5-dev
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
make -j$(nproc) ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
生成相关文件:
arch/arm/boot/uImage
output/lib/modules/3.4.XXX/
11)更新modules
mount ${card}${p}2 mnt
rm rm -rf mnt/lib/modules/*
time cp -rf lib/modules/3.4.104/ mnt/lib/modules/
sync
umount mnt大概步骤就是这样,做完这几步后就可以把sd卡插入开发板,usb转串口线连接开发板与电脑,在电脑端设置好串口参数,启动串口终端软件,给开发板连接电源,系统就会运行了
简单的几步却涵盖了linux软硬件协同工作的方方面面。从硬件设计,到软件工具链安装、u-boot、内核参数设置、编辑脚本文件到编译,sd卡挂载、分区、cp/dd文件等基本操作。(*@ο@*) 哇~,太多了,偶要去睡觉了。
本文档只做A13 debian系统安装基本参考,有多处编写不够严谨,需要实际参考官方文档进行验证。
本人也刚开始学嵌入式linux,共勉!