Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2713794
  • 博文数量: 505
  • 博客积分: 1552
  • 博客等级: 上尉
  • 技术积分: 2514
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-23 18:24
文章分类

全部博文(505)

文章存档

2019年(12)

2018年(15)

2017年(1)

2016年(17)

2015年(14)

2014年(93)

2013年(233)

2012年(108)

2011年(1)

2009年(11)

分类: LINUX

2013-04-11 21:44:12

U-boot已经在Mini2440上跑起来了,下一步就是要让Linux内核在U-boot上跑起来,自己移植内核先放放在说,先让现成的Linux内核跑起来再说啦~

在make menuconfig之后,使用make命令会在linux根目录下生成vmlinux,使用友善之臂的make zImage命令直接生成的zImage在U-boot是不能用的,必须要使用U-boot tools目录下的mkimage命令重新生成uImage镜像。后来查资料发现新的linux内核已经具有了U-boot的mkimage命令,使用make uImage就会生成U-boot能够识别的uImage镜像,这个等移植成功了之后在试试。

    1、先看一下mkimage的用法吧,下面的摘要来自U-boot目录下的readme文件,介绍了mkimage命令的参数和用法。

     The "uImage" build target uses a special tool (in 'tools/mkimage') to encapsulate a compressed Linux kernel image with header  information,
    CRC32 checksum etc. for use with U-Boot. This is what we are doing:

    * build a standard "vmlinux" kernel image (in ELF binary format):

    * convert the kernel into a raw binary image:

${CROSS_COMPILE}-objcopy -O binary \
         -R .note -R .comment \
         -S vmlinux linux.bin

    * compress the binary image:

gzip -9 linux.bin

    * package compressed binary image for U-Boot:

mkimage -A arm -O linux -T kernel -C gzip \
      -a 0x30008000 -e 0x30008000 -n "Linux Kernel Image" \
      -d linux.bin.gz uImage

    2、mkimage原理

    mkimage其实在zImage增加了一个Header,共64个字节。这个Header的结构如下所示(摘自:u-boot-200903/include/image.h):

typedef struct image_header {
     uint32_t ih_magic;
     uint32_t ih_hcrc;
     uint32_t ih_time;
     uint32_t ih_size;
     uint32_t ih_load;
     uint32_t ih_ep; 
     uint32_t ih_dcrc;
     uint8_t  ih_os; 
     uint8_t  ih_arch;
     uint8_t  ih_type;
     uint8_t  ih_comp;
     uint8_t  ih_name[IH_NMLEN];
    } image_header_t;

此Header是怎么产生的呢?是利用u-boot中的源码包生成的,位于U-boot-200903/tools/mkimage.c中,在此文件中还注明了mkimage详细的参数和用法,如下所示:

"       %s [-x] -A arch -O os -T type -C comp "
             "-a addr -e ep -n name -d data_file[:data_file...] image\n"
             "          -A ==> set architecture to 'arch'\n"
             "          -O ==> set operating system to 'os'\n"
             "          -T ==> set image type to 'type' “kernel” or “ramdisk”\n"
             "          -C ==> set compression type 'comp'(如果之前内核被gzip压缩过,则参数为gzip,否则参数为none)\n"
             "          -a ==> set load address to 'addr' (hex)\n"
             "          -e ==> set entry point to 'ep' (hex)(内核启动时在此查询完整内核镜像)\n"
             "          -n ==> set image name to 'name'\n"
             "          -d ==> use image data from 'datafile'\n"
             "          -x ==> set XIP (execute in place))(不进行拷贝,直接在当前位置执行)\n",

不知道为什么,在我的Ubuntu和Fedora上使用U-boot200903生成的mkimage编译。在第一步使用:

arm-linux-objcopy -O binary -R .note -R .comment -S vmlinux linux.bin,生成的linux.bin竟然有3G,晕啊~

查了半天资料,也没有找到合适的解决方法,但是感觉zImage的大小到时正常,有1点几M。后来无意中在一个ppt中看到了基于zImage生成uImage的方

法,尝试了一下,竟然跳过了Uncompressed部分,开心啊。:)

mkimage -A arm -O linux -T kernel -C none -a 30008000 -e 30008000 -n "Linux Kernel Image" -d zImage uImage

还有注意是采用tftp boot 和bootm命令的地址,最好能离-a和-e制定的地址远点,以便有足够的空间解压。

接下来就是要移植busybox了,继续奋进。

参考文章:http://blog.csdn.net/sailor_8318/archive/2008/08/05/2773412.aspx

阅读(5034) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~