mkimage使用說明

The mkimage command is used to create images for use with the U-Boot boot loader


更新記錄

item note
20150615 第一版

目錄


mkimage說明

  • 參考linux-3.0.y/driver/blackfin/Kconfig裡說明,在產生kernel時會採用mkimage包裝image
  • uboot要load kernel image,需要知道kernel一些訊息(architecture,os,compression type等)

    For example, the bootable U-Boot format (created with
    mkimage) has a 64 byte header (0x40). So while the image
    you write to flash might start at say 0x20080000, you have
    to add 0x40 to get the kernel’s ROM base as it will come
    after the header.

目前採用mkimage來包裝更新檔

  • image_header_t 大小為64byte(0x40)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#define IH_NMLEN		32
typedef struct image_header {
uint32_t ih_magic; /* Image Header Magic Number */
uint32_t ih_hcrc; /* Image Header CRC Checksum */
uint32_t ih_time; /* Image Creation Timestamp */
uint32_t ih_size; /* Image Data Size */
uint32_t ih_load; /* Data Load Address */
uint32_t ih_ep; /* Entry Point Address */
uint32_t ih_dcrc; /* Image Data CRC Checksum */
uint8_t ih_os; /* Operating System */
uint8_t ih_arch; /* CPU architecture */
uint8_t ih_type; /* Image Type */
uint8_t ih_comp; /* Compression Type */
uint8_t ih_name[IH_NMLEN]; /* Image Name */
} image_header_t;
  • 使用mkimage -l xxx,查看訊息
  • 此為7個檔案組合
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  xx$ mkimage -l xx.bin
Image Name: FULLIMAGE_NK8XX
Created: Fri May 15 16:11:47 2015
Image Type: PowerPC Linux Multi-File Image (gzip compressed)
Data Size: 38580292 Bytes = 37676.07 kB = 36.79 MB
Load Address: 00000000
Entry Point: 00000000
Contents:
Image 0: 2457600 Bytes = 2400.00 kB = 2.34 MB
Image 1: 307200 Bytes = 300.00 kB = 0.29 MB
Image 2: 3710192 Bytes = 3623.23 kB = 3.54 MB
Image 3: 13238272 Bytes = 12928.00 kB = 12.62 MB
Image 4: 15036416 Bytes = 14684.00 kB = 14.34 MB
Image 5: 3538944 Bytes = 3456.00 kB = 3.38 MB
Image 6: 291636 Bytes = 284.80 kB = 0.28 MB
  • 使用od查看檔頭內容,在64byte之後,開始存放每個image大小
    0x250800 -> 2457600
    0x04b000 -> 307200
    0x0389cf0 -> 3710192
    0x0ca0000 -> 13238272
    0x0e57000 -> 15036416
    0x0360000 -> 3538944
    0x0047334 -> 291636
    0x0000000 -> 表示結束
1
2
3
4
5
6
7
8
 xx$ od -t x xx.bin |more
0000000 56190527 67dff43e 43aa5555 44b04c02
0000020 00000000 00000000 c09c2dda 01040705
0000040 4c4c5546 47414d49 4b4e5f45 20585838
0000060 00000000 00000000 00000000 00000000
0000100 00802500 00b00400 f09c3800 0000ca00
0000120 0070e500 00003600 34730400 00000000
0000140 e0ffd8ff 464a1000 01004649 01000001

簡易mkimage extract 工具

  • 由已知的檔頭訊息及mkimage -l 可取出各另image
  • 採用dd來分解檔案
    • IMG0_SIZE 為image size
    • IMG0_SKIP_SIZE 為需要刪除的檔頭byte數
shell script extract mkimagelink
1
2
dd if=$file_name of=$IMG_TMP bs=$skip_len skip=1
dd if=$IMG_TMP of=$img_name bs=$img_len count=1

參考來原