Arm

如何解壓(解壓)U-Boot boot.scr.uimg 到 boot.scr?

  • August 9, 2019

我有一個 ARM 開發板(STM32MP157A-DK1),我正在四處尋找 Linux 映像是如何建構的。

boot.scr.uimg在引導分區中有文件。據我所知boot.scr.uimg是壓縮版boot.scr

有什麼方法可以解壓縮/提取原始boot.scr文件boot.scr.uimg嗎?

這是結果file boot.scr.uimg

boot.scr.uimg: u-boot legacy uImage, , Linux/ARM, Script File (Not compressed), 1489 bytes, Thu Jan  1 00:00:00 1970, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xC80D8B27, Data CRC: 0x62B32EA2

這是boot.scr.uimg文件連結。

printenvU-Boot CLI 中的結果:

STM32MP> printenv
altbootcmd=run bootcmd
arch=arm
autoload=no
baudrate=115200
board=stm32mp1
board_name=stm32mp157c-dk2
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_device=mmc
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}extlinux/extlinux.conf
boot_instance=0
boot_net_usb_start=true
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_targets=mmc0
bootcmd=run distro_bootcmd
bootcmd_mmc0=setenv devnum 0; run mmc_boot
bootcmd_mmc1=setenv devnum 1; run mmc_boot
bootcmd_mmc2=setenv devnum 2; run mmc_boot
bootcmd_pxe=run boot_net_usb_start; dhcp; if pxe get; then pxe boot; fi
bootcmd_ubifs0=setenv devnum 0; run ubifs_boot
bootcount=2
bootdelay=1
bootlimit=0
cpu=armv7
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
ethaddr=00:80:e1:42:5d:63
fdt_addr_r=0xc4000000
fdt_high=0xffffffff
fdtcontroladdr=ddc3c4f8
initrd_high=0xffffffff
kernel_addr_r=0xc2000000
mmc_boot=if mmc dev ${devnum}; then setenv devtype mmc; run scan_dev_for_boot_part; fi
mtdparts_nand0=2m(fsbl),2m(ssbl1),2m(ssbl2),-(UBI)
mtdparts_nor0=256k(fsbl1),256k(fsbl2),2m(ssbl),256k(logo),-(nor_user)
preboot=echo "Boot over ${boot_device}${boot_instance}!"; if test ${boot_device} = serial; then stm32prog serial ${boot_instance}; else if test ${boot_device} = usb; then stm32prog usb ${boot_instance}; else if test ${boot_device} = mmc; then env set boot;
pxefile_addr_r=0xc4200000
ramdisk_addr_r=0xc4400000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}extlinux/extlinux.conf; then echo Found ${prefix}extlinux/extlinux.conf; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
scriptaddr=0xc4100000
serial#=0038001A3338510A39303435
serverip=192.168.1.1
soc=stm32mp
splashimage=0xc4300000
stderr=serial
stdin=serial
stdout=serial
ubifs_boot=env exists bootubipart || env set bootubipart UBI; env exists bootubivol || env set bootubivol boot; if ubi part ${bootubipart} && ubifsmount ubi${devnum}:${bootubivol}; then setenv devtype ubi; run scan_dev_for_boot; fi
usb_boot=usb start; if usb dev ${devnum}; then setenv devtype usb; run scan_dev_for_boot_part; fi
usb_pgood_delay=2000
vendor=st

Environment size: 3053/4092 bytes
STM32MP>

我對 U-Boot 還沒有太多經驗,所以我不確定它是否與boot.scr. 我仍然想知道如何在不訪問 U-Boot CLI的情況下boot.scr從中提取。boot.scr.uimg

安裝u-boot-tools

$ sudo apt install u-boot-tools

檢查圖像的標題:

$ dumpimage -l boot.scr.uimg 
Image Name:   
Created:      Wed Dec 31 16:00:00 1969
Image Type:   ARM Linux Script (uncompressed)
Data Size:    1489 Bytes = 1.45 KiB = 0.00 MiB
Load Address: 00000000
Entry Point:  00000000
Contents:
  Image 0: 1481 Bytes = 1.45 KiB = 0.00 MiB

boot.scr從圖像中提取文件:

$ dumpimage -i boot.scr.uimg boot.scr

提取的文件比Contents標題中的表顯示的大 8 字節,1489 字節與預期的 1481 字節相比。如果您願意,可以使用以下命令修剪這些字節:

tail -c+8 boot.scr > $$; mv $$ boot.scr

**編輯:**關於 OP @Bumsik Kim 和專家審閱者@Kusalananda,建議將dumpimage語法更改為:

dumpimage -o boot.scr boot.scr.uimg

我將在此處包含該註釋以防它對某些人有幫助,但在 Ubuntu 18.04 系統上,該命令成功,但什麼也不做:

# ls -l
total 4
-rw------- 1 root root 1553 Aug  7 11:30 boot.scr.uimg
# dumpimage -o boot.scr boot.scr.uimg && ls -l
total 4
-rw------- 1 root root 1553 Aug  7 11:30 boot.scr.uimg

上面的原始語法適用於 Ubuntu 18:

$ dumpimage -i boot.scr.uimg boot.scr && ls -l
total 8
-rw------- 1 root root 1489 Aug  9 10:51 boot.scr
-rw------- 1 root root 1553 Aug  7 11:30 boot.scr.uimg

儘管如此,我希望包括並承認他們建議的語法。

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