3

I got an ARM dev board (STM32MP157A-DK1) and I'm messing around to see how the Linux Image is built.

I got boot.scr.uimg file in the boot partition. As far as I know boot.scr.uimg is a compressed version of boot.scr.

Is there any way to decompress/extract the original boot.scr from boot.scr.uimg?

Here is the result of 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

Here is the boot.scr.uimg file link.

The result of printenv in 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>

I don't have much experience in U-Boot yet, so I'm not sure if it is the same as boot.scr. Still I would like to know how to extract boot.scr from boot.scr.uimg without accessing U-Boot CLI.

2
  • Compilation and compression are two completely different things (I fixed your question). Aug 1 '19 at 8:09
  • 2
    Is this question helpful?
    – Jim L.
    Aug 4 '19 at 0:53
1
+100

Install u-boot-tools:

$ sudo apt install u-boot-tools

Examine the header of the image:

$ 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

Extract the file boot.scr from the image:

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

The extracted file is 8 bytes larger than the Contents table in the header would indicate, 1489 bytes versus the expected 1481. If you like, you can trim those bytes off with:

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

Edit: with respect to OP @Bumsik Kim and expert reviewer @Kusalananda, the suggestion was made that the dumpimage syntax be changed to:

dumpimage -o boot.scr boot.scr.uimg

I will include that note here in case it is helpful for some, but on an Ubuntu 18.04 system, that command succeeds, but does nothing:

# 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

The original syntax above is what works on 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

Nonetheless, I wish to include and acknowledge their suggested syntax.

2
  • Thanks, it works! I slightly fix your answer.
    – Bumsik Kim
    Aug 9 '19 at 6:20
  • @BumsikKim That syntax doesn't work for me, but I edited it into the answer in case it works for others.
    – Jim L.
    Aug 9 '19 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.