2022年6月

1、开发平台

虚拟机:VMware 12

操作系统:Ubuntu 14.04 64bit

2、准备ARM交叉编译工具包

编译uboot和linux kernel都需要ARM交叉工具链支持,这里使用Linaro提供的交叉编译工具。下载地址为:http://releases.linaro.org/

注意:如果主机是64bit,请选择64位的交叉编译器工具链,32bit的主机选择32位的交叉工具链。

The Linaro Toolchain Working Group is pleased to announce this quarter’s release of the Linaro Toolchain Binaries, a pre-built version of Linaro GCC and Linaro GDB that runs on generic Linux or Windows and targets the glibc Linaro Engineering Build.

Beginning 2014.11, Linaro is changing the layout and structure of its prebuilt toolchain binary releases. 2014.11 is the first release built with ABE, adding more maintainable code base and automatic testing. For further details on ABE, please visit https://wiki.linaro.org/ABE.

The folder names above describe the target triplets, i.e. the system on which you want your programs/applications to run. For more details on triplets, please click here.

Inside each folder is also a manifest.txt file further describing the target and host systems meant for the toolchain, plus source component versions.

Essentially, the main folder contents are as follows:

aarch64-linux-gnu

· gcc-linaro-*x86_64_aarch64-linux-gnu.tar.xz

o Linux 64-bit binaries for the Aarch64 Linux cross-toolchain

· gcc-linaro-*i686-mingw32_aarch64-linux-gnu.tar.xz

o Windows 32-bit binaries for the Aarch64 Linux cross-toolchain

aarch64-none-elf

· gcc-linaro-*x86_64_aarch64-elf.tar.xz

o Linux 64-bit binaries for the Aarch64 bare-metal cross-toolchain

· gcc-linaro-*i686-mingw32_aarch64-elf.tar.xz

o Windows 32-bit binaries for the Aarch64 bare-metal cross-toolchain

aarch64_be-linux-gnu

· gcc-linaro-*x86_64_aarch64_be-linux-gnu.tar.xz

o Linux 64-bit binaries for the Aarch64 Linux Big Endian cross-toolchain

· gcc-linaro-*i686-mingw32_aarch64_be-linux-gnu.tar.xz

o Windows 32-bit binaries for the Aarch64 Linux Big Endian cross-toolchain

aarch64_be-none-elf

· gcc-linaro-*x86_64_aarch64_be-elf.tar.xz

o Linux 64-bit binaries for the Aarch64 bare-metal Big Endian cross-toolchain

· gcc-linaro-*i686-mingw32_aarch64_be-elf.tar.xz

o Windows 32-bit binaries for the Aarch64 bare-metal Big Endian cross-toolchain

arm-linux-gnueabi

· gcc-linaro-*x86_64_arm-linux-gnueabi.tar.xz

o Linux 64-bit binaries for the ARMv7 Linux soft float cross-toolchain

· gcc-linaro-*i686-mingw32_arm-linux-gnueabi.tar.xz

o Windows 32-bit binaries for the ARMv7 Linux soft float cross-toolchain

arm-linux-gnueabihf

· gcc-linaro-*x86_64_arm-linux-gnueabihf.tar.xz

o Linux 64-bit binaries for the ARMv7 Linux hard float cross-toolchain

· gcc-linaro-*i686-mingw32_arm-linux-gnueabihf.tar.xz

o Windows 32-bit binaries for the ARMv7 Linux hard float cross-toolchain

arm-none-eabi

· gcc-linaro-*x86_64_arm-eabi.tar.xz

o Linux 64-bit binaries for the ARMv7 bare-metal cross-toolchain

· gcc-linaro-*i686-mingw32_arm-eabi.tar.xz

o Windows 32-bit binaries for the ARMv7 bare-metal cross-toolchain

armeb-linux-gnueabihf

· gcc-linaro-*x86_64_armeb-linux-gnueabihf.tar.xz

o Linux 64-bit binaries for the ARMv7 Linux Big Endian hard float cross-toolchain

