Linux-Kernel

uboot Flattened Image Tree 反編譯

  • June 16, 2019

我在嘗試為我的嵌入式 linux 系統配置 bootargs 時遇到了問題。設備樹被編譯成與核心相同的映像。它包括引導參數 ( /chosen/bootargs )。此外,我需要在(uboot)執行時配置一些時間。這意味著我需要能夠同時使用兩者。我知道核心有一個配置定義(https://stackoverflow.com/a/48814885/11312396),但這僅適用於arm(我使用的是aarch64)。

我目前正在嘗試使用 uboot 的 fdt 命令將設備樹引導參數載入到 uboot 中並將它們附加到那裡。然後核心使用 uboot 傳遞的那些。

那裡的問題是獲取設備樹地址。因為它被編譯成一個扁平化的圖像樹,我只知道它的基地址,我沒有設備樹 blob 本身的地址。我可以通過使用iminfouboot 命令手動找到它,但 uboot 沒有工具來解析該命令的輸出。

## Checking Image at 03000000 ...
FIT image found
FIT description: U-Boot fitImage for Ultra96 kernel
Image 0 (kernel@0)
Description:  Linux Kernel
Type:         Kernel Image
Compression:  gzip compressed
Data Start:   0x030000d4
Data Size:    7399390 Bytes = 7.1 MiB
Architecture: AArch64
OS:           Linux
Load Address: 0x00080000
Entry Point:  0x00080000
Hash algo:    sha1
Hash value:   47edccde80d64c636a01dbf4916662e2cdbfda96
Image 1 (fdt@0)
Description:  Flattened Device Tree blob
Type:         Flat Device Tree
Compression:  uncompressed
Data Start:   0x0370e9ac
Data Size:    41889 Bytes = 40.9 KiB
Architecture: AArch64
Hash algo:    sha1
Hash value:   d977763b2ec8079aca8908b28c732c3a79e1f7ab
Default Configuration: 'conf@1'
Configuration 0 (conf@1)
Description:  Boot Linux kernel with FDT blob
Kernel:       kernel@0
FDT:          fdt@0
## Checking hash(es) for FIT Image at 03000000 ...
Hash(es) for Image 0 (kernel@0): sha1+ 
Hash(es) for Image 1 (fdt@0): sha1+ 

所以我試圖自己反編譯它的標題,但這有點超出我的能力:

03000000: edfe0dd0 98907100 38000000 988e7100    .....q.....8.q..
03000010: 28000000 11000000 10000000 00000000    ...(............
03000020: 6c000000 608e7100 00000000 00000000    ...l.q.`........
03000030: 00000000 00000000 01000000 00000000    ................
03000040: 03000000 04000000 5c000000 e1e8455c    ...........\\E..
03000050: 03000000 23000000 00000000 6f422d55    .......#....U-Bo
03000060: 6620746f 6d497469 20656761 20726f66    ot fitImage for 
03000070: 72746c55 20363961 6e72656b 00006c65    Ultra96 kernel..
03000080: 03000000 04000000 0c000000 01000000    ................
03000090: 01000000 67616d69 00007365 01000000    ....images......
030000a0: 6e72656b 30406c65 00000000 03000000    kernel@0........
030000b0: 0d000000 00000000 756e694c 654b2078    ........Linux Ke
030000c0: 6c656e72 00000000 03000000 dee77000    rnel.........p..
030000d0: 1b000000 00088b1f 00000000 5bec0302    ...............[
030000e0: d754540d f7bfff9d 23010f86 c087c332    .TT........#2...
030000f0: 8c0199d9 59ac493a e4688106 d1a260cd    ....:I.Y..h..`..

TLDR:是否有可能從上面列出的 FIT 文件頭轉儲到設備樹的起始地址 (0x0370e9ac)

不,因為它位於二進制轉儲的中間。

看一下這個解析範例(文件偏移量在左邊):

00000000                 Magic: D00DFEED    FDT File OK
00000004             File Size: 002C076C
00000008      DT Struct Offset: 00000038
0000000C     DT Strings Offset: 002C0564
00000010     Mem RsvMap Offset: 00000028
00000014               Version: 00000011
00000018  Last Compatible Vers: 00000010
0000001C           Boot CPU_ID: 00000000
00000020       DT Strings Size: 0000006C
00000024        DT Struct Size: 002C052C
00000038
00000040     timestamp = 18/01/2019 12:25:33
00000050     description = Jackal Kernel Image generated with Linux kernel and FDT blob
0000009C     #address-cells = 0x00000001
000000AC     images
000000B8        kernel@1
000000C8           description = Linux kernel
000000E4           data = 2872840 Bytes [000000F0-002BD6F7]
002BD6F8           type = kernel
002BD70C           arch = arm
002BD71C           os = linux
002BD730           compression = none
002BD744           load = 0x03000000
002BD754           entry = 0x03000000
002BD764           hash@1
002BD770              value = 29684CCAA0B89E0C9B9E2AB47B120CB0
002BD78C              algo = md5
002BD7A4        fdt@1
002BD7B0           description = Device Tree
002BD7C8           data = 11376 Bytes [002BD7D4-002C0443]
002C0444           type = flat_dt
002C0458           arch = arm
002C0468           compression = none
002C047C           hash@1
002C0488              value = 062502B2C222FE1547BDA6118C6FC1EE
002C04A4              algo = md5
002C04C0     configurations
002C04D4        default = config@1
002C04EC        config@1
002C04FC           description = Boot Linux kernel with FDT blob
002C0528           kernel = kernel@1
002C0540           fdt = fdt@1

引用自:https://unix.stackexchange.com/questions/510528