注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

onefish资料库

成功要素---耐得住孤独!

 
 
 

日志

 
 

Getting u-boot, a kernel, and a rootfs on an SD card.  

2012-10-26 15:43:23|  分类: Linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

This is a document which brings the sunxi u-boot, linux and other bits together to form a useful SD card, the basis for further hacking. It is a boiled down and updated version of "Building Debian From Source Code for Mele". We of course do not build a whole distribution, we only build u-boot, the kernel and a handful of tools, and then use an existing rootfs to get a useful system.

While we currently focus on the mele A1000, most of it seems reasonably universal.

Contents

  [hide

The SD-Card

Depending on the size of the rootfs, you might want to use a 2GB or larger SDCard. Partitioning and formatting this SDCard will be taken care of during the relevant sections.

The toolchain

Before anything else, you need to have a working toolchain. This is a set of binaries, system libraries and tools which will allow you to build (in our case, cross-compile) u-boot and the kernel for the target platform. This will, to some limited extent, need to match the target rootfs. A big and vastly incompatible change has taken place recently, namely the introduction of the Hard Float ABI, and now two different debian and ubuntu ports exist which are binary incompatible with eachother.

One option is to get a linaro released toolchain. Ignore most of the files there, but take the gcc-linaro-arm-linux-gnueabihf-*_linux.tar.bz2 file and untar it. You will find a bin directory in there, and it pays to temporarily add it to the environment you are building from:

  export PATH="$PATH":/home/blah/bleh/gcc-linaro-arm-linux-gnueabihf-..._linux/bin/ 

The more recent linaro toolchains are Hard Float (hf), which only runs us into one issue with u-boot, and this will be used throughout the document. Wherever you see something like

  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 

you need to exchange arm-linux-gnueabihf- with arm-linux-gnueabi- if your are not using a hardfloat toolchain.

The rootfs

Linaro also offers a set of different root filesystems, you can get the actual rootfs tarballs here.

The code

For our endeavour we will need to get 4 sunxi specific git repositories. All are gathered in one place nowadays.

git clone https://github.com/linux-sunxi/u-boot-sunxi.git git clone https://github.com/linux-sunxi/linux-sunxi.git git clone https://github.com/linux-sunxi/sunxi-tools.git git clone https://github.com/linux-sunxi/sunxi-boards.git 

Building u-boot

With your toolchain in your PATH, you can now descend into the u-boot-sunxi directory and build it with:

  make mele_a1000 CROSS_COMPILE=arm-linux-gnueabihf- 

Other targets can be found in board/allwinner.

When you are using a hardfloat toolchain like in the example, u-boot will fail to build. You will need to edit arch/arm/cpu/armv7/config.mk, and remove "-msoft-float" from the line immediately after the license statement:

PLATFORM_RELFLAGS += -fno-common -ffixed-r8 -msoft-float 

so that it reads:

PLATFORM_RELFLAGS += -fno-common -ffixed-r8 

Building script.bin

Descend into sunxi-tools and run make. You do need to have the libusb devel package installed though.

Then, get into the sunxi-board tree. You will find the .fex file for the mele in sys_config/a10/. Open up your mele and find out the MAC Address, as you will need to fix the MAC in the fex file, to match the one for your device:

MAC = "000000000000" 

to, for example:

MAC = "0123456789AB" 

Now you can create the script.bin file:

/home/blah/bleh/sunxi-tools/fex2bin mele_a1000.fex script.bin 

You will need this later on when finishing u-boot installation.

Building the kernel

Descend into your linux tree, and check out the correct branch:

  git checkout origin/sunxi-3.0 

Then run

  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun4i_defconfig 

and

  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j5 uImage modules 

Once this stops building you can run

  make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install 

but you can come back to that later, and first occupy yourself with setting up the sdcard.

Setting up the SDCard

The first megabyte of the SDCard will contain the partition table, and a few other binaries needed for booting.

  dd if=/dev/zero of=/dev/mmcblkx bs=512 count=2047 

Now you can set up a partition table on your SDCard with for instance fdisk. Here is an example partition table for a 4GB SDCard:

Disk /dev/mmcblkx: 3965 MB, 3965190144 bytes 122 heads, 62 sectors/track, 1023 cylinders, total 7744512 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xb4e92fdc     Device Boot      Start         End      Blocks   Id  System /dev/mmcblkxp1            2048       34815       16384   83  Linux /dev/mmcblkxp2           34816     7744511     3854848   83  Linux 

Note that the boot partition should start at cluster 2048 (1024MB). Also note that this partition can have the linux partition type, we will format it to vfat later. You might want to make your boot partition bigger though.

Install the SPL loader and the u-boot binary to the first MB, before the first partition. The SPL to 8kB and the u-boot binary to 32kB:

dd if=/home/blah/bleh/u-boot-sunxi/spl/sunxi-spl.bin of=/dev/mmcblkx bs=1024 seek=8 dd if=/home/blah/bleh/u-boot-sunxi/u-boot.bin of=/dev/mmcblkx bs=1024 seek=32 

Setting up the boot partition

Hopefully by now, the building of the kernel and the modules has finished, and you have already installed the kernel modules. If not, go back to #Building_the_kernel and do the last step there.

Format the boot partition

mkfs.vfat /dev/mmcblk0p1 

and mount it somewhere, and descend into it.

Now copy the kernel image over:

cp /home/blah/bleh/linux-sunxi/arch/arm/boot/uImage . 

We will copy the modules and such to the rootfs later on.

Now copy over the script.bin we created from the .fex file:

cp /home/blah/bleh/sunxi-boards/sys_config/a10/script.bin . 

Create a boot.cmd with the following content:

setenv bootargs console=ttyS0 root=/dev/mmcblk0p1 rootwait panic=10 ${extra} ext2load mmc 0 0x43000000 boot/script.bin ext2load mmc 0 0x48000000 boot/uImage bootm 0x48000000 

Now you can generate boot.scr:

mkimage -C none -A arm -T script -d boot.cmd boot.scr 

Setting up the rootfs

Format the root partition:

mkfs.ext3 /dev/mmcblkxp2 

and mount it somewhere convenient.

Now you can untar your rootfs there, or debootstrap it if you are under a debian-like operating system.

  评论这张
 
阅读(685)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017