· gcc-linaro-*i686-mingw32_armeb-linux-gnueabihf.tar.xz

o Windows 32-bit binaries for the ARMv7 Linux Big Endian hard float cross-toolchain

armeb-none-eabi

· gcc-linaro-*x86_64_armeb-eabi.tar.xz

o Linux 64-bit binaries for the ARMv7 bare-metal Big Endian cross-toolchain

· gcc-linaro-*i686-mingw32_armeb-eabi.tar.xz

o Windows 32-bit binaries for the ARMv7 bare-metal Big Endian cross-toolchain

NOTE

· The binary source package is no longer distributed as the components are now archived at http://abe.tcwglab.linaro.org/snapshots and downloaded automatically based on manifest.txt when (re)building with ABE.

· The source package releases for the individual components are still at http://releases.linaro.org/latest/components/toolchain. Select the component (e.g. gcc, glibc, binutils, gdb) as necessary.

· The binary tarball has been splitted into 3 parts. As a result, you can install only the parts needed:

o gcc-linaro-*.tar.xz – the compiler and tools

o runtime-linaro-*.tar.xz – runtime libraries needed on the target

o sysroot-linaro-*.tar.xz – sysroot (a set of libraries and headers to develop against)

· Beginning 2014.11, sysroots will use the latest glibc release provided by Linaro engineers in order that users get the latest features and optimizations in the system libraries.

· Eglibc 2.15 compatible sysroots will no longer be released. Users that require Eglibc 2.15 sysroots that need the latest Linaro GCC compiler should use the previous quarterly released sysroot.

· x86 (32-bit) Linux host toolchains are no longer provided. x86_64 (64-bit) Linux host toolchains are provided instead.

· Soft-float targeted toolchains are no longer supported.

笔者使用的ARM交叉工具链版本为gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

下载地址为:

http://releases.linaro.org/components/toolchain/binaries/6.1-2016.08/arm-linux-gnueabi/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

3、安装步骤

3.1、Ubuntu14.04 64bit系统下安装标准的C开发环境

sudo apt-get install gcc g++ libgcc1 libg++ make gdb

或者 sudo apt-get install build-essential

3.2、下载gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

1> 在/usr/local/文件夹下建立名为ARM-toolchain的文件夹

$ sudo mkdir /usr/local/ARM-toolchain

2> 下载gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

$ cd /usr/local/ARM-toolchain

sudo wget http://releases.linaro.org/components/toolchain/binaries/6.1-2016.08/ arm-linux-gnueabi/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

3.3、安装gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi

解压gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

$ xz –d gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar.xz

$ tar xvf gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi.tar

3.4、修改环境变量,把交叉编译器的路径加入到PATH

修改/etc/bash.bashrc文件(此文件只对当前用户适用)

$sudo gedit /etc/bash.bashrc

然后在文件的末尾空白处加入一下代码:

Add ARM toolschain path

if [ -d /usr/local/ARM-toolchain/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi ] ; then

PATH= /usr/local/ARM-toolchain/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi/bin:"${PATH}"

fi

3.5、使新的环境变量生效(不用重启电脑)

$ source /etc/bash.bashrc

3.6. 检查是否将路径加入到PATH:

$ echo $PATH

若显示的内容中含有:/usr/local/ARM-toolchain/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi/bin 说明已经将交叉编译器的路径加入PATH。

至此,交叉编译环境安装完成。

3.7. 测试是否安装成功

$ arm-linux-gnueabi-gcc -v

执行上面的命令,显示arm-linux-gnueabi-gcc -v信息和版本:

$ arm-linux-gnueabi-gcc -v

Using built-in specs.

COLLECT_GCC=arm-linux-gnueabi-gcc

COLLECT_LTO_WRAPPER=/usr/local/ARM-toolchain/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi/bin/../libexec/gcc/arm-linux-gnueabi/6.1.1/lto-wrapper

Target: arm-linux-gnueabi

