我有一块 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
printenv
U-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
答案1
安装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
尽管如此,我希望包含并承认他们建议的语法。