Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unpacking U-Boot image file

1,584 views
Skip to first unread message

trewio

unread,
Apr 9, 2014, 12:06:40 PM4/9/14
to pytho...@python.org
How to extract files from U-Boot image file, LZMA-compressed?

Is there a Python script that can do this properly?

Rustom Mody

unread,
Apr 9, 2014, 1:18:56 PM4/9/14
to
On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote:
> How to extract files from U-Boot image file, LZMA-compressed?
>
> Is there a Python script that can do this properly?

For lzma theres this (recent) python library
https://docs.python.org/dev/library/lzma.html

Though you might just be better off with the command-line xz unxz etc

After that.. whats the U-boot format?

Adnan Sadzak

unread,
Apr 9, 2014, 1:33:20 PM4/9/14
to python-list
I belive you are trying to decompress some router images or router backup/config files?
Check if maybe LZS.

Rustom gave You starting point.



trewio

unread,
Apr 9, 2014, 1:59:37 PM4/9/14
to pytho...@python.org
I need decompress image(modem), and I deciced use some Python script or utility which capable run on Python for Windows OS.

trewio

unread,
Apr 9, 2014, 1:53:23 PM4/9/14
to pytho...@python.org
U-Boot format: hmm, I'm not sure, can someone specify Python script that will help me deterermine U-boot format used? [for Python for Windows OS]

Note: I need Python script for Python under Windows OS.


> ----- Original Message -----
> From: Rustom Mody
> Sent: 04/09/14 08:18 PM
> To: pytho...@python.org
> Subject: Re: Unpacking U-Boot image file
>

lagu...@mail.com

unread,
Apr 9, 2014, 4:49:36 PM4/9/14
to pytho...@python.org
I know about Binwalk, it can run on Linux OS only. I am looking for Python script that can run on Windows too.

Thank you.
 

 

 

----- Original Message -----

From: Adnan Sadzak

Sent: 04/09/14 11:37 PM

To: trewio

Subject: Re: Unpacking U-Boot image file

 
Oh then see Craig's page [0]. You can find in deepth explanation about some tools (Linux) that is used to desompress and mount filesystems/images. From my experience you should find first read modem tehnical documentation. Find out what kind of firmware is using. You won't find just script to decompress those images.
 
 
Cheers
 

 

 


 

Dave Angel

unread,
Apr 9, 2014, 8:42:33 PM4/9/14
to pytho...@python.org
"trewio" <lagu...@mail.com> Wrote in message:
> How to extract files from U-Boot image file, LZMA-compressed?
>
> Is there a Python script that can do this properly?
>

Use the lzma module in Python 3.3 for starters

--
DaveA

Dave Angel

unread,
Apr 9, 2014, 8:44:49 PM4/9/14
to pytho...@python.org
"trewio" <lagu...@mail.com> Wrote in message:
> U-Boot format: hmm, I'm not sure, can someone specify Python script that will help me deterermine U-boot format used? [for Python for Windows OS]
>
> Note: I need Python script for Python under Windows OS.
>
>
>> ----- Original Message -----
>> From: Rustom Mody
>> Sent: 04/09/14 08:18 PM
>> To: pytho...@python.org
>> Subject: Re: Unpacking U-Boot image file
>>
>> On Wednesday, April 9, 2014 9:36:40 PM UTC+5:30, trewio wrote:
>> > How to extract files from U-Boot image file, LZMA-compressed?
>> >
>> > Is there a Python script that can do this properly?
>>
>> For lzma theres this (recent) python library
>> https://docs.python.org/dev/library/lzma.html
>>
>> Though you might just be better off with the command-line xz unxz etc
>>
>> After that.. whats the U-boot format?
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>

Good job starting 3 separate threads for same question. Sorry I
answered the first one.
--
DaveA

Rhodri James