Configured with: /home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/snapshots/gcc-linaro-6.1-2016.08/configure SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libstdcxx-pch --disable-libmudflap --with-cloog=no --with-ppl=no --with-isl=no --disable-nls --enable-c99 --enable-gnu-indirect-function --with-tune=cortex-a9 --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=softfp --with-mode=thumb --disable-multilib --enable-multiarch --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/_build/sysroots/arm-linux-gnueabi --enable-lto --enable-linker-build-id --enable-long-long --enable-shared --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/_build/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabi/libc --enable-languages=c,c++,fortran,lto --enable-checking=release --disable-bootstrap --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabi --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/label/docker-trusty-amd64-tcwg/target/arm-linux-gnueabi/_build/builds/destdir/x86_64-unknown-linux-gnu

Thread model: posix

gcc version 6.1.1 20160711 (Linaro GCC 6.1-2016.08)

一、sd启动

将u-boot镜像写入SD卡,将SD卡通过读卡器接上电脑(或直接插入笔记本卡槽),通过"cat /proc/partitions"找出SD卡对应的设备,我的设备节点是/dev/sdb.(内存卡的节点)。

当有多个交叉编译器是,不方便设置环境变量时,可以在编译命令中指定交叉编译器,具体如下:在源码中操作以下步骤:

make distclean

make ARCH=arm CROSS_COMPILE=/opt/FriendlyARM/toolschain/4.5.1/bin/arm-none-linux-gnueabi- mrproper

make ARCH=arm CROSS_COMPILE=/opt/FriendlyARM/toolschain/4.5.1/bin/arm-none-linux-gnueabi- tiny210_config

make ARCH=arm CROSS_COMPILE=/opt/FriendlyARM/toolschain/4.5.1/bin/arm-none-linux-gnueabi- all spl

编译出tiny210-uboot.bin,注意交叉编译工具路径

执行下面的命令
$sudo dd iflag=dsync oflag=dsync if=tiny210-uboot.bin of=/dev/sdb seek=1

把内存卡插入开发板,使用串口工具设置环境变量:

setenv gatewayip 192.168.1.1 (电脑网关)
setenv ipaddr 192.168.1.102 (开发板ip,不要与虚拟机和电脑ip冲突)
setenv netmask 255.255.255.0
setenv serverip 192.168.1.10 (虚拟机ip)

saveenv

二、nand启动

烧写Uboot:

通过SD卡启动的u-boot for tiny210 将u-boot镜像写入nandflash

在虚拟机下重启tftp sudo service tftpd-hpa restart

开发板终端下执行下面的命令:

[FriendlyLEG-TINY210]# tftp 21000000 tiny210-uboot.bin

[FriendlyLEG-TINY210]# nand erase.chip

[FriendlyLEG-TINY210]# nand write 21000000 0 3c1f4 (写入长度)

内核的烧写位置是0x600000开始的区域,文件系统烧写位置为0xe00000开始的区域。

三、烧写内核:

重新设置环境变量:

setenv gatewayip 192.168.1.1 (电脑网关)
setenv ipaddr 192.168.1.102 (开发板ip,不要与虚拟机和电脑ip冲突)
setenv netmask 255.255.255.0
setenv serverip 192.168.1.10 (虚拟机ip)

saveenv

在/svn/linux-3.0.8 源码目录下make uImage,将uImage拷贝到tftp目录下

[FriendlyLEG-TINY210]#tftp 21000000 uImage          //下载文件到内存

[FriendlyLEG-TINY210]#nand erase 600000 f200000               //擦写相应的nand

[FriendlyLEG-TINY210]#nand write 21000000 600000 b03c280(写入长度) //写到nand

TFTP服务器配置:

sudo apt-get install xinetd

sudo apt-get install tftp-hpa tftpd-hpa

配置:

1: 在/etc/xinetd.d/目录下创建tftp配置文件

2: touch /etc/xinetd.d/tftp

3:

service tftp

{

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /var/tftpboot/

disable = no

per_source = 11

cps = 100 2

flags = IPv4

}

4: 创建tftp下载目录:

mkdir -p /var/tftpboot/

sudo chmod 777 /var/tftpboot

