How to extract files from uImage?

mkimage -l uImage

Will dump the information in the header.

tail -c+65 < uImage > out

Will get the content.

tail -c+65  < uImage | gunzip > out

will get it uncompressed if it was gzip-compressed.

If that was an initramfs, you can do cpio -t < out or pax < out to list the content.

If it's a ramdisk image, you can try and mount it with:

mount -ro loop out /mnt

file out could tell you more about what it is.


U-Boot brings its own dumpimage tool (find it in the tools directory of your U-Boot tree)

Of course it works with simple images, but it also supports the old-style multi images

$ ~2/tools/dumpimage -l uMulti 
Image Name:   
Created:      Thu Aug 31 19:54:29 2017
Image Type:   ARM Linux Multi-File Image (uncompressed)
Data Size:    5678650 Bytes = 5545.56 kB = 5.42 MB
Load Address: 10008000
Entry Point:  10008000
Contents:
   Image 0: 5028760 Bytes = 4910.90 kB = 4.80 MB
   Image 1: 602111 Bytes = 588.00 kB = 0.57 MB
   Image 2: 47762 Bytes = 46.64 kB = 0.05 MB
$ ~2/tools/dumpimage -i uMulti kernel.extracted
$ ~2/tools/dumpimage -i uMulti -p 1 initramfs.extracted
$ ~2/tools/dumpimage -i uMulti -p 2 device-tree.extracted

Have not tried it with new style FIT images yet, but I guess it should just work.


In case there are several images inside here is a quick bash script to extract them all into the files image_0, image_1, …:

#!/bin/bash

src_file=uImage

declare -ia sizes=( $(mkimage -l "$src_file" |
  awk '/^ +Image [0-9]+/ { print $3 }') )
declare -i offset="68+4*${#sizes[@]}"
declare -i size

for i in "${!sizes[@]}"; do

  size=${sizes[$i]}

  echo "Unpacking image_$i"
  dd if="$src_file" of="image_$i" bs=1 skip="$offset" count="$size"

  # going to offset of next file while rounding to 4 byte multiple
  offset+=$(( size + (4 - size % 4) % 4 ))

done

You then need to check then what is what (could be a packed Linux kernel, archive with files, device tree, …). file and binwalk (http://binwalk.org/) might be helpful.