unread,
Apr 10, 2014, 6:01:50 PM4/10/14
to
On Wed, 09 Apr 2014 18:18:56 +0100, Rustom Mody <rusto...@gmail.com>
wrote:
The Fine Manual (http://www.denx.de/wiki/view/DULG/UBootImages) isn't very
forthcoming, sadly;

"U-Boot operates on "image" files which can be basically anything,
preceeded by a special header; see the definitions in include/image.h for
details; basically, the header defines the following image properties

* Target Operating System
* Target CPU Architecture
* Compression Type
* Load Address
* Entry Point
* Image Name
* Image Timestamp"

I suspect taking this apart may be a little involved.

--
Rhodri James *-* Wildebeest Herder to the Masses

Rustom Mody

unread,
Apr 10, 2014, 11:27:14 PM4/10/14
to
On Friday, April 11, 2014 3:31:50 AM UTC+5:30, Rhodri James wrote:
> On Wed, 09 Apr 2014 18:18:56 +0100, Rustom Mody
> > After that.. whats the U-boot format?
>
> The Fine Manual (http://www.denx.de/wiki/view/DULG/UBootImages) isn't very
> forthcoming, sadly;
>
> "U-Boot operates on "image" files which can be basically anything,
> preceeded by a special header; see the definitions in include/image.h for
> details; basically, the header defines the following image properties
>
> * Target Operating System
> * Target CPU Architecture
> * Compression Type
> * Load Address
> * Entry Point
> * Image Name
> * Image Timestamp"
>
>
> I suspect taking this apart may be a little involved.

If its a binary format, you (OP) may want to look at
https://pypi.python.org/pypi/construct/2.5.1

Of course you will have to read/get the C struct and write the corresponding
"Construct"

You may want to ask on a U-boot forum for more details.

Grant Edwards

unread,
Apr 11, 2014, 12:02:36 PM4/11/14
to
Not really. For the format you're talking about (single-file uImage),
you can extract the data like so:

data = open("foobar.uImage","rb").read()[64:]

Then just uncompress 'data' as desired.

If you want to look at individual fields in the heaer, here's the
structure:

#define IH_MAGIC 0x27051956 /* Image Magic Number */
#define IH_NMLEN 32 /* Image Name Length */

typedef struct image_header
{
uint32_t ih_magic; /* Image Header Magic Number */
uint32_t ih_hcrc; /* Image Header CRC Checksum */
uint32_t ih_time; /* Image Creation Timestamp */
uint32_t ih_size; /* Image Data Size */
uint32_t ih_load; /* Data Load Address */
uint32_t ih_ep; /* Entry Point Address */
uint32_t ih_dcrc; /* Image Data CRC Checksum */
uint8_t ih_os; /* Operating System */
uint8_t ih_arch; /* CPU architecture */
uint8_t ih_type; /* Image Type */
uint8_t ih_comp; /* Compression Type */
uint8_t ih_name[IH_NMLEN]; /* Image Name */
} image_header_t;

Header fields are all in network byte order (bit-endian).

However, there's also a "multi-file" uImage format that I suspect is
what the OP is referring to (since he says he needs to extract "files"
from a uImage file).

http://www.isysop.com/unpacking-and-repacking-u-boot-uimage-files/

In that case, the "Image Type" field will be set to 4, and the 'data'
field starts with a list of 32-bit image size values (network byte
order, terminated by 0x00000000). That list is then followed by the
image data.

Here's a Python 2.7 program that reads the uImage header, prints some
stuff and then reads the data for the image(s). What to _do_ with the
data for the image(s) is left as an exercise for the gentle reader.

-------------------------------------8<-------------------------------------
#!/usr/bin/python

import sys,struct

f = open(sys.argv[1],"rb")

(ih_magic, ih_hcrc, ih_time, ih_size, ih_load, ih_ep, ih_dcrc,
ih_os, ih_arch, ih_type, ih_comp, ih_name) \
= struct.unpack("!IIIIIIIBBBB32s",f.read(64))

print "magic=%08x type=%d size=%d name='%s'" % (ih_magic, ih_type, ih_size, ih_name)

if ih_type == 4:
# multi-file: read image lengths from data
imagesizes = []
while 1:
size, = struct.unpack("!I",f.read(4))
if size == 0:
break
imagesizes.append(size)
else:
# single-file
imagesizes = [ih_size]

print imagesizes

images = [f.read(size) for size in imagesizes]

print [len(image) for image in images]

extradata = f.read()

if extradata:
print "%d bytes of extra data" % len(extradata)

-------------------------------------8<-------------------------------------










--
Grant Edwards grant.b.edwards Yow! The Korean War must
at have been fun.
gmail.com
0 new messages