echo “iloveyou” >> /var/tftpboot/demo

测试:

tftp localhost

tftp 127.0.0.1

get demo

quit

四、启动参数

设置bootargs参数
1:如果用yaffs2文件系统
setenv bootargs noinitrd root=/dev/mtdblock4 rootfstype=yaffs2 rw console=ttySAC0,115200 init=/linuxrc mem=64M

设置自启动参数bootcmd 

setenv bootcmd nand read 21000000 80000 (nand起始地址)22e800 (nand写入长度)\; bootm 21000000

烧写命令如下:

[FriendlyLEG-TINY210]#tftp 21000000 rootfs_android.img            //下载文件到内存

[FriendlyLEG-TINY210]#nand erase e00000 f200000               //擦写相应的nand

[FriendlyLEG-TINY210]#nand write.yaffs 21000000 e00000 b03c280       //写到nand

记住yaffs镜像是包含OOB数据的,所以写入NAND Flash的数据长度应该是2112(=2048 + 64)字节的整数倍。

2:如果用NFS烧写文件系统
setenv bootargs root=/dev/nfs rw nfsroot=192.168.1.10(虚拟机ip):/home/xyp/nfsroot/rootfs ip=192.168.1.102(开发板ip):192.168.1.10(虚拟机ip):192.168.1.1:255.255.255.0::eth0:off console=ttySAC0,115200 init=/linuxrc

Setenv bootcmd nand read 21000000 600000 20b334 \; bootm 21000000

Saveenv

2.1 nfs配置

Sudo apt-get install nfs-kernel-server 配置nfs

Sudo vi /etc/exports添加/home/ly/nfs *(rw,sync,no_root_squash)

重启nfs服务,使配置生效:sudo /etc/init.d/nfs-kernel-server restart

2、构建根文件按系统
2.1、建立根文件系统目录
在/home/ly下创建目录system,新建建立根文件系统目录的脚本文件 create_rootfs_bash,使用命令sudo chmod +x create_rootfs_bash改变文件的可执行权限,./create_rootfs_bash运行脚本,就完成了根文件系统目录的创建。

文件系统目录脚本文件:

!/bin/sh

echo "------Create rootfs directons start...--------"
mkdir rootfs
cd rootfs

echo "--------Create root,dev....----------"
mkdir root dev etc boot tmp var sys proc lib mnt home usr
mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules

echo "make node in dev/console dev/null"

mknod -m 600 dev/console c 5 1
mknod -m 600 dev/null c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp

mkdir var/lib var/lock var/run var/tmp

chmod 1777 tmp
chmod 1777 var/tmp

echo "-------make direction done---------"

2.2建立动态链接库
动态链接库直接用友善之臂的,先解压友善之臂的根文件包,拷贝lib的内容到新 建的根文件目录lib内。
cd /opt/studyarm (压缩包存放位置)

