最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【转】mkimage制作linux内核映像 即uImage是怎么制作的

Linux crifan 2973浏览 0评论

【转】mkimage制作linux内核映像

bootm命令是用来引导经过u-boot的工具mkimage打包后的kernel image的,什么叫做经过u-boot的工具mkimage打包后的kernel image,这个就要看mkimage的代码,看看它做了些什么,虽然我很希望大家不要偷懒,认真地去看看,但是我知道还是有很多人懒得去做这件,那么我就j将分析mkimage代码后得到的总结告诉大家,mkimage做了些什么,怎么用这个工具。

mkimage的用法
uboot源代码的tools/目录下有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件。

mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字节的头,记录参数所指定的信息,这样uboot才能识别这个映象是针对哪个CPU体系结构的,哪个OS的,哪种类型,加载内存中的哪个位置, 入口点在内存的那个位置以及映象名是什么

root@Glym:/tftpboot# ./mkimage
Usage: ./mkimage -l image
-l ==> list image header information
./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file…] image
-A ==> set architecture to ‘arch’
-O ==> set operating system to ‘os’
-T ==> set image type to ‘type’
-C ==> set compression type ‘comp’
-a ==> set load address to ‘addr’ (hex)
-e ==> set entry point to ‘ep’ (hex)
-n ==> set image name to ‘name’
-d ==> use image data from ‘datafile’
-x ==> set XIP (execute in place)
参数说明:

-A 指定CPU的体系结构:

取值 表示的体系结构
alpha Alpha
arm ARM
x86 Intel x86
ia64 IA64
mips MIPS
mips64 MIPS 64 Bit
ppc PowerPC
s390 IBM S390
sh SuperH
sparc SPARC
sparc64 SPARC 64 Bit
m68k MC68000

-O 指定操作系统类型,可以取以下值:
openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos

-T 指定映象类型,可以取以下值:
standalone、kernel、ramdisk、multi、firmware、script、filesystem

-C 指定映象压缩方式,可以取以下值:
none 不压缩
gzip 用gzip的压缩方式
bzip2 用bzip2的压缩方式

-a 指定映象在内存中的加载地址,映象下载到内存中时,要按照用mkimage制作映象时,这个参数所指定的地址值来下载

-e 指定映象运行的入口点地址,这个地址就是-a参数指定的值加上0x40(因为前面有个mkimage添加的0x40个字节的头)

-n 指定映象名

-d 指定制作映象的源文件

mkimage

   解压内核源码包,编辑Makefile
   设置 cross_compile:=[编译器的绝对路径]     ;这个绝对路径既上面2.95.3放到的路径
   进入内核文件夹,执行下面命令
   [root@hostname]# make clean
   [root@hostname]# make dep
   [root@hostname]# make
   [root@hostname]# [编译器的绝对路径]/bin/arm-linux-objcopy -O binary -S vmlinux linux.bin    ;编译器的绝对路径也是上面说到的路径
    [root@hostname]# gzip linux.bin
下面的比较重要了,主要是u-boot的安装,这个在H9200的手册上说的很不清楚
    [root@hostname]# tar xzvf u-boot-1.0.0.tar.gz      ;解压u-boot
    [root@hostname]# cd u-boot-1.0.0
    [root@hostname]# make distclean
    [root@hostname]# make at91rm9200dk_config
    [root@hostname]# make all
    然后在/usr/local下建立uboot文件夹将u-boot-1.0.0下的所有文件都复制到uboot下
    [root@hostname]# [uboot的绝对路径]/tools/mkimage -A arm -O linux -C gzip -a 0x20008000 -e 0x20008000 -d linux.bin.gz uImage           ;这里的绝对路径是/usr/local/uboot

vmlinux linux.bin linux.bin.gz uImage(uboot制作的image)

mkimage -a -e

-a参数后是内核的运行地址,-e参数后是入口地址。

1)如果我们没用mkimage对内核进行处理的话,那直接把内核下载到0x30008000再运行就行,内核会自解压运行(不过内核运行需要一个tag来传递参数,而这个tag建议是由bootloader提供的,在u-boot下默认是由bootm命令建立的)。

2)如果使用mkimage生成内核镜像文件的话,会在内核的前头加上了64byte的信息,供建立tag之用。bootm命令会首先判断bootm xxxx 这个指定的地址xxxx是否与-a指定的加载地址相同。
(1)如果不同的话会从这个地址开始提取出这个64byte的头部,对其进行分析,然后把去掉头部的内核复制到-a指定的load地址中去运行之
(2)如果相同的话那就让其原封不同的放在那,但-e指定的入口地址会推后64byte,以跳过这64byte的头部。

QUESTIONS

1. I have built a vmlinux image but I can boot it.

2: The mkimage tool, ARMboot’s tftp command, and the bootm command require
   certain load and entry addresses. I’m confused which ones to chose.

ANSWERS

1. I have built a vmlinux image but I can boot it.
————————————————–

ARMboot is designed to boot Images as created by the mkimage tool, that
comes with ARMboot and is automatically built, too. You cannot directly load
the vmlinux image, as it expects a number of prerequisits such as special
register contents etc.

2. The mkimage tool, ARMboot’s tftp command, and the bootm command require
   certain load and entry addresses. I’m confused which ones to chose.
————————————————————————–

Well, there are 3 different addresses:

1. Kernel Load Address. This is the address, where the kernel was linked
   to when you built the vmlinux and can be found in arch/arm/Makefile.
   The default for it is:
  
   ifeq ($(CONFIG_CPU_32),y)
   PROCESSOR    = armv
   TEXTADDR     = 0xC0008000
   LDSCRIPT     = arch/arm/vmlinux-armv.lds.in
   endif
  
   Provide this as "-a" parameter to mkimage.

2. Kernel Entry Point. This is the address, where ARMboot jumps to to
   enter the Kernel. It usually is the same as the kernel load address.

   Provide this as "-e" parameter to mkimage.

3. The Network Download Address. This is where you download the mkimage
   File. This address MUST BE different to the Kernel Load Address, and
   should be sufficiently far away to allow ARMboot to relocate the
   image to the final Kernel Load Address. Loading to the 5th MB
   within the RAM is usually a good idea, eg. if the RAM begins at
   0xc0000000, you can do this:
  
   LART # tftp c0400000 linux.img
   ARP broadcast 1
   eth addr: 00:02:03:04:05:06
   TFTP from server 192.168.1.1; our IP address is 192.168.1.2
   Filename ‘image.img’.
   Load address: 0xc0400000
   Loading:
   ##################################################################done
   Bytes transferred = 567252 (8a7d4 hex)
   LART # bootm c0400000
      Image Name:   Linux 2.4.18
      Created:      Mon Jun 24 12:00:01 2002
      Image Type:   ARM Linux Kernel Image (gzip compressed)
      Data Size:    567188 Bytes = 553 kB = 0 MB
      Load Address: 0xc0008000
      Entry Point: 0xc0008000
      Verifying Checksum … OK
      Loading Kernel Image … OK

   Starting kernel …
   Linux version 2.4.18 (mag@mag) (gcc version 2.95.3 20010315 (release)) #4 Mon Jun 17 20:35:32 CST 2002
   …

===========================================================================

转载请注明:在路上 » 【转】mkimage制作linux内核映像 即uImage是怎么制作的

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
81 queries in 0.175 seconds, using 22.12MB memory