tar –zxvf root_qtopia.tgz –C /opt/studyarm (输出目录)
cp –rf /opt/studyarm/root_qtopia/lib/* /home/ly/system/rootfs/lib/

2.3交叉编译Bosybox
Bosybox是一个遵循GPLv2协议的开源项目,它在编写过程总对文件大小进行优化,并考虑了系统资源有限(比如内存等)的情况,使用Busybox可以自动生成根文件系统所需的bin、sbin、usr目录和linuxrc文件。
1、解压busybox
cd /mnt/hgfs/share (压缩包存放位置)
tar –zxvf busybox-1.13.3.tar.tgz –C /opt/studyarm (输出目录)
2、进入源码,修改Makefile文件:
cd /opt/studyarm/busybox-1.13.3
修改:
CROSS_COMPILE ?=arm-linux- //第164行
ARCH ?=arm //第189行

3、配置busybox
输入make menuconfig进行配置
(1)、Busybox Settings--->
General Configuration--->
[*] Show verbose applet usage messages
[*] Store applet usage messages in compressed form
[*] Support –install [-s] to install applet links at runtime
[*] Enable locale support(system needs locale for this to work)
[*] Support for –long-options
[*] Use the devpts filesystem for unix98 PTYs
[*] Support writing pidfiles
[*] Runtime SUID/SGID configuration via /etc/busybox.config
[*] Suppress warning message if /etc/busybox.conf is not readable
Build Options--->

  [*] Build BusyBox as a static binary(no shared libs) 

[*] Build with Large File Support(for accessing files>2GB)
Installation Options->
[]Don’t use /usr
Applets links (as soft-links) --->
(./_install) BusyBox installation prefix
Busybox Library Tuning --->
(6)Minimum password legth
(2)MD5:Trade Bytes for Speed
[*]Fsater /proc scanning code(+100bytes)
[*]Command line editing
(1024)Maximum length of input
[*] vi-style line editing commands
(15) History size
[*] History saving
[*] Tab completion
[*]Fancy shell prompts
(4) Copy buffer size ,in kilobytes
[*]Use ioctl names rather than hex values in error messages
[*]Support infiniband HW
(2)、Linux Module Utilities--->
(/lib/modules)Default directory containing modules
(modules.dep)Default name of modules.dep
[*] insmod
[*] rmmod
[*] lsmod
[*] modprobe
-----options common to multiple modutils
[ ] support version 2.2/2.4 Linux kernels
[*]Support tainted module checking with new kernels
[*]Support for module .aliases file
[*] support for modules.symbols file

如果出现错误,直接找到相应的函数,取消该选项,在make menuconfig下用/查找,空格键添加/取消选项内容。

4、在busybox中配置对dev下设备类型的支持

mdev是busybox自带的一个简化版的udev,适合于嵌入式的应用埸合。其具有使用简单的特点。它的作用,就是在系统启动和热插拔或动态加载驱动程序时,自动产生驱动程序所需的节点文件。在以busybox为基础构建嵌入式linux的根文件系统时,使用它是最优的选择。下面的选项将增加对mdev的支持。
Linux System Utilities --->

[*]Support /etc/mdev.conf          
[*]Support command execution at device addition/removal

5、编译busybox
编译busybox到指定目录:
cd /opt/studyarm/busybox-1.13.3
make CONFIG_PREFIX=/home/ly/system/rootfs install

在rootfs目录下会生成目录bin、sbin、usr和文件linuxrc的内容。

6、建立etc目录下的配置文件
1、etc/mdev.conf文件,内容为空。
2、拷贝主机etc目录下的passwd、group、shadow文件到rootfs/etc 目录下。
3、etc/sysconfig目录下新建文件HOSTNAME,内容为”LYliyan”。
4、etc/inittab文件:

etc/inittab

::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r
7、etc/init.d/rcS文件:

!/bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel

echo "----------munt all----------------"
mount -a

echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s

echo "*"
echo "*Studying ARM"
echo "Kernel version:linux-2.6.29.1"
echo "Student:Feng dong rui"
echo "Date:2009.07.15"
echo ""

/bin/hostname -F /etc/sysconfig/HOSTNAME
使用以下命令改变rcS的执行权限:
sudo chmod +x rcS
8、etc/fstab文件:

device mount-point type option dump fsck order

proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
9、 etc/profile文件:

Ash profile

vim:syntax=sh

No core file by defaults

ulimit -S -c 0>/dev/null 2>&1

USER="id -un"
LOGNAME=$USER
PS1='[\u@\h=W]#'
PATH=$PATH
HOSTNAME='/bin/hostname'
export USER LOGNAME PS1 PATH

10、制作根文件系统映像文件
使用以下命令安装好yaffs文件系统制作工具:
cd /mnt/hgfs/share
tar –zxvf mkyaffs2image.tgz –C /
在/opt/studyarm目录下,使用命令mkyaffs2image rootfs rootfs.img 生成根文件系统映像文件。

注意:

制作镜像提供的有两个工具,我的开发板是1G Flash的所以应该选用mkyaffs2image-128M的,选用mkyaffs2image会出现烧写文件系统不成功的错误。提供的文档中rootfs_rtm_210这个文件系统也